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.
Illustration of 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 and prints its growth
rate gamma and real frequency omega. 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)
Independent scans and ensembles support parallel workers; nonlinear solves can opt into a species–Hermite device mesh, with serial execution as the default. See parallel execution and features and limitations for supported configurations, identity checks, and eigenmode and finite-window gradient limitations.
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; check resolution and closure sensitivity (numerics) |
| Perpendicular velocity (opt-in) | nodal mu grid: [run] mu_vperp_max = 4.0, Nl = nodes |
linear runs; check node count, velocity extent and agreement with the Laguerre representation (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 (method guidance) |
| 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.35.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; check equivalent states and diagnostics when comparing layouts |
| 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 | choose thread and worker counts by measuring the intended workload (performance) |
Resolution, step and solver guidance says what to set for kinetic electrons and electromagnetic runs, and how to check it.
Validation and comparisons
| Problem | Quantities to compare |
|---|---|
| Slab waves and Landau damping | growth or damping rate, real frequency, dispersion and recurrence |
| Cyclone, Miller, ETG and KBM | eigenpair residual, branch identity, growth rate, frequency and eigenfunction |
| W7-X and HSX flux tubes | geometry profiles, fields, linear modes and transport diagnostics |
| Nonlinear turbulence | stationary heat-flux windows, energies, resolved spectra and replicated-seed uncertainty |
Run the input decks in benchmarks/cases and the workflows in examples, then compare the same model, geometry, normalization, resolution, timestep policy, collisions and diagnostic definitions. The validation guide explains convergence and uncertainty checks; conventions gives cross-code conversions. Agreement at one finite resolution supports that configuration and observable.
References include the GX code paper and the W7-X stella–GENE benchmark. Use their declared models and analysis protocols when reconstructing a comparison. Keep generated results outside version control and record the input deck, command, source revisions and acceptance criteria with each result.
Derivatives and optimization
Eigenvalue derivatives use dλ/dp = wᴴ(dA/dp)v / (wᴴv) with residual,
overlap and conditioning checks. Nonlinear heat-flux derivatives use a
checkpointed discrete adjoint over a finite post-saturation window. Compare
these derivatives with finite differences across perturbation sizes and
window lengths; assess a design change with independent long simulations.
See nonlinear autodiff.
VMEX composes its equilibrium derivative with GKX solver objectives. Run the optimization example to combine heat flux with equilibrium constraints. Quasilinear flux requires calibration and held-out nonlinear validation before it supports an absolute transport prediction (quasilinear, stellarator optimization).
Performance
Reuse prepared cases when topology is fixed. Warm the exact callable before timing, wait for device completion and report compilation separately from execution. Check numerical agreement before comparing kernels or device layouts, and include diagnostics and I/O in end-to-end measurements.
Each species can use its own Nl and Nm; validate the observable at higher
moment counts before reducing them. Named species–Hermite parallel execution
has narrower operator support than whole-state placement, so inspect the
resolved routing message when assessing scaling.
See performance and
parallel execution.
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). Keep generated test and benchmark outputs outside version control. Cite GKX with CITATION.cff.
License
MIT; see LICENSE.
Metadata
Release files for gkx 2.9.0
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.9.0.tar.gz | 633.7 kB | With provenance | Details for gkx-2.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gkx-2.9.0-py3-none-any.whl | Python 3 | none | any | Details for gkx-2.9.0-py3-none-any.whl |
Total release size: 1.3 MB
Release files / gkx-2.9.0.tar.gz
| Download URL | gkx-2.9.0.tar.gz |
|---|---|
| Size | 633.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0cb70dd93305c3a4178d13be1bb0b81504cf3b59dea55e0b314c51b263409b8a
|
|
BLAKE2b-256 checksum How to use checksums |
8a41bf635527064a5abcc66c338108ff0c0987d6ff99ae993e216808cbf07fdf
|
| 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 6, 2026.
Transparency logRelease files / gkx-2.9.0-py3-none-any.whl
| Download URL | gkx-2.9.0-py3-none-any.whl |
|---|---|
| Size | 694.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f9e5485a9616486d2db6f4ae64dd2ef59648f973a8fdd2e92a189439f80f02e0
|
|
BLAKE2b-256 checksum How to use checksums |
9840b9120a5bbbc6550762466baf2d6ca3a7636359773afd9747c57de0f1a87a
|
| 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 6, 2026.
Transparency logSecurity for gkx 2.9.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.
Attestation for gkx-2.9.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 Nov 6, 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.