❯ SPECTRAX: Hermite-Fourier Vlasov-Maxwell solver in JAX for plasma physics simulations
Table of Contents
- Table of Contents
- Overview
- Mathematical Method
- Features
- Getting Started
- Input File Format
- Contributing
- License
- Acknowledgments
Overview
SPECTRAX is an open-source spectral kinetic plasma solver written in Python with the JAX ecosystem. It solves the collisionless Vlasov–Maxwell equations by evolving the Hermite–Fourier coefficients of the particle distribution function and the electromagnetic fields. This approach was previously implemented in SpectralPlasmaSolver (SPS), developed at Los Alamos National Laboratory, and described in Delzanno (2025), Vencels et al. (2016) and Roytershteyn & Delzanno (2018), where the one particle distribution is expanded in asymmetrically weighted (AW) Hermite functions in velocity space and Fourier modes in configuration space. By performing an AW Hermite expansion in velocity space, the method naturally couples fluid and kinetic physics: the lowest‐order Hermite coefficients correspond to fluid moments and higher modes capture kinetic corrections.
SPECTRAX implements a Hermite–Fourier spectral approach for Vlasov–Maxwell simulations in a JAX framework. It uses just‑in‑time compilation to run efficiently on CPUs and GPUs, adopts state‑of‑the‑art ODE solvers from the Diffrax library, and includes utilities for diagnostics and plotting. The code supports multi‑species plasmas and arbitrary spatial dimensionality (1D to 3D) and can serve as a test bed for studying kinetic instabilities, turbulence, and the transition between fluid and kinetic regimes.
Mathematical Method
The Hermite–Fourier spectral method replaces the Vlasov equation in the 6-dimensional phase-space with a hierarchy of coupled ordinary differential equations (ODEs) for the Hermite–Fourier moments of the one-particle probability density function and the electric and magnetic fields. The Hermite-Fourier expansion is truncated for closure and a hypercollisional operator is introduced in velocity space to suppress recurrence. The resulting system of ODEs is integrated in time using solvers from the Diffrax library. Diffrax's implementation of the Dormand-Prince’s 8/7 method, Dopri8, proved to be notoriously fast and stable, and is set as the default solver.
Features
-
JAX‑based spectral solver – all core operations are implemented in JAX and compiled with
jit, enabling efficient execution on CPUs and GPUs. -
Efficient time integration – SPECTRAX uses ODE solvers from the Diffrax library (e.g.,
Dopri5,Dopri8,Tsit5; a Diffrax-based, custom-made implicit midpoint solver is also available asImplicitMidpoint) to advance the Hermite–Fourier coefficients in time. Thesimulationfunction assembles the right‑hand‑side, applies a 2⁄3 de‑aliasing mask on Fourier modes in the nonlinear term, and integrates the system untilt_max, returning the time‑evolved coefficients. -
Multi‑species and multi‑dimensional – the code supports multiple particle species with distinct mass ratios, temperatures and drift velocities. Resolution in spatial dimensions is controlled via
Nx,Ny,Nz, and velocity Hermite orders viaNn,Nm,Np. -
Diagnostics – after each simulation the
diagnosticsfunction computes the Debye length, kinetic energies of each species, electromagnetic energy and total energy and stores them in the output dictionary. -
Plotting utilities – the
plotfunction produces a multi‑panel figure showing energy evolution, relative energy error, density fluctuations and phase‑space distributions for each species. It reconstructs the distribution function by performing an inverse Fourier transform followed by an inverse Hermite transform. The phase‑space reconstruction uses theinverse_HF_transformfunction, which evaluates Hermite polynomials and sums over all modes. The phase-space plots assume a 1D simulation. -
Flexible initialization – simulation parameters may be provided through simple TOML files or directly in Python. The
load_parametersfunction reads a TOML file and merges it with sensible defaults that initialize a two‑stream instability. Users can also initialize their own spectral coefficients, as shown in the example scripts. -
Open source and extensible – SPECTRAX is released under the MIT License. Its modular structure allows researchers to experiment with new closures, collision operators or boundary conditions.
Getting Started
Prerequisites
- Programming Language: Python
Besides Python, SPECTRAX has minimum requirements. These are stated in requirements.txt, and consist of the Python libraries jax, jax_tqdm and matplotlib.
Installation
SPECTRAX is a standard Python package that may be installed from a local checkout. The project depends
on jax, jaxlib, jax_tqdm, diffrax, orthax, and matplotlib.
- Clone this repository:
git clone https://github.com/uwplasma/SPECTRAX.git
cd SPECTRAX
-
(Optional) create a virtual environment and activate it.
-
Install the package in editable mode:
pip install -r requirements.txt
pip install -e .
JAX will automatically select the available hardware (CPU or GPU). For GPU support you may need the
appropriate CUDA-enabled version of jaxlib; consult the JAX installation guide.
Usage
SPECTRAX can be used either via a command‑line interface or directly as a Python module.
Command‑line Interface
After installation, the spectrax CLI entry point is available. You can run an instance of the 1D two-stream instability by simply calling spectrax from the terminal.
spectrax
To run it with different input parameters, us a TOML file like those in the Examples directory.
spectrax example_input.toml
Other examples written in Python scripts, like those in the Examples directory, can be executed from the terminal as follows:
python example_script.py
The simulation function returns a dictionary containing the evolved Hermite coefficients Ck, electromagnetic coefficients Fk, time array, the input parameters and diagnostic quantities.
Testing
Run the test suite using the following command:
pytest .
Input File Format
Input files are written in TOML and define both physical and solver parameters. Below is a summary of the most important keys. Keys absent from the file fall back to sensible defaults specified in the code.
| Parameter | Description |
|---|---|
Lx, Ly, Lz |
Domain lengths in the spatial directions (periodic boundary condition). |
mi_me |
Ion‑to‑electron mass ratio. |
Ti_Te |
Ion‑to‑electron temperature ratio. |
qs |
Array of species charges. |
alpha_s |
Thermal scales for each species for Hermite basis. |
u_s |
Drift velocities for each species for Hermite basis (packed as [u_x,u_y,u_z] ). |
Omega_cs |
Cyclotron frequencies for each species. |
nu |
Hyper-collision frequency to damp recurrence. |
D |
Hyper‑diffusion coefficient. |
t_max |
Final simulation time. |
nx, ny, nz |
Mode numbers used to seed sinusoidal perturbations (see examples). |
dn1, dn2 |
Amplitudes of initial density perturbations (see examples). |
ode_tolerance |
Relative/absolute tolerance for adaptive solvers. |
Nx, Ny, Nz |
Number of retained Fourier modes per spatial dimension. |
Nn, Nm, Np |
Number of Hermite modes per velocity dimension. |
Ns |
Number of species (two by default). |
timesteps |
Number of solution snapshots to store between t=0 and t_max. |
dt |
Initial step size provided to the ODE solver. |
solver |
Name of Diffrax solver (e.g., Tsit5, Dopri5, Dopri8, ImplicitMidpoint). |
adaptive_time_step |
Timestep adaptability (true by default). |
Many of these parameters can be arrays; for example alpha_s must contain three values per species (one
for each velocity dimension) and can be used to represent anisotropic plasmas.
Contributing
- 💬 Join the Discussions: Share your insights, provide feedback, or ask questions.
- 🐛 Report Issues: Submit bugs found or log feature requests for the
SPECTRAXproject. - 💡 Submit Pull Requests: Review open PRs, and submit your own PRs.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/uwplasma/SPECTRAX
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
License
This project is protected under the MIT License. For more details, refer to the LICENSE file.
Acknowledgments
- We acknowledge the help of the whole UWPlasma plasma group.
Metadata
Release files for spectrax 0.2.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 |
|---|---|---|---|---|
| spectrax-0.2.1.tar.gz | 4.7 MB | With provenance | Details for spectrax-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spectrax-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for spectrax-0.2.1-py3-none-any.whl |
Total release size: 4.8 MB
Release files / spectrax-0.2.1.tar.gz
| Download URL | spectrax-0.2.1.tar.gz |
|---|---|
| Size | 4.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
993940a3bfd4673a832f3b99d2f1f555813028b52ef8731724253cf53fdc24c1
|
|
BLAKE2b-256 checksum How to use checksums |
6e3a3038f7db85135267340793bda3ec29247981f8214ab728a124cda869eb74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 5, 2026.
Transparency logRelease files / spectrax-0.2.1-py3-none-any.whl
| Download URL | spectrax-0.2.1-py3-none-any.whl |
|---|---|
| Size | 28.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
551c13b32fb52fc4fa410e01d9652794a27e29500a3865f122afa6514e372302
|
|
BLAKE2b-256 checksum How to use checksums |
44924d4d962adaa539789f846858a4ef2fc3db5766857cb2672f003d2b4b06be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 5, 2026.
Transparency logSecurity for spectrax 0.2.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for spectrax-0.2.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 Mar 5, 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.