Testing and Comparing Backends#
If we create a network with a set of rates, we should get the same “ydots” (\(dY_k/dt\)) values regardless of the backend (to roundoff, and maybe interpolation, error)
To facilitate comparing the backends, we have a NetworkCompare
helper class that takes a library and evaluates the ydots for different backends.
Currently it can work with:
RateCollection/ inline python networks: this uses the built-inevalmethods to evaluate each of the rates.PythonNetworkmodules: this means writing out the network as a.pyfile, importing it, and then using the functions in the module to evaluate the rates.AmrexAstroCxxNetwork: this uses thestandalone_buildoption towrite_network()to output a driver and makefile. The output is then parsed to get the ydot values.SimpleCxxNetwork: we build a simple test driver and parse the output to get the ydot values.
Tests can be run with or without screening. Once the NetworkCompare
object is setup, the comparison can be run for a single density and temperature
using the evaluate method. The data are then stored in the object.
Accessing comparison data#
ODE righthand side: The \(\partial Y/\partial t\) data for each network is stored as a
dictkeyed byNucleusasydots_py_inline,ydots_py_module,ydots_amrex, andydots_cxx.Jacobian: The composition terms of the Jacobian, \(\partial \dot{Y}_i/\partial Y_j\), are stored in a dict keyed by a tuple
(nuc_i, nuc_j), wherenuc_iandnuc_jareNucleusobjects representing the row and column nucleus respectively.Raw rates : The individual rate data (just the \(N_A\langle \sigma v \rangle\) or equivalent) is stored as a
dictkeyed byRateasrates_py_inline,rates_py_module,rates_amrex, andrates_cxx.Energy : The nuclear energy from mass changes is stored as a scalar,
enuc_py_inline,enuc_py_module,enuc_amrex, andenuc_cxx.Weak rate neutrino losses : The neutrino energy loss from weak rates is stored as a scalar,
enu_weak_py_inline,enu_weak_py_module,enu_weak_amrex, andenu_weak_cxx.
Performing the comparison#
The compare_results
method manages the comparison. It accepts a relative and absolute
tolerance and raises a ValueError if networks do not agree.
A summary of the comparison (including errors) can be printed using
print_summary.
Current unit tests comparing networks#
NetworkCompare is used in the following unit tests in
pynucastro/networks/tests/comparing_nets_tests:
test_compare_big_net.py : this creates a network consisting of an \(\alpha\)-chain and an iron-group, with \((\alpha,p)(p,\gamma)\) and \((nn,\gamma)\) rate approximations, derived reverse rates, modified rates, and tabular weak rates. It is modeled off of the AMReX Astro Microphysics ase-iron network.
test_compare_branched.py : this compares networks that use
BranchedRatefor a reduced CNO cycle.test_compare_co_approx.py : this compares the approximate rates for carbon and oxygen burning (as discussed in Approximating C and O Burning).
test_compare_cxx_and_python.py : this compares just strong reaction rates, but includes derived reverse rates.
test_compare_cxx_and_python_screened.py : a simpler version of
test_compare_cxx_and_python.py(no derived reverse rates), but with screening enabled.test_compare_temp_tabular_starlib.py : this compares the evaluation of a
TemperatureTabularRateand severalStarLibRate. Note that simple-C++ networks are not currently included.
As more features are ported to SimpleCxxNetwork, we should extend
the testing to compare with python rates.