Skip to main content

SPECTRAX-GK

Release PyPI CI Coverage License: MIT Python

SPECTRAX-GK is a JAX-native gyrokinetic solver for linear stability, nonlinear turbulence, differentiable analysis, and stellarator design. It uses Fourier perpendicular coordinates, a Hermite-Laguerre velocity basis, and field-aligned analytic, Miller, or VMEC geometry. The package runs on CPUs and GPUs, exposes a Python API for autodiff and optimization, and provides a simple executable for routine simulations.

Installation

pip install spectraxgk

For development:

git clone https://github.com/uwplasma/SPECTRAX-GK
cd SPECTRAX-GK
pip install -e .

Quickstart

Run the built-in linear initial-value example:

spectraxgk

The equivalent spectrax-gk entry point is also installed. The default run prints setup, progress, elapsed time, and ETA, then writes its input, summary, time series, eigenfunction, and a two-panel plot in the current directory.

Run a checked-in case or plot an existing result:

spectraxgk examples/linear/axisymmetric/cyclone.toml
spectraxgk run-runtime-nonlinear \
  --config examples/nonlinear/axisymmetric/runtime_cyclone_nonlinear.toml \
  --steps 200 --out cyclone.out.nc
spectraxgk --plot cyclone.out.nc

Generate the small VMEC equilibria used by the self-contained examples:

pip install vmec-jax
cd examples/vmec
./generate_wouts.sh

Start with the quickstart and input reference for linear, nonlinear, Miller, VMEC, restart, quasilinear, and plotting workflows.

Highlights

  • Electrostatic and electromagnetic gyrokinetics with kinetic or Boltzmann species.
  • Linear initial-value, dominant-eigenmode, and nonlinear turbulence solvers.
  • Analytic s-alpha, Miller, imported VMEC, and differentiable VMEC/Boozer geometry.
  • JAX JIT, forward/reverse autodiff, implicit eigenvalue derivatives, and UQ tools.
  • Quasilinear transport diagnostics with explicit saturation-rule metadata.
  • CPU/GPU execution and production parallelization for independent scans and ensembles.
  • Restartable NetCDF output and spectraxgk --plot publication-style figures.
  • A limited conserving Lenard-Bernstein/Dougherty-like collision model, with advanced multispecies and linearized Landau operators remaining research lanes.

Main Validation Results

The release atlas compares growth rates, frequencies, eigenfunctions, and nonlinear transport windows with established gyrokinetic reference results. Promoted cases include Cyclone ITG, Cyclone Miller, KBM, W7-X, and HSX, with ETG and kinetic-electron stress cases kept at their documented claim level.

Linear and nonlinear benchmark summary

The exact equations, normalization, grids, boundary conditions, diagnostic windows, tolerances, and artifact provenance are in the benchmark documentation and verification matrix. A visual overlay alone is not treated as parity evidence.

The advanced-collision research lane now generates the complete retained finite-Larmor Coulomb moment algebra and checks it against independent velocity-space projection, spectral convergence, drift-kinetic conservation, finite-wavelength gyro-diffusion, and the H-theorem. The panel below passes all operator-level gates, but does not claim production Landau transport yet; the finite-Larmor collisional-ITG gate and drift-kinetic collisional-zonal gate are closed, and the paper-resolution finite-wavelength zonal traces and velocity sections now pass their independent literature gate. The differentiable driven-current solve is equation-tested, and the direct Coulomb hierarchy is now converged through (P,J)=(20,5) with a maximum nested current change of 0.017%. Its collision-frequency and electric-field normalizations are now closed against the stationary Spitzer problem: all three operators saturate by t nu_ee=50, remain linear over a 100x field scan, and Coulomb reaches the high-charge analytic limit within 7.46%. The arbitrary-order original model reproduces its published 11% low-charge current deficit, while the converged improved model is within 0.31% of Coulomb over the complete ion-charge scan. The converged finite-Larmor ITG artifact is accepted; the generated equal-species operator remains a Python research path because a production input-file selector would imply broader multispecies coefficients that are not yet implemented.

Coulomb collision operator verification

Equations, thresholds, machine-readable results, literature links, and the one-command reproduction recipe are in the collision-operator documentation.

Paper-resolution collisional zonal response

At (P,J)=(24,10), the drift-kinetic traces approach the Xiao residual and the finite-wavelength tails reproduce the published original < improved < Coulomb ordering at both kx rho_i=0.1 and 0.2. The improved model is also closer to Coulomb over t nu_ii <= 10 at both wavenumbers. Equations, velocity-space convergence, compact replay data, and the Figure 12--14 gate are documented in Operators and Terms.

Runtime and Memory

Runtime and memory comparison

The panel reports measured cold wall time and peak memory for the tracked CPU, GPU, and comparison-code runs. Cold JAX rows include startup and compilation. Prepared Python simulations avoid recompiling a fixed geometry and numerical policy, but their CPU/GPU throughput depends on the software stack and GPU operating state. See performance for profiler artifacts, memory accounting, current reproducibility notes, and the distinction between executable, prepared, and distributed runs.

Differentiable Python API

import jax.numpy as jnp

from spectraxgk import CycloneBaseCase, LinearParams, integrate_linear_from_config
from spectraxgk.core.grid import build_spectral_grid
from spectraxgk.geometry import SAlphaGeometry

cfg = CycloneBaseCase()
grid = build_spectral_grid(cfg.grid)
geometry = SAlphaGeometry.from_config(cfg.geometry)
parameters = LinearParams()
state = jnp.zeros((2, 2, grid.ky.size, grid.kx.size, grid.z.size), dtype=jnp.complex64)
state = state.at[0, 0, 0, 0, :].set(1.0e-3)
trajectory, potential = integrate_linear_from_config(
    state, grid, geometry, parameters, cfg.time
)

For repeated nonlinear calls with fixed geometry and numerical policy, prepare the compiled simulation once:

from spectraxgk.nonlinear import prepare_nonlinear_explicit_diagnostics

simulation = prepare_nonlinear_explicit_diagnostics(
    initial_state,
    grid,
    geometry,
    parameters,
    dt=0.02,
    steps=400,
    resolved_diagnostics=False,
)
time, diagnostics, final_state, fields = simulation.run()

The prepared object accepts another same-shape initial state without rebuilding the scan. A matched rebuilt cache/parameter PyTree can also remain dynamic for autodiff; geometry layout is fixed, and dynamic-geometry compile reuse remains an active differentiability lane.

The planted two-mode inverse problem below recovers two gradient parameters and checks the autodiff Jacobian against finite differences. The single-mode demo in the docs intentionally demonstrates non-identifiability rather than exact parameter recovery.

Two-mode autodiff inverse validation

See differentiable workflows, algorithms, and stellarator optimization for JVP, VJP, implicit differentiation, conditioning, covariance, and finite-difference gates.

Quasilinear Modeling

Stellarator quasilinear usefulness

The current quasilinear implementation is a scoped model-development and optimization-screening result. It supports ranking and correlation studies but is not a runtime/TOML absolute-flux predictor. Absolute-flux promotion remains rejected when the declared Solovev and shaped-pressure stress outliers are retained. Model definitions, derivations, calibration splits, uncertainty, residual anatomy, and holdout gates are in the quasilinear documentation.

QA ITG Optimization

The VMEC-JAX-style examples append a SPECTRAX-GK growth-rate, quasilinear, or nonlinear-window residual to the aspect-ratio, mean-iota, and quasisymmetry objective tuples. The baseline follows the max-mode-5 QA workflow; all transport comparisons use solved VMEC equilibria.

VMEC-JAX QA max-mode-5 optimizer sweep

These rows are not promoted turbulent-flux designs. Their matched long post-transient nonlinear audits use converged post-transient heat-flux windows and do not show a statistically significant reduction relative to the strict QA baseline. They are useful negative transfer evidence for improving objective conditioning and optimizer choice.

The RBC(1,1) scan is a landscape and noise/convergence diagnostic, not a source of admitted optimized candidates. It compares linear growth, all shipped quasilinear rules, and replicated long-window nonlinear transport.

QA RBC(1,1) transport landscape

Reproducible scripts are in examples/optimization, and full objective equations, optimizer policies, comparison fingerprints, and long-window audits are in the optimization documentation.

Parallelization

Production parallelization currently covers independent k_y scans, quasilinear/UQ ensembles, and file-backed independent tasks with deterministic ordering and serial identity gates. Sensitivity sweeps can use the same deterministic independent-work reconstruction, but they need a dedicated matched scaling artifact before any speedup claim is promoted.

Nonlinear whole-state and domain decomposition remain diagnostic. Species-first and Hermite-second decomposition, explicit Hermite halo exchange, field-moment collectives, and physical transport-window identity must pass before a nonlinear parallelization speedup is claimed. See parallelization.

Current Claim Scope

Validated release claims are bounded by the release scope:

  • Standard electrostatic/electromagnetic full gyrokinetics is validated only on the promoted cases and observables in the verification matrix.
  • Quasilinear outputs are diagnostics and screening models, not universal absolute nonlinear heat-flux predictions.
  • Nonlinear optimization evidence requires matched, replicated, long post-transient windows; startup or reduced envelopes are not production evidence.
  • W7-X zonal long-window recurrence/damping and W7-X TEM / kinetic-electron extensions are deferred.
  • Production nonlinear domain decomposition, equilibrium ExB flow shear, species-coupled collisions, and linearized Landau/Sugama operators remain open.

Examples and Documentation

The repository keeps small runnable examples under:

Detailed user and developer documentation:

Testing

pytest
python tools/release/run_test_gates.py fast
python tools/release/run_test_gates.py wide-coverage \
  --shards 48 --timeout 300 --fail-under 95 \
  --pytest-arg=-o --pytest-arg=addopts= --pytest-arg=-m --pytest-arg="not slow"
python -m sphinx -W -b html docs docs/_build/html

The package-wide CI coverage gate is at least 95%. Physics, convergence, comparison, differentiability, and performance gates are required in addition to line coverage.

License

SPECTRAX-GK is distributed under the MIT License.

Metadata

Release files for spectraxgk 1.7.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 spectraxgk 1.7.0
File Size Uploaded Provenance Actions
spectraxgk-1.7.0.tar.gz 994.7 kB With provenance Details for spectraxgk-1.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.7 MB

Release files / spectraxgk-1.7.0.tar.gz

Download URL spectraxgk-1.7.0.tar.gz
Size 994.7 kB
Tags Source
SHA-256 checksum
How to use checksums
808f655a7aa8ef5a07dc1126844efbecbbf71df39d98c0c2a191cde3439278fa
BLAKE2b-256 checksum
How to use checksums
b8013b82817f916cfdbf57c6a4ef3632ed9ada43c91dc22d640829e7469145d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 17, 2026.

Transparency log

Release files / spectraxgk-1.7.0-py3-none-any.whl

Download URL spectraxgk-1.7.0-py3-none-any.whl
Size 704.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d0896e0fa37101fe0cd1972a9946abc32c7d26cc5fae54649d4f4dd275534ab
BLAKE2b-256 checksum
How to use checksums
f48156e7ee2481169fea94fc3981ba13ec83641be9058497f57b9ce4a6f0720a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 17, 2026.

Transparency log

Security for spectraxgk 1.7.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spectraxgk-1.7.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 Jul 17, 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