Skip to main content

pynucastro

PyPI Version Conda Version

pytest-all pylint flake8 docs build Docs

License

DOI DOI

Binder

pynucastro is a python library for nuclear astrophysics. It provides access to nuclear data and reaction rates, and tools for building and interactively exploring nuclear reaction networks.

The main features are:

  • Easy access to nuclear properties, including T-dependent partition functions, spins, masses, etc.

  • The ability to create a reaction network based on a collection of rates, a set of nuclei, or an arbitrary filter applied to a library.

    • Includes support for ReacLib rates and tabulated weak rates from a variety of sources.
  • Interactive exploration of rates and networks in Jupyter notebooks, including:

    • Many different ways of visualizing a network.

    • The ability to export a NetworkX graph (for instance, to find cycles).

  • Methods to determine which rates are important and which might be missing from a network, as well as analyze the stiffness of a network.

  • The ability to approximate rates and derive reverse rates via detailed balance.

  • An NSE solver to find the equilibrium abundance of a set of nuclei given a thermodynamic state.

  • The ability to write out python or C++ code needed to integrate the network.

  • Additional physics methods for thermal neutrino sources and Fermi-Dirac integrals.

Documentation

Documentation for pynucastro is available here:

https://pynucastro.github.io/pynucastro/

Examples

Exploring a reaction rate

The following example reads in the ReacLib rate database and gets the rate for C13(p,g)N14 and evaluates it at a temperature of 1.e9 K and makes a plot of the T dependence:

In [1]: import pynucastro as pyna

In [2]: rl = pyna.ReacLibLibrary()

In [3]: c13pg = rl.get_rate_by_name("c13(p,g)n14")

In [4]: c13pg.eval(1.e9)
Out[4]: 3883.4778216250666

In [5]: fig = c13pg.plot()

In [6]: fig.savefig("c13pg.png")

The resulting figure is:

Creating a network

The following builds a simple network that has carbon burning, outputs the value of the rates at a set of thermodynamic conditions, and plots the network:

In [1]: import pynucastro as pyna

In [2]: nuclei = ["p", "he4", "c12", "n13", "o16", "ne20", "na23", "mg24"]

In [3]: net = pyna.network_helper(nuclei, use_tabular_rates=False)

In [4]: rho = 1.e7

In [5]: T = 3.e9

In [6]: comp = pyna.Composition(nuclei)

In [7]: comp.set_equal()

In [8]: net.evaluate_rates(rho=rho, T=T, composition=comp)
Out[8]: 
{C12 + p ⟶ N13 + 𝛾: 52860361.23712939,
 C12 + He4 ⟶ O16 + 𝛾: 231.46132999413808,
 O16 + He4 ⟶ Ne20 + 𝛾: 4660.126437920582,
 Ne20 + He4 ⟶ Mg24 + 𝛾: 53650.76987097864,
 Na23 + p ⟶ Mg24 + 𝛾: 71891152.99067408,
 C12 + C12 ⟶ p + Na23: 209.07753161235584,
 C12 + C12 ⟶ He4 + Ne20: 259.65215046037304,
 N13 + He4 ⟶ p + O16: 355698292.6571981,
 O16 + C12 ⟶ He4 + Mg24: 0.8082923986833515,
 Na23 + p ⟶ He4 + Ne20: 6840366554.79809,
 3 He4 ⟶ C12 + 𝛾: 0.12389170353139083,
 N13 ⟶ p + C12: 984313528.3619095,
 O16 ⟶ He4 + C12: 0.00013799339351820605,
 Ne20 ⟶ He4 + O16: 39.38899256329942,
 Mg24 ⟶ p + Na23: 6.121492897494776e-07,
 Mg24 ⟶ He4 + Ne20: 9.835129431742516e-06,
 C12 ⟶ 3 He4: 0.008264918834094248,
 O16 + p ⟶ He4 + N13: 11.428884290229457,
 Ne20 + He4 ⟶ p + Na23: 317753.8001151714,
 Ne20 + He4 ⟶ C12 + C12: 1.929507593099608e-05,
 Na23 + p ⟶ C12 + C12: 0.33819870621531356,
 Mg24 + He4 ⟶ C12 + O16: 1.8802924022864885e-11}

In [9]: fig = net.plot(rotated=True, hide_xalpha=True)

In [10]: fig.savefig("c-net.png")

Here network_helper found all of the rates that link the input nuclei and rederived the reverse rates to be in detailed balance with the forward rates.

The resulting figure is:

Interactive exploration

We can also interactively explore a reaction network. Here's an example of hot-CNO with breakout reactions:

Binder

by increasing the temperature, you can see the transition from CNO to hot-CNO (proton captures on C13 become faster than the beta decay) and then the breakout of hot-CNO when the alpha capture on O14 becomes faster than its decay.

Installation

pynucastro is available on PyPI and can be installed via:

pip install pynucastro

Alternately, to install via source, you can do:

pip install .

for a systemwide install, or

pip install --user .

for a single-user install. This will put the pynucastro modules and library in the default location python searches for packages.

Requirements

pynucastro is supported on Python 3.10 or later and the following libraries:

  • numpy

  • sympy

  • scipy

  • matplotlib

  • networkx

  • ipywidgets

  • numba

To build the documentation or run the unit tests, sphinx and pytest are additionally required along with some supporting packages. See the included requirements.txt and requirements-docs.txt files for a list of these packages and versions. To install the packages from the requirements file, do:

pip install -r requirements.txt -r requirements-docs.txt

It is important to stress out that all the dependencies should be installed before pynucastro, otherwise the installation should be repeated.

Contributing

We welcome contributions from anyone, including posting issues or submitting pull requests to the pynucastro github. For more details on how to contribute to pynucastro, please see CONTRIBUTING.md.

Core Developers

People who make a number of substantive contributions (new features, bug fixes, etc.) will be named "core developers" of pynucastro.

Core developers will be recognized in the following ways:

  • invited to the group's slack team

  • listed in the User's Guide and website as a core developer

  • listed in the author list on the Zenodo DOI for the project (as given in the .zenodo.json file)

  • invited to co-author general code papers / proceedings describing pynucastro. (Note: science papers that use pynucastro will always be left to the science paper lead author to determine authorship).

If a core developer is inactive for 3 years, we may reassess their status as a core developer.

Getting Help

We use our Github Discussions page for requesting help and interacting with the community.

Metadata

Release files for pynucastro 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynucastro 3.2.0
File Size Uploaded Provenance Actions
pynucastro-3.2.0.tar.gz 54.5 MB Without provenance Details for pynucastro-3.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pynucastro 3.2.0
File Interpreter ABI Platform Actions
pynucastro-3.2.0-py3-none-any.whl Python 3 none any Details for pynucastro-3.2.0-py3-none-any.whl

Total release size: 99.4 MB

Release files / pynucastro-3.2.0.tar.gz

Download URL pynucastro-3.2.0.tar.gz
Size 54.5 MB
Tags Source
SHA-256 checksum
How to use checksums
f080040a4a367e35af8b6de6da31022649890eb811127fffda6df317dcd0ffab
BLAKE2b-256 checksum
How to use checksums
27634a9c5765fe76b0af3612a3458a5c7d39636878b3bf1b32aa1a80ebb49ecb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / pynucastro-3.2.0-py3-none-any.whl

Download URL pynucastro-3.2.0-py3-none-any.whl
Size 44.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4392c47f5fa7646080c931ba36c37d0f93f59df2bbb356f02537bab81a20895b
BLAKE2b-256 checksum
How to use checksums
2604604ad058838352d52efbeb3a4ada57ae900cd078725047b204c0a1e58844
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for pynucastro 3.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page