Skip to main content

flexipde

CI Docs PyPI version codecov

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 to have a performant, simple to use and flexible library. 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 .toml suffix 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.PDEModel or 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.

Metadata

Release files for flexipde 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flexipde 0.3.3
File Size Uploaded Provenance Actions
flexipde-0.3.3.tar.gz 45.0 kB With provenance Details for flexipde-0.3.3.tar.gz

Built distribution (wheel)

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

Total release size: 76.8 kB

Release files / flexipde-0.3.3.tar.gz

Download URL flexipde-0.3.3.tar.gz
Size 45.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5f7336555ce3b1d403db71774a0a5f7db2a23d5a89b25dfec9613f953c5115eb
BLAKE2b-256 checksum
How to use checksums
9a28b12ccf484a2d9c12b522b1bf53b6bd945a79e613ed2586fd579cf8d88609
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 Sep 30, 2025.

Transparency log

Release files / flexipde-0.3.3-py3-none-any.whl

Download URL flexipde-0.3.3-py3-none-any.whl
Size 31.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc0a830ab8a2f0c3a8382a772638c3f32ef4f9d99baf78511f517d58f0eaa0e2
BLAKE2b-256 checksum
How to use checksums
703915d96b8f4605448459f72767cc4ab786457a1076756a42089b1c256c1d94
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 Sep 30, 2025.

Transparency log

Security for flexipde 0.3.3

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 flexipde-0.3.3.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 Sep 30, 2025.

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.

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files Full provenance

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