Skip to main content

agnimhd

CI codecov docs PyPI DOI

AGNI is a differentiable finite-n ideal MHD stability solver. It discretizes the ideal MHD energy principle on a straight-field-line grid and returns the squared growth rate of the most unstable mode (positive: unstable) and its gradient. It computes the stability objective but does not run an optimization itself.

The package is under active development, and the API, the file format and the numerics change without notice. It is the successor of the AGNI implementation in DESC, PR #1893.

Quick start

Stability of a DESC equilibrium (needs DESC installed):

agnimhd solve my_equilibrium.h5 --res 24,12,8

prints gamma^2 for each toroidal mode family n = x + k NFP, all solved on one field period, and names the most unstable.

From Python:

import agnimhd

basis = agnimhd.Basis(24, 12, 8)                 # n_zeta = 8 per field period
eq, diffmat = agnimhd.from_desc("my_equilibrium.h5", basis, family=0)
gamma2 = agnimhd.growth_rate(eq, diffmat)        # gamma^2 = -lambda > 0: unstable

growth_rate(eq, diffmat) is solve mode and is not differentiable. The gradient comes from optimize mode, jax.grad(agnimhd.growth_rate)(params, diffmat, equilibrium_map=f), with f the equilibrium code's map from its parameters to an EquilibriumData.

Matrices too large for one GPU: SolverConfig(eigensolver="dense_mg") splits the dense matrix over all GPUs of a node with JAXMg (tested with jaxmg==0.0.9). A matrix of 182,784 unknowns takes 8.5 minutes on four A100s. See the multi-GPU page of the documentation.

Two shipped cases run without DESC: python examples/eigenfunction.py. Other codes build an EquilibriumData from arrays, or load a saved one with EquilibriumData.load("eq.npz"). See the documentation.

Install

pip install agnimhd               # jax, numpy, scipy, matfree
pip install "agnimhd[hdf5,test]"  # HDF5 files and the test suite

Python 3.12. DESC is optional and only needed for from_desc and desc_from_eqdsk. GPU, DESC and multi-GPU set-ups: Installation.

Development

pip install -e ".[dev]"
pre-commit install
pytest tests -q          # about 25 min on one CPU

Releasing: tag vX.Y.Z on master and publish a GitHub release of it. The release workflow builds the package from the tag and uploads it to PyPI, and Zenodo archives the release with a DOI. The version comes from the tag (setuptools_scm), and nothing in the source is edited.

Reference

R. Gaur, S. Patil, P. Gupta, D. Patch, T. Qian, AGNI: A differentiable MHD stability solver & optimizer for magnetic confinement fusion devices, arXiv:2608.01750 (2026), doi:10.48550/arXiv.2608.01750. PDF of v3 in this repository: docs/paper/agni_arxiv_2608.01750v3.pdf. The software is archived on Zenodo, all versions: doi:10.5281/zenodo.23410169.

@article{gaur2026agni,
  title   = {{AGNI}: A differentiable {MHD} stability solver \& optimizer for magnetic confinement fusion devices},
  author  = {Gaur, Rahul and Patil, Sanket and Gupta, Prateek and Patch, Djin and Qian, Tony},
  journal = {arXiv preprint arXiv:2608.01750},
  year    = {2026},
  doi     = {10.48550/arXiv.2608.01750}
}

Originally developed inside DESC (PR #1893, on the differentiation matrices of PR #1789). MIT license.

The EFIT g-file conversion, desc_from_eqdsk, is a port of efit2desc: D. Panici, efit2desc: a Python tool for converting an EFIT g-file to a (fixed-boundary) DESC Equilibrium, github.com/dpanici/efit2desc (2025), MIT license.

Metadata

Release files for agnimhd 0.3.1

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

Source distribution (sdist)

Source distribution for agnimhd 0.3.1
File Size Uploaded Provenance Actions
agnimhd-0.3.1.tar.gz 122.8 kB With provenance Details for agnimhd-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 240.8 kB

Release files / agnimhd-0.3.1.tar.gz

Download URL agnimhd-0.3.1.tar.gz
Size 122.8 kB
Tags Source
SHA-256 checksum
How to use checksums
012c429e02fa4917beb72c7058b342e09f5ef50432aaaca6a74cb00db20448ad
BLAKE2b-256 checksum
How to use checksums
23ccb055fe53ce46298cf2d961cbf6c6e2499db0a6d073323c341652f9839ff6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / agnimhd-0.3.1-py3-none-any.whl

Download URL agnimhd-0.3.1-py3-none-any.whl
Size 118.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f36e4f856107d4f2896ab168c0a3c2d884b368f726212f0967190e37f0ef55e
BLAKE2b-256 checksum
How to use checksums
36ab398513758fa9a8c7e0c86bbbf69a4d0584c53bc3f761ec66b9008651d917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for agnimhd 0.3.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agnimhd-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

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