Skip to main content

agnimhd

CI 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 is solve mode and is not differentiable. The gradient comes from optimize mode, jax.grad(agnimhd.growth_rate_of)(params, equilibrium_map, diffmat), with equilibrium_map 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.1.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.1.0
File Size Uploaded
agnimhd-0.1.0.tar.gz 95.3 kB Details

Built distribution (wheel)

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

Total release size: 193.1 kB

Release files / agnimhd-0.1.0.tar.gz

Download URL agnimhd-0.1.0.tar.gz
Size 95.3 kB
Tags Source
SHA-256 checksum
How to use checksums
34c87ea3dce27d491505de8b19033e0e179493965c62f59224da45aa7697d461
BLAKE2b-256 checksum
How to use checksums
f90c0305390d7f69fe7a9484bd6d809bc9f702f51f14454eada778e45a64ab7e
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 9, 2026.

Transparency log

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

Download URL agnimhd-0.1.0-py3-none-any.whl
Size 97.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91f3af4a5c80f2a297817604b294f79b4b00b7f90ebc66e57a773a48b0f878dd
BLAKE2b-256 checksum
How to use checksums
4438815f05f4bcf30a4e9bdaadbb24cbcba5b1601a0c80a1a68286511b8089da
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 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

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