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-in eval methods to evaluate each of the rates.

  • PythonNetwork modules: this means writing out the network as a .py file, importing it, and then using the functions in the module to evaluate the rates.

  • AmrexAstroCxxNetwork : this uses the standalone_build option to write_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 dict keyed by Nucleus as ydots_py_inline, ydots_py_module, ydots_amrex, and ydots_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), where nuc_i and nuc_j are Nucleus objects 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 dict keyed by Rate as rates_py_inline, rates_py_module, rates_amrex, and rates_cxx.

  • Energy : The nuclear energy from mass changes is stored as a scalar, enuc_py_inline, enuc_py_module, enuc_amrex, and enuc_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, and enu_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:

As more features are ported to SimpleCxxNetwork, we should extend the testing to compare with python rates.