GKX
GKX is a JAX gyrokinetic solver for tokamak and stellarator flux tubes. It reads a VMEC or VMEX equilibrium, or builds an analytic Miller or s-alpha geometry, and computes linear stability and nonlinear turbulence in a Hermite-Laguerre velocity basis. The whole path, equilibrium included, is differentiable on CPUs and GPUs.
- Run what you have: a VMEC/VMEX
wout, a Miller or s-alpha tokamak, or one TOML deck. The executable sizes the grid and says why. - Trust the eigenvalue: every returned eigenpair is checked against the full operator; an under-resolved run warns instead of reporting a number.
- Differentiate it: implicit eigenvalue derivatives, and a checkpointed adjoint of the nonlinear heat flux over a saturated window.
- Optimize with it: the heat flux, growth rate or quasilinear flux is an objective in VMEX stellarator shape optimization.
Saturated ITG turbulence on a Cyclone flux tube (full-rate movie).
Install and first run
pip install gkx
gkx
Python 3.10+. The wheel installs CPU JAX; for GPUs add an accelerator JAX wheel
(JAX install guide).
gkx with no arguments runs a linear Cyclone case in under a minute on a
laptop CPU and prints gamma and omega; a CI gate holds its growth rate
within 1% of the certified eigenvalue. The tutorial walks
through twelve runs, from this one to a stellarator optimization; each is a
directory in examples/.
Run a case
gkx wout_circular_tokamak.nc --estimate # size the grid, explain it, exit
gkx wout_circular_tokamak.nc # nonlinear ITG run to saturation
gkx plot wout_circular_tokamak/gkx.out.nc # replot a saved bundle
gkx examples/01_linear_tokamak/case.toml # any TOML deck
--estimate derives each grid entry from the geometry and prints the reason. A
run stops when heat flux, field energy and free energy are stationary, or
reports that it did not. It writes figures, a restartable NetCDF bundle and the
resolved deck that reproduces it (inputs,
outputs).
From Python:
import gkx
case = gkx.load("examples/01_linear_tokamak/case.toml")
result = gkx.solve(
case, ky_target=0.3, Nl=case.run.Nl, Nm=case.run.Nm, show_progress=True
)
print(result.gamma, result.omega)
Models and defaults
| Choice | Default | Notes |
|---|---|---|
| Geometry | s-alpha, Miller, VMEC/VMEX, imported | [geometry] model; gkx wout_*.nc for any VMEC |
| Velocity space | Hermite-Laguerre, (Nl, Nm), per species with [[species]] Nl/Nm |
hypercollisions damp the last Hermite moments; kinetic-electron decks that name no resolution get ions (12, 32) and electrons (6, 48) linear, (4, 16) nonlinear (guidance) |
| Hermite closure (opt-in) | [[species]] hermite_closure = "reflectionless" |
absorbing last-moment closure per species: TEM growth rate +4-11% at Nm 16, +1-2% at Nm >= 48; not the default (numerics) |
| Perpendicular velocity (opt-in) | nodal mu grid: [run] mu_vperp_max = 4.0, Nl = nodes |
linear runs; 8 nodes match Laguerre Nl 16-24 on Cyclone at 5-12x less cost; flat convergence on TEM and KBM (numerics) |
| Collisions | linearized Landau | conserving, H-theorem; Dougherty, Sugama alternatives (operators) |
| End damping | one rate, [time] damp_ends_rate |
same on every route; no time step enters (numerics) |
| Time stepping | no dt: nonlinear rk4-pi, or adaptive imex-ark3 for kinetic electrons at beta <= 3e-4; linear rk4 + CFL |
a dt gives rk2 at that step; fixed_dt = false keeps the controller's stepper (measured speedups) |
| Eigensolver | auto: banded direct shift-invert where it fits, else Arnoldi on the time-advance map; every pair certified |
matrix-free shift-invert opt-in (algorithms) |
| SOLVAX | solvax>=0.33.0 |
provides the sparse eigensolver and the rk4-pi stepper; installed with pip install gkx |
ky layout |
half: the 1 + Ny//2 non-negative rows |
[grid] ky_layout = "full" stores the two-sided axis; same physics to round-off, about 1.4-1.8x slower and 12-25% more memory |
| Drift kernel | fused Pallas kernel on NVIDIA GPUs when Nx*Nz >= 64 and Nl*Nm <= 256 |
default there; CPU and other GPUs keep the jnp terms, which derivatives use (performance) |
| Devices | one device | [parallel] strategy = "batch", axis = "ky", num_devices spreads independent k_y scans and ensembles; results match the serial run (parallelization) |
| Precision | float32; float64 with JAX_ENABLE_X64=true |
eigensolver, Krylov residual and conditioning checks need float64 |
| CPU threads | XLA's own; Eigen pool off on fewer than four CPUs | steps do not scale past about four threads (performance) |
Resolution, step and solver guidance says what to set for kinetic electrons and electromagnetic runs, and how to check it.
Agreement with other codes
| Case (reference) | Quantity | Agreement |
|---|---|---|
| KAW (analytic dispersion) | gamma, omega | gamma 0.0004%, omega 0.051% |
| ETG (GX) | gamma, omega | gamma 0.040%, omega 0.074% |
| W7-X (GX) | gamma, omega | gamma 0.265%, omega 0.296% |
| HSX (GX) | gamma, omega | gamma 0.577%, omega 0.273% |
| Cyclone ITG and Miller (GX) | gamma | within 0.3% at 7 of 8 k_y |
| Cyclone ITG and Miller (GS2) | gamma | within 2.4% at five points, 0.3% at two |
| Cyclone Miller, kinetic electrons (GX, GS2) | gamma, omega | within 0.4% of GX, 1.5% of GS2 |
W7-X bean tube, k_y rho_i 2.1 (GX, Gonzalez-Jerez 2022) |
gamma, omega | 0.1750, 0.2628 as GX; paper 0.172, 0.27 |
| KBM, beta 0.015 (GS2) | gamma | 3.2% at the ntheta limit of each code |
| Nonlinear Cyclone heat flux (GX paper Table 1) | Q_i/Q_GB | 7.08 +- 0.12 against 7.2 +- 0.8 |
Linear scan rows are 100 * max|GKX - ref| / max|ref| over the scan, checked
against the evidence ledger in CI. These are
agreements on shared test cases, not a ranking of codes. Cases, resolutions,
open items and provenance are in validation.
Nonlinear turbulence
(a) A circular tokamak run straight from a VMEC wout, replicated with two
seeds and a second time step: window means 18.7, 19.3 and 18.9 over
t = 350-700, a 3.5% spread against a 15% gate. (b) Mean relative difference
from GX runs of the same decks in heat flux, free energy and field energy for
Cyclone, Cyclone Miller, W7-X, HSX and KBM, all below 10%. This is a window
comparison, not a validation of saturated transport.
Derivatives and optimization
Eigenvalue derivatives use dλ/dp = wᴴ(dA/dp)v / (wᴴv). The nonlinear heat
flux over a post-saturation window is differentiated through a
block-checkpointed discrete adjoint
(figure): on a 16x16x16
Cyclone case over 1024 steps, checkpointing cuts temporary memory from 7.8 GB to
187 MB for about twice the runtime, and the gradient matches finite differences
to 1e-11 through 512 steps.
heat_flux, gradient = jax.value_and_grad(loss)(shape0)
VMEX composes its implicit equilibrium
derivative with GKX's, so a growth rate, quasilinear flux or nonlinear heat flux
sits next to quasisymmetry, aspect ratio and iota in one least-squares problem.
examples/10_vmex_optimization/run.py extends VMEX's QA_optimization.py with
the nonlinear heat flux as a fourth objective on the vacuum QA ladder (equilibria,
traces).
The boundary change is small (aspect ratio +0.0115%, mean iota -0.044%). The preliminary 12.26% reduction across 24 nominal pairs (conditional 95% CI 10.64-13.88%) is not statistically resolved: 4 of 48 nominal traces fail the per-trace drift test. A transport claim needs matched, replicated, long post-saturation windows. The quasilinear flux is a ranking and screening measure, not a runtime/TOML absolute-flux predictor (quasilinear, stellarator optimization).
Performance
- Nonlinear step: about 196 ns per
Nx*Ny*Nz*Nl*Nmelement per step on CPU; 15.6 ms for 64x64x24, Nl = 4, Nm = 8 on one RTX A4000. - Eigenvalues: the sparse direct shift-invert route certifies the Cyclone eigenpair at n = 3,072 in about 5 s against 32-36 s matrix-free.
- Kinetic electrons:
imex-ars3is 10x faster to solution than RK3 at 64x64x24, and does not pay on tutorial grids. The adaptiveimex-ark3default holds the error per step to 1e-3: its saturated heat flux averages within 1% ofrk4-pi(three seeds, 32x32x16) at about 2x the steps of 1e-2, which read 6% high (guidance). - Parallel work: independent
k_yscans and ensembles run across devices with results identical to the serial run.
Each species can keep its own Nl and Nm, so ions do not pay for the
electrons' Hermite moments. Against uniform counts the growth rate agrees to
1.6% on Cyclone ITG, TEM, ETG-range and QA stellarator decks and the nonlinear
heat-flux window mean to 2%; an explicit 64x64x24 step is 1.1-1.9x faster in
1.3-1.5x less memory. The implicit imex factor and collision sub-step also
run at each species' own counts: with ions (8, 16) and electrons (4, 32) the
32x32x16 factor is 3.3x smaller and a solve 2.2x faster, and 64x64x24 fits a
16 GB GPU where the padded factor does not (guidance).
Performance · parallelization.
Documentation and development
Documentation: gkx.readthedocs.io. Start with the tutorial and the guidance page; equations and algorithms are in theory, operators and numerics; modules in design.
git clone https://github.com/uwplasma/GKX
cd GKX
pip install -e ".[dev]"
pytest -n 4
CI requires 95% line coverage plus the physics, convergence, comparison,
differentiability and performance gates (CONTRIBUTING.md).
Figures in docs/_static/readme/ have JSON companions with every plotted
number. Cite GKX with CITATION.cff.
License
MIT; see LICENSE.
Metadata
Release files for gkx 2.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gkx-2.8.1.tar.gz | 638.3 kB | With provenance | Details for gkx-2.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gkx-2.8.1-py3-none-any.whl | Python 3 | none | any | Details for gkx-2.8.1-py3-none-any.whl |
Total release size: 1.3 MB
Release files / gkx-2.8.1.tar.gz
| Download URL | gkx-2.8.1.tar.gz |
|---|---|
| Size | 638.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f81a4fc5e9acbf8c341f2e7a43e4bdc0a5b645779a4f8e712ef98ca728b063f
|
|
BLAKE2b-256 checksum How to use checksums |
945fc0f2e4320cb9e7adab8984b9cfa5998957d07cb7a443448855707323cab6
|
| 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 3, 2026.
Transparency logRelease files / gkx-2.8.1-py3-none-any.whl
| Download URL | gkx-2.8.1-py3-none-any.whl |
|---|---|
| Size | 699.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6e6272552a359c6fc757a648699d50721c83795f0602bd265e04043522e5509
|
|
BLAKE2b-256 checksum How to use checksums |
9b67b2b04dec17ebc7b1763c0ee76543fb4442aeb5a0763083fe760e3a6a44a3
|
| 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 3, 2026.
Transparency logSecurity for gkx 2.8.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.
Attestation for gkx-2.8.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 3, 2026.
Transparency logA 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.