Skip to content

How It Works

A diffsol solver does not call Python. Instead, diffsol-jax compiles your equations and hands diffsol native functions to call:

  1. Every callback the solver needs (rhs, its Jacobian action, the sensitivity and adjoint right-hand sides, ...) is derived from your functions with JAX's own transformations (jax.jvp, jax.vjp) and lowered to StableHLO.
  2. The StableHLO is compiled through the PJRT C API and the resulting executables are passed to diffsol as C function pointers.
  3. The solves themselves are exposed to JAX as XLA FFI custom calls, which is what makes solve work under jax.jit, jax.grad and jax.vmap.

This means each callback call carries a fixed overhead of a few microseconds. For stiff problems and large batches this is negligible. For a tiny non-stiff system it is significant, and a pure-JAX solver such as diffrax that compiles the entire loop is much faster. See Benchmarks.

GPU is not supported: diffsol's matrix types are CPU.

Building from Source

Building needs a Rust toolchain and a C++ compiler; one cargo invocation builds everything, including the vendored C++:

cargo build --release   # _native.py finds target/release
pip install -e .        # or install the package
python -m pytest tests

The tests need a CPU PJRT plugin, from pip install "diffsol-jax[cpu]" or via the DIFFSOL_JAX_PJRT_PLUGIN environment variable.