Flexible high‑performance plasma physics solver in Python using JAX and NumPy
Project description
flexipde
flexipde is a flexible, high‑performance library for solving plasma physics equations in any number of dimensions. It combines the ease of writing Python with the speed of modern array libraries like NumPy and JAX. The library draws inspiration from—and goes beyond—established simulation frameworks such as BOUT++ for fluid plasmas and Gkeyll for kinetic models【635715314594784†L14-L33】. Instead of low‑level C++ or Fortran, you write concise Python code that can automatically run on CPUs or GPUs via JAX, and you can differentiate simulations with respect to parameters to enable optimisation or machine‑learning pipelines.
Features
- Unified grid and coordinate system: Create structured grids in 1D, 2D or 3D, including cylindrical coordinate systems with arbitrary metrics.
- Multiple discretisation methods: Choose between Fourier spectral methods for periodic domains and finite difference methods for general boundaries. Additional schemes (e.g. finite volume/WENO) can be added easily.
- Built‑in models: Includes linear advection, diffusion, ideal Alfvén waves, resistive MHD, two‑fluid plasmas, drift‑kinetic equations and a Vlasov–Poisson solver. Additional models can be implemented by subclassing a base class.
- Custom equations: Write your own PDEs without modifying the library—see the Burgers and Hasegawa–Wakatani examples.
- JAX acceleration and differentiability: When JAX is installed, simulations are JIT‑compiled and run on GPU/TPU. You can compute gradients of objectives with respect to simulation parameters and plug them into optimisation routines (via Optax).
- CLI and configuration files: Run simulations from the command line using TOML configuration files. You can specify the filename without the
.tomlsuffix for convenience. - Extensive documentation: A pedagogical guide introduces the mathematics and numerics behind each model, with worked examples and a gentle introduction for students and researchers.
- Continuous integration and coverage: GitHub workflows run tests, build the docs, and report coverage to codecov.
Installation
pip install flexipde
# Or install with JAX support
pip install 'flexipde[jax]'
To install from source for development:
git clone https://github.com/uwplasma/flexipde.git
cd flexipde
pip install -e .[jax,testing,docs]
Models
The library comes with several built‑in models:
- LinearAdvection: Advection of a scalar field with constant velocity. You can supply a velocity vector of arbitrary dimension.
- Diffusion: Heat equation with configurable diffusivity.
- IdealAlfvén: A toy model of shear Alfvén waves in 1D with two fields (velocity and magnetic field).
- ResistiveMHD: A simplified resistive magnetohydrodynamics system with transverse velocity and magnetic field and resistivity parameter.
- TwoFluid: Ion and electron densities advect independently with prescribed velocity vectors.
- DriftKinetic: A drift–kinetic equation in 1D phase space (x,v) with a constant electric field.
- VlasovTwoStream: A 1D Vlasov–Poisson solver modelling the two‑stream instability with Maxwellian streams. You can adjust the number of velocity grid points and thermal velocities.
- Custom models: You can implement arbitrary PDE systems by subclassing :class:
flexipde.models.base.PDEModelor by writing a simple Python function in a driver script. See the Hasegawa–Wakatani and Burgers examples for guidance.
Features
Run a 1D diffusion simulation from a TOML file:
flexipde examples/diffusion_1d
# automatically appends `.toml` if missing
Or run the same simulation from Python:
from flexipde.io import build_simulation
sim = build_simulation('examples/diffusion_1d.toml')
times, states = sim.run()
import matplotlib.pyplot as plt
plt.plot(sim.grid.coords[0], states[-1]['u'])
plt.show()
See the examples directory for more scripts illustrating custom models and optimisation tasks.
Documentation
The full documentation, including a tutorial introduction, API reference, and mathematical derivations, is available at https://uwplasma.github.io/flexipde. The docs are built with MkDocs and use MathJax to render equations.
Tests and coverage
To run the test suite with coverage:
pip install 'flexipde[testing]'
pytest --cov=flexipde tests
Manufactured solution tests are provided for each model to verify that spatial operators and PDE right‑hand sides are correct. We use functions like f(x,t)=cos(2x)*cos(3t) to ensure the gradients, divergences and Laplacians match analytic expressions.
Contributing
Contributions are welcome! Please open issues or pull requests on GitHub. We follow PEP8 coding style and maintain a high level of test coverage.
License
This project is licensed under the MIT license—see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flexipde-0.3.2.tar.gz.
File metadata
- Download URL: flexipde-0.3.2.tar.gz
- Upload date:
- Size: 45.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8d6a952109a8c6030ea6170cdba69efa595b649343d89e16a398658c4a73fdc
|
|
| MD5 |
5a961cfeb705affb5cb7e0692f3d0296
|
|
| BLAKE2b-256 |
e4669d72fe4f5fa026b13db812bd587ca81ef533af81b564591a9ec0a2691a34
|
Provenance
The following attestation bundles were made for flexipde-0.3.2.tar.gz:
Publisher:
release.yml on uwplasma/flexipde
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexipde-0.3.2.tar.gz -
Subject digest:
f8d6a952109a8c6030ea6170cdba69efa595b649343d89e16a398658c4a73fdc - Sigstore transparency entry: 572087243
- Sigstore integration time:
-
Permalink:
uwplasma/flexipde@047f018cf999dfd714ef2ad46b77523239da7d7d -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/uwplasma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@047f018cf999dfd714ef2ad46b77523239da7d7d -
Trigger Event:
push
-
Statement type:
File details
Details for the file flexipde-0.3.2-py3-none-any.whl.
File metadata
- Download URL: flexipde-0.3.2-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5fdf9f68e64daab9e9cf2e45b89cbbc935cae3063884a00a3b3a648ffd7e0e4
|
|
| MD5 |
04b88d7ddb40b772826997abedd088b3
|
|
| BLAKE2b-256 |
64fce0800026e4980632c1821293b40a8646e688525e2d46c629dd99d3e20fe7
|
Provenance
The following attestation bundles were made for flexipde-0.3.2-py3-none-any.whl:
Publisher:
release.yml on uwplasma/flexipde
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flexipde-0.3.2-py3-none-any.whl -
Subject digest:
a5fdf9f68e64daab9e9cf2e45b89cbbc935cae3063884a00a3b3a648ffd7e0e4 - Sigstore transparency entry: 572087351
- Sigstore integration time:
-
Permalink:
uwplasma/flexipde@047f018cf999dfd714ef2ad46b77523239da7d7d -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/uwplasma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@047f018cf999dfd714ef2ad46b77523239da7d7d -
Trigger Event:
push
-
Statement type: