|
GridFire v0.7.1_rc2
General Purpose Nuclear Network
|
GridFire is a C++ library designed to perform general nuclear network evolution. It is part of the larger SERiF project within the 4D-STAR collaboration. GridFire is primarily focused on modeling the most relevant burning stages for stellar evolution modeling. Currently, there is limited support for inverse reactions. Therefore, GridFire has a limited set of tools to evolve a fusing plasma in NSE; however, this is not the primary focus of the library and has therefore not had significant development. For those interested in modeling super nova, neutron star mergers, or other high-energy astrophysical phenomena, we strongly recommend using SkyNet.
GridFire is architected to balance physical fidelity, computational efficiency, and extensibility when simulating complex nuclear reaction networks. Users begin by defining a composition, which is used to construct a full GraphEngine representation of the reaction network. A GraphNetwork uses JINA Reaclib reaction rates (Cyburt et al., ApJS 189 (2010) 240.) along with a dynamically constructed network topology. To manage the inherent stiffness and multiscale nature of these networks, GridFire employs a layered view strategy: partitioning algorithms isolate fast and slow processes, adaptive culling removes negligible reactions at runtime, and implicit solvers stably integrate the remaining stiff system. This modular pipeline allows researchers to tailor accuracy versus performance trade-offs, reuse common engine components, and extend screening or partitioning models without modifying core integration routines.
GridFire is a part of the 4D-STAR collaboration.
4D-STAR is funded by European Research Council (ERC) under the Horizon Europe programme (Synergy Grant agreement No. 101071505: 4D-STAR) Work for this project is funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council.
By far the easiest way to install is with pip. This will install either pre-compiled wheels or, if your system has not had a wheel compiled for it, it will try to build locally (this may take a long time). The python bindings are just that and should maintain nearly the same speed as the C++ code. End users are strongly encouraged to use the python module rather than the C++ code.
Installing from pip is as simple as.
These wheels have been compiled on many systems
| Version | Platform | Architecture | CPython Versions | PyPy Versions |
|---|---|---|---|---|
| 0.7.0_rc1 | macOS | arm64 | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (std & t), 3.14 (std & t) | 3.10, 3.11 |
| 0.7.0_rc1 | Linux | aarch64 | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (std & t), 3.14 (std & t) | 3.10, 3.11 |
| 0.7.0_rc1 | Linux | x86_64 | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (std & t), 3.14 (std & t) | 3.10, 3.11 |
| 0.5.0 | macOS | arm64 | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (std & t), 3.14 (std & t) | 3.10, 3.11 |
| 0.5.0 | Linux | aarch64 | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (std & t), 3.14 (std & t) | 3.10, 3.11 |
| 0.5.0 | Linux | x86_64 | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (std & t), 3.14 (std & t) | 3.10, 3.11 |
Note: Currently macOS x86_64 does not have a precompiled wheel. Due to that platform being phased out it is likely that there will never be precompiled wheels or releases for it.
Note: macOS wheels were targeted to macOS 12 Monterey and should work on any version more recent than that (at least as of August 2025).
Note: Linux wheels were compiled using manylinux_2_28 and are expected to work on Debian 10+, Ubuntu 18.10+, Fedora 29+, or CentOS/RHEL 8+
Note: If your system does not have a prebuilt wheel the source distribution will download from pypi and try to build. This may simply not work if you do not have the correct system dependencies installed. If it fails the best bet is to try to build boost >= 1.83.0 from source and install (https://www.boost.org/) as that is the most common broken dependency.
The user may also build the python bindings directly from source
Note: that if you do not have all system dependencies installed this will fail, the steps in further sections address these in more detail.
Note: If you are using macos you should use the included
pip_install_mac_patch.shscript instead ofpip install .as this will automatically patch the build shared object libraries such that they can be loaded by the macos dynamic loader.
If you are a developer and would like an editable and incremental python install meson-python makes this very easy
This will generate incremental builds whenever source code changes, and you run a python script automatically (note that since meson setup must run for each of these it does still take a few seconds to recompile regardless of how small a source code change you have made). It is strongly recommended that developers use this approach and end users do not.
If you need to patch shared object files generated by meson-python directly you should first locate the shared object file these will be in the site-packages and site-packages/fourdst directories for your python environment.
Look for files named
site-packages/gridfire.cpython-3*-darwin.sosite-packages/fourdst/_phys.cpython-3*-darwin.sothen, for each of these files, run
count the number of occurrences of duplicate RPATH entries (these should look like @loaderpath/.gridfire.mesonpy.libs or @loaderpath/../.fourdst.mesonpy.libs). Then use install_name_tool to remove all but one of these from each shared object file.
If for example there are 4 occurrences of the path @loader_path/../.fourdst.mesonpy.libs in _phys.cpython-3*-darwin.so then you should run the following command 3 times
the same for the other shared object file (make sure to count the duplicate rpath entries for each separately as there may be a different number of duplicates in each shared object file).
We also include a script at pip_install_mac_patch.sh which will do this automatically for you.
The easiest way to build GridFire is using the install.sh or install-tui.sh scripts in the root directory. To use these scripts, simply run:
The regular installation script will select a standard "ideal" set of build options for you. If you want more control over the build options, you can use the install-tui.sh script, which will provide a text-based user interface to select the build options you want.
Generally, both are intended to be easy to use and will prompt you automatically to install any missing dependencies.
The installation script has been tested and found to work on clean installations of the following platforms:
Note: On Ubuntu 22.04 the user needs to install boost libraries manually as the versions in the Ubuntu repositories are too old. The installer automatically detects this and will instruct the user in how to do this.
These only need to be manually installed if the user is not making use of the install.sh or install-tui.sh
meson-python>=0.15.0install.sh script, not needed if using pip or meson directly)install.sh script or by calling pip directly, not needed if using meson directly)Note: Boost is the only external library dependency used by GridFire directly.
Note: Windows is not supported at this time and there are no plans to support it in the future. Windows users are encouraged to use WSL2 or a Linux VM.
Note: If
install-tui.shis not able to find a usable version of boost it will provide directions to fetch, compile, and install a usable version.
GridFire ships with an installer (install.sh) which is intended to make the process of installation both easier and more repeatable.
Both scripts are intended to automate installation more or less completely. This includes dependency checking. In the event that a dependency cannot be found they try to install (after explicitly asking for user permission). If that does not work they will provide a clear message as to what went wrong.
The TUI mode provides easy modification of meson build system and compiler settings which can then be saved to a config file. This config file can then be loaded by either tui mode or cli mode (with the --config) flag meaning that build configurations can be made and reused. Note that this is not a deterministically reproducible build system as it does not interact with any system dependencies or settings, only meson and compiler settings.
Note:
install-tui.shis simply a script which callsinstall.shwith the--tuiflag. You can get the exact same results by runninginstall.sh --tui.
Note: Call
install.shwith the--helpor--hflag to see command line options
Note:
clangtends to compile GridFire much faster thangccthus why I select it in the above asciinema recording.
Note: Depending on the ubuntu version you have the libboost-all-dev libraries may be too old. If this is the case refer to the boost documentation for how to download and install a version
>=1.83.0
Note: On recent versions of ubuntu python has switched to being externally managed by the system. We strongly recommend that if you install manually all python packages are installed inside some kind of virtual environment (e.g.
pyenv,conda,python-venv, etc...). When using the installer script this is handled automatically usingpython-venv.
As noted above clang tends to compile GridFire much faster than gcc. If your system has both clang and gcc installed you may force meson to use clang via environmental variables
GridFire uses C++23 features and therefore only compilers and standard library implementations which support C++23 are supported. Generally we have found that gcc >= 13.0.0 or clang >= 16.0.0 work well.
GridFire is organized into a series of composable modules, each responsible for a specific aspect of nuclear reaction network modeling. The core components include:
GraphEngine) that evaluate reaction network rate equations and energy generation. Also implemented Views submodule.MultiscalePartitioningEngineView) which can be used to make a problem more tractable or applicable.WeakScreening (Salpeter, 1954), BareScreening) affecting reaction rates.GroundStatePartitionFunction, RauscherThielemannPartitionFunction (Rauscher & Thielemann, 2000) to weight reaction rates based on nuclear properties.CVODESolverStrategy) for solving the stiff ODE systems arising from reaction networks.ProtonProtonReactionChainPolicy enforces than an engine must include at least all the reactions in the proton-proton chain. This module exposes the primary construction interface for users. I.e. select a policy (such as MainSequencePolicy), provide a composition, and get back an engine which satisfies that policy.Generally a user will start by selecting a base engine (currently we only offer GraphEngine), which constructs the full reaction network graph from a given composition. The user can then apply various engine views to adapt the network topology, such as partitioning fast and slow reactions, adaptively culling low-flow pathways, or priming the network with specific species. Finally, a numerical solver is selected to integrate the network over time, producing updated abundances and diagnostics.
GridFire is, at its core, based on a series of Engines. These are constructs which know how to report information on series of ODEs which need to be solved to evolve abundances. The important thing to understand about Engines is that they contain all the detailed physics GridFire uses. For example a Solver takes an Engine but does not compute physics itself. Rather, it asks the Engine for stuff like the jacobian matrix, stoichiometry, nuclear energy generation rate, and change in abundance with time.
Refer to the API documentation for the exact interface which an Engine must implement to be compatible with GridFire solvers.
Currently, we only implement GraphEngine which is intended to be a very general and adaptable Engine.
In GridFire the GraphEngine will generally be the most fundamental building block of a nuclear network. A GraphEngine represents a directional hypergraph connecting some set of atomic species through reactions listed in the JINA Reaclib database.
GraphEngines are constructed from a seed composition of species from which they recursively expand their topology outward, following known reaction pathways and adding new species to the tracked list as they expand.
GraphEngine exposes runtime configuration methods to tailor network construction and rate evaluations:
composition: The initial seed composition to start network construction from.BuildDepthType (Full, Shallow, SecondOrder, etc...): controls number of recursions used to construct the network topology. Can either be a member of the NetworkBuildDepth enum or an integer.partition::PartitionFunction: Partition function used when evaluating detailed balance for inverse rates.NetworkConstructionFlags: A bitwise flag telling the network how to construct itself. That is, what reaction types should be used in construction. For example one might use NetworkConstructionFlags::STRONG | NetworkConstructionFlags::BETA_PLUS to use all strong reactions and β+ decay. By Default this is set to use reaclib strong and reaclib weak (no WRL included by default due to current pathological stiffness issues).BARE, WEAK).| Function Name | Identifier / Enum | Description |
|---|---|---|
GroundStatePartitionFunction | "GroundState" | Weights using nuclear ground-state spin factors. |
RauscherThielemannPartitionFunction | "RauscherThielemann" | Interpolates normalized g-factors per Rauscher & Thielemann. |
CompositePartitionFunction | "Composite" | Combines multiple partition functions for situations where different partitions functions are used for different domains |
One of the primary tasks any engine must accomplish is to report the jacobian matrix of the system to the solver. GraphEngine uses CppAD, a C++ auto differentiation library, to generate analytic jacobian matrices very efficiently.
All reactions in JINA Reaclib which only include reactants iron and lighter were downloaded on June 17th, 2025 where the most recent documented change on the JINA Reaclib site was on June 24th, 2021.
All of these reactions have been compiled into a header file which is then statically compiled into the gridfire binaries (specifically into lib_reaction_reaclib.cpp.o). This does increase the binary size by a few MB; however, the benefit is faster load times and more importantly no need for end users to manage resource files.
If a developer wants to add new reaclib reactions we include a script at utils/reaclib/format.py which can ingest a reaclib data file and produce the needed header file. More details on this process are included in utils/reaclib/readme.md
The GridFire engine supports multiple engine view strategies to adapt or restrict network topology. Generally when extending GridFire the approach is likely to be one of adding new EngineViews.
| View Name | Purpose | Algorithm / Reference | When to Use |
|---|---|---|---|
| AdaptiveEngineView | Dynamically culls low-flow species and reactions during runtime | Iterative flux thresholding to remove reactions below a flow threshold | Large networks to reduce computational cost |
| DefinedEngineView | Restricts the network to a user-specified subset of species and reactions | Static network masking based on user-provided species/reaction lists | Targeted pathway studies or code-to-code comparisons |
| FileDefinedEngineView | Load a defined engine view from a file using some parser | Same as DefinedEngineView but loads from a file | Same as DefinedEngineView |
| MultiscalePartitioningEngineView | Partitions the network into fast and slow subsets based on reaction timescales | Network partitioning following Hix & Thielemann Silicon Burning I & II (DOI:10.1086/177016,10.1086/306692) | Stiff, multi-scale networks requiring tailored integration |
| NetworkPrimingEngineView | Primes the network with an initial species or set of species for ignition studies | Single-species ignition and network priming | Investigations of ignition triggers or initial seed sensitivities |
These engine views implement the common Engine interface and may be composed in any order to build complex network pipelines. New view types can be added by deriving from the EngineView base class, and linked into the composition chain without modifying core engine code.
There are certain functions for which it is expected that a call to an engine view will propagate the result down the chain of engine views, eventually reaching the base engine (e.g. DynamicEngine::update). We do not strongly enforce this as it is not hard to contrive a situation where that is not the mose useful behavior; however, we do strongly encourage developers to think carefully about passing along calls to base engine methods when implementing new views.
GridFire defines a flexible solver architecture through the networkfire::solver::NetworkSolverStrategy interface, enabling multiple ODE integration algorithms to be used interchangeably with any engine that implements the Engine or DynamicEngine contract.
All GridFire solvers implement the abstract strategy templated by NetworkSolverStrategy which enforces only that there is some evaluate method with the following signature
Which is intended to integrate some network over some time and returns updated abundances, temperature, density, and diagnostics.
GridFire solvers use a unified input and output type for their public interface (though as developers will quickly learn, internally these are immediately broken down into simpler data structures). All solvers expect a NetIn struct for the input type to the evaluate method and return a NetOut struct.
A NetIn struct contains
NetIn::composition)NetIn::temperature)NetIn::density)NetIn::tMax)NetIn::dt0)NetIn::energy)>Note: It is often useful to set NetIn::dt0 to something very small and >let an iterative time stepper push the timestep up. Often for main sequence >burning I use ~1e-12 for dt0
>Note: The composition must be a fourdst::composition::Composition >object. This is made available through the foursdt library and the >fourdst/composition/Composition.h header. fourdst is installed >automatically with GridFire
>Note: In Python composition comes from fourdst.composition.Composition >and similarly is installed automatically when building GridFire python >bindings.
A NetOut struct contains
tMax (NetOut::composition)tmax (NetOut::num_steps)tMax (NetOut::energy) [erg/g]NetOut::dEps_dT)NetOut::dEps_dRho)tMax (NetOut::total_neutrino_loss) [erg/g]tMax (NetOut::total_neutrino_flux)We use the CVODE module from SUNDIALS as our primary numerical solver. Specifically we use the BDF linear multistep method from that which includes advanced adaptive timestepping.
Further, we use a trigger system to periodically repartition the network as the state of the network changes. This keeps the stiffness of the network tractable. The algorithm we use for that is
Moreover, callback functions can be registered in either python or C++ which will take a const CVODESolverStrategy::TimestepContext& struct as argument. This allows for more complex logging logic. Note that callbacks do not let you reach inside the solver and adjust the state of the network. They are only intended for investigation not extension of physics. If you wish to extend the physics this must be implemented at the engine or engine view level.
Through the Python bindings, users can subclass engine view classes directly in Python, override methods like evaluate or generateStoichiometryMatrix, and pass instances back into C++ solvers. This enables rapid prototyping of custom view strategies without touching C++ sources.
A representative workflow often composes multiple engine views to balance accuracy, stability, and performance when integrating stiff nuclear networks:
Custom callback functions can be registered with any solver. Because it might make sense for each solver to provide different context to the callback function, you should use the struct gridfire::solver::<SolverName>::TimestepContext as the argument type for the callback function. This struct contains all the information provided by that solver to the callback function.
>Note: If you want to see exactly why each repartitioning stage was triggered in a human readable manner add the flag True to solver.evaluate (solver.evaluate(input, true)).
>Note: A fully detailed list of all available information in the TimestepContext struct is available in the API documentation.
>Note: The order of species in the boost state vector (ctx.state) is not guaranteed to be any particular order run over run. Therefore, in order to reliably extract
values from it, you must use the
getSpeciesIndexmethod of the engine to get the index of the species you are interested in (these will always be in the same order).
If you wish to know what is provided by a solver context without investigating the code you can simply do
If you set this as the callback (to any solver strategy) it will print out the available parameters and what they are and then close the code. This is useful when writing new callbacks.
Since each solver may provide different context to the callback function, and it may be frustrating to refer to the documentation every time, we also enforce that all solvers must implement a descripe_callback_context method which returns a vector of tuples<string, string> where the first element is the name of the field and the second is its datatype. It is on the developer to ensure that this information is accurate.
The python bindings intentionally look very similar to the C++ code. Generally all examples can be adapted to python by replacing includes of paths with imports of modules such that
#include "gridfire/engine/GraphEngine.h" becomes import gridfire.engine.GraphEngine
All GridFire C++ types have been bound and can be passed around as one would expect.
The syntax for registration is very similar to C++. There are a few things to note about this more robust example
C++ does not have a stable ABI nor does it make any strong guarantees about stl container layouts between compiler versions. Therefore, GridFire includes a set of stable C bindings which can be used to interface with a limited subset of GridFire functionality from other languages.
Note: These bindings are not intended to allow GridFire to be extended from other languages; rather, they are intended to allow GridFire to be used as a black-box library from other languages.
Note: One assumption for external usage is that the ordering of the species list will not change. That is to say that whatever order the array used to register the species is will be assumed to always be the order used when passing abundance arrays to and from GridFire.
Note: Because the C API does not pass the general Composition object a
mass_lostoutput parameter has been added to the evolve calls, this tracks the total mass in species which have not been registered with the C API GridFire by the caller
## C API Overview In general when using the C API the workflow is to
gf_context pointer. This object holds the state of GridFire so that it does not need to be re-initialized for each call.gf_evolve function to evolve a network over some time.gf_free to free the context and all associated memory.GridFire makes use of the stable C API and Fortran 2003's iso_c_bindings to provide a Fortran interface for legacy code. The fortran interface is designed to be very similar to the C API and exposes the same functionality.
GridFiregff_init: Initializes a GridFire context and returns a handle to it.GridFireregister_species: Registers species with the GridFire context.GridFiresetup_policy: Configures the engine using a specified policy and initial abundances.GridFiresetup_solver: Sets up the solver for the engine.GridFireevolve: Evolves the network over a specified time step.GridFireget_last_error: Retrieves the last error message from the GridFire context.GridFiregff_free: Frees the GridFire context and associated resources.Note: You must instantiate a
GridFiretype object to access these methods.
Note: free and init have had the
gff_prefix (GridFire Fortran) to avoid name clashes with common Fortran functions.
When building GridFire a fortran module file gridfire_mod.mod is generated which contains all the necessary bindings to use GridFire from Fortran. You must also link your code against the C API library libgridfire_extern.
GridFire integrates with and builds upon several key 4D-STAR libraries:
libcomposition, libconfig, liblogging, and libconstants