Skip to main content

ALFVEX

Tests Docs License: MIT

ALFVEX is a lean JAX code for shear-Alfvén physics in stellarators: the continuum, AE3D-form global modes and a perturbative fast-ion drive, with first-order derivatives with respect to profiles and, through VMEX, the VMEC boundary.

CTOK continuum and global modes Könies TAE drive

Left: the n = 2 CTOK continuum with the six global modes nearest 384 kHz (red). Right: the passing-only drive of the Könies et al. (2018) TAE.

Scope

Supported Not supported
Low-β continuum on each Boozer surface (STELLGAP form) Sound coupling in the global modes, so no BAE or BAAE eigenmodes (the continuum has it, opt-in)
Real potentials: each harmonic on both signs, solved as cosine and sine sectors for stellarator-symmetric geometry The drive reads a mode as a travelling wave unless growth_rate(..., standing=True) (a sector mode)
AE3D-form reduced ideal-MHD global modes, signed $\omega^2$ Continuum damping and electron damping
finite_beta=True: restricted $J_\parallel$ and pressure terms (experimental) A full-MHD or compressional model
Drive of a fixed mode: zero orbit width, passing ions only Trapped particles, finite orbit width, finite Larmor radius

The drive is perturbative and valid up to about 200 keV in the Könies case ($\gamma/\omega \le 4%$). It is about 0.6 of the CAS3D-K zero-orbit-width curve; the ratio is unexplained (see the validation page). Derivatives are first order and are NaN unless the eigensolve converged and its selection is not a tie.

Install

Python 3.10 or newer, JAX 0.4.38 or newer, solvax>=0.36.0. ALFVEX is on PyPI as alfvex. Versions up to 1.2.1 are imported as fax, from 2.0.0 as alfvex. Do not pip install fax: that is an unrelated package.

pip install alfvex            # core
pip install "alfvex[vmex]"    # VMEC solves and boundary gradients (Python >= 3.11)
pip install "alfvex[plot]"    # matplotlib, for the figure examples

From a clone, pip install . (with the same extras) installs the development version.

Quickstart

This runs from an installed wheel with no data files: a continuum, a global TAE and one gradient on the analytic Könies et al. (2018) torus.

import jax, jax.numpy as jnp, alfvex

s = (jnp.arange(200) + 0.5) / 200
geo = alfvex.circular_torus(s=s, major_radius=10.0, minor_radius=1.0, B0=3.0, iota=1 / (1.71 + 0.16 * s), epsilon_B=0.1)
harmonics, rho = alfvex.mode_family(6, 16, 5), alfvex.mass_density(2e19, 1.00727647)
f_hz = alfvex.continuum(geo, harmonics, rho)  # (surfaces, harmonics)
modes = alfvex.eigenmodes(geo, harmonics, rho, target_hz=6.46e4, count=3, ntheta=32, nzeta=4)
print(modes.frequencies_hz[-1], modes.status.converged)  # the TAE, 64.63 kHz
f = lambda r: alfvex.frequency_hz(geo, harmonics, r, 2, 3, target_hz=6.46e4, count=3, ntheta=32, nzeta=4)
print(jax.grad(f)(rho))  # equals -f / (2 rho)

The command line runs the continuum and global-mode tasks from a TOML case; the drive, objectives and boundary gradients are Python only.

Examples (checkout only)

These read files in the repository or need an extra; each is a plain script with its settings at the top and no command-line parsing.

File Needs Shows
examples/quickstart.py nothing the quickstart above, plus gaps, a dense solve and the smooth objectives
examples/ctok_boozmn.py, ctok_continuum.toml, ctok_eigenmodes.toml tests/data CTOK from a boozmn file: the TOML cases, the Python API and alfvex run <case> --plot
examples/qa_vmex.py, qa_continuum.toml vmex VMEC solve, Boozer transform, continuum and the gradient with respect to boundary coefficients
examples/koenies_tae_drive.py plot fast-ion drive against temperature, slowing-down ions and Landau damping
examples/optimize_alfven.py vmex, plot QS plus Paul's continuum cost (QH) or a classified gap-mode window (QA)
examples/knyazev_qa.py tests/data, plot the STELLGAP and AE3D comparison; RESEARCH and an archive rebuild the fixture
examples/benchmark.py tests/data equal-accuracy timings of the eigensolvers

Every script has a RESEARCH = False switch at the top: the default is a fast run, True selects the finer settings and extra analysis.

Evidence

Check Result
STELLGAP CTOK continuum (97 surfaces), outer Boozer half surface restored 4.2e-3 mean, 7.0e-3 maximum relative
AE3D v31 CTOK, six global modes within 0.19–1.35% in frequency; two of them (738.2, 741.2 kHz) in frequency only (inertia-norm cosine 0.37, 0.08)
AE3D CTOK TAE, 337.9 kHz not reproduced. On identical input three $\iota'$ terms of AE3D's bending blocks differ from the energy (pinned block comparison; real-space quadrature ALFVEX 0.1–0.3%, AE3D 2–37%). The $J_\parallel$ blocks still disagree, cause open. Not reported upstream
Knyazev et al. (2026) precise QA continuum 3.0e-3 mean from STELLGAP. The AE3D global mode (30.31 kHz) is not an ALFVEX eigenmode (overlap 0.18, 5.1% below); cause unresolved
Könies et al. (2018) TAE (n = 6) 4.061e5 rad/s (CAS3D 4.01e5, GYGLES 4.13e5), converged to 1e-4
Drive, 100/200/300/400 keV 4.29/16.39/32.72/64.48 ×10³ s⁻¹; 0.58–0.60 of CAS3D-K ZOW at 82–191 keV (content unmatched, not a validation)
Gradients fixed-geometry AD vs finite differences to about 1e-9 at best; LP-QA gap-mode shift of 4 kHz predicted to 0.05 kHz, resolution budget 0.13 kHz; the $m = 1$ gauge leaves a 1e-2 floor on zs11, not closed

The validation page has every gate, its test and what is not done.

Ecosystem

SOLVAX provides the generalized eigensolver and its implicit derivatives; VMEX the equilibrium and its implicit derivative; booz_xform_jax the Boozer transform. ESSOS orbit transport of ALFVEX modes is planned, not implemented.

Documentation and testing

alfvex.readthedocs.io: getting started and TOML reference, tutorials, theory, validation, API with its derivative contract.

pip install -e ".[dev,vmex]"
python -m pytest -q -m 'not scheduled'
ruff check . && ruff format --check . && sphinx-build -W -b html docs docs/_build/html

Citing and license

Cite the repository through CITATION.cff and the papers whose models ALFVEX implements (references). MIT license.

Metadata

Release files for alfvex 2.0.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 alfvex 2.0.0
File Size Uploaded Provenance Actions
alfvex-2.0.0.tar.gz 2.0 MB With provenance Details for alfvex-2.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 2.0 MB

Release files / alfvex-2.0.0.tar.gz

Download URL alfvex-2.0.0.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
fdbab37fa9cab35f8295fcf99d5f72e4f36a01a2b4a50fc8b07f8173d136665a
BLAKE2b-256 checksum
How to use checksums
4614e2a1226eea45c751bc600b4dbd93c74c378e61912cd00b641d5568a165d5
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 Dec 1, 2026.

Transparency log

Release files / alfvex-2.0.0-py3-none-any.whl

Download URL alfvex-2.0.0-py3-none-any.whl
Size 60.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b9dcecb34eb49716dcbbe39289aff8f833e7c8ae2820362a8ae42d6c59d84a7
BLAKE2b-256 checksum
How to use checksums
8501033aa9a29d5aec174519f8da9caf446a683229f1bae580f0f4098a7c4e7c
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 Dec 1, 2026.

Transparency log

Security for alfvex 2.0.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.

Full provenance

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

Select from 2 files

Attestation for alfvex-2.0.0.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 Dec 1, 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