Quickstart#

modax is a library of GPU-accelerated ODE solvers optimised for solving massive ensembles (1k-100k) of low-dimensional (<200D) ODE trajectories, built on JAX and Numba-CUDA-MLIR. Applications include: Bayesian parameter estimation, uncertainty quantification and the integration of physically uncoupled systems.

Every solver is compiled as a custom CUDA kernel using Numba-CUDA-MLIR. Each ODE trajectory is solved within its own CUDA thread and results are exposed to JAX as an XLA FFI custom call. Calls to modax therefore behave as ordinary JAX primitives. They are jit-traceable, auto-differentiable and a vmap over a single solve lowers to one native ensemble launch.

Installation#

pip install "modax-solvers[cuda13]"   # or [cuda12]; Python 3.10 needs cuda12

There is no system library to install first: every dependency ships wheels, the AMD ordering included. A GPU is needed to run a solve. The Enzyme-derived Jacobians come from numba-enzyme-cuda, the CUDA-enabled fork of numba-enzyme, which carries its own LLVM 15 and Enzyme binaries and provides the numba_enzyme import package, so upstream numba-enzyme must not be installed alongside it. See wheels/README.md for what is in the wheel and why.

Any GPU of compute capability 7.0 or later runs it. On Blackwell (10.0 and up) the kernels and their Enzyme derivatives are compiled for sm_90, the newest target whose LLVM dialect Enzyme’s LLVM 15 toolchain reads, and linked for the GPU itself; NUMBA_ENZYME_CUDA_CC overrides that target.

The CPU install is enough to build these docs and to run the host-side part of the test suite, which is small: most tests need a device, and tests/test_examples.py compiles the examples’ callbacks with cuda.compile_ptx, which initialises the CUDA driver and so skips without one.

Your first solve#

This example demonstrates a stiff decay chain A → B → C, solved for 1000 rate constants at once, with a declared sparsity pattern (i.e. which inputs affect which outputs):

import jax.numpy as jnp
import modax
import numpy as np


def ode_fn(y, t, p):  # tuples of scalars in and out
    return -p[0] * y[0], p[0] * y[0] - p[1] * y[1], p[1] * y[1]


sparsity = np.array([[1, 0, 0], [1, 1, 0], [0, 1, 1]], dtype=bool)
params = jnp.stack([jnp.logspace(0, 4, 1000), jnp.ones(1000)], axis=1)
y0 = jnp.array([1.0, 0.0, 0.0])
t_span = jnp.linspace(0.0, 10.0, 11)

# Rodas5P, the default method, suits a stiff system
y = modax.solve(ode_fn, y0, t_span, params, sparsity=sparsity)  # (1000, 11, 3)

The ensemble dimension comes from whichever of y0 and params is two-dimensional; if both are 2D, they must then agree. The returned integration history has shape (N, n_save, n_vars).

Where to go next?#

Choosing a solver

Tsit5 for non-stiff problems, Rodas5P for stiff ones.

Choosing a solver
Running a solver

solve(...), its arguments, and the rules callbacks must obey.

Running a solver
Exploiting sparsity

Speeding up solves using knowledge of which inputs affect which outputs.

Exploiting sparsity
Computing gradients

jax.jvp and jax.jacfwd using continuous forward-sensitivity solves.

Computing gradients