Skip to main content

agnimhd

CI codecov docs PyPI

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; it does not run an optimization itself.

The package is under active development, and the API, the file format and the numerics change without notice. For a stable version use the AGNI implementation inside DESC, PR #1893, branch rg/AGNI_var.

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); 182,784 unknowns in 8.5 minutes on four A100s. See the multi-GPU page of the documentation.

Two shipped cases run without DESC: python examples/cross_sections.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. 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); 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.

@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.

Metadata

Release files for agnimhd 0.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 agnimhd 0.2.0
File Size Uploaded
agnimhd-0.2.0.tar.gz 95.2 kB Details

Built distribution (wheel)

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

Total release size: 192.9 kB

Release files / agnimhd-0.2.0.tar.gz

Download URL agnimhd-0.2.0.tar.gz
Size 95.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bbfcef5ada7e91df10102d8a53ae8d7bdc91749e1986c2909b88c0d8796b8668
BLAKE2b-256 checksum
How to use checksums
a496faf8b0b9b180a03bbbfd904b9e7af10d34571a8308b4f779c47ab00bf3ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

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

Download URL agnimhd-0.2.0-py3-none-any.whl
Size 97.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95d795a361550110378ed4cc902b5b8d293bf526338f03092c8f6c0e6d004aba
BLAKE2b-256 checksum
How to use checksums
d792bcb6cb367317165e04900a7c880ecf92483cfba06b03fa566310fe921be4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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