diffsol: Rust crate for solving differential equations

diffsol: Rust crate for solving differential equations - Published in JOSS (2026)

https://github.com/martinjrobins/diffsol

Science Score: 87.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in JOSS metadata
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

bdf dsl jacobian mass-matrix ode ode-integrator ode-solver runge-kutta rust scientific-computing solver sparse-matrix

Keywords from Contributors

batteries
Last synced: 27 days ago · JSON representation

Repository

ODE solver library in Rust

Basic Info
Statistics
  • Stars: 91
  • Watchers: 4
  • Forks: 11
  • Open Issues: 17
  • Releases: 20
Topics
bdf dsl jacobian mass-matrix ode ode-integrator ode-solver runge-kutta rust scientific-computing solver sparse-matrix
Created about 2 years ago · Last pushed 28 days ago
Metadata Files
Readme Contributing Funding License

README.md

diffsol logo

mdbook badge docs.rs badge CI build status badge code coverage

Diffsol is a library for solving ordinary differential equations (ODEs) or semi-explicit differential algebraic equations (DAEs) in Rust. It can solve equations in the following form:

math M \frac{dy}{dt} = f(t, y, p)

where $M$ is a (possibly singular and optional) mass matrix, $y$ is the state vector, $t$ is the time and $p$ is a vector of parameters.

The equations can be given by either rust code or the DiffSL Domain Specific Language (DSL). The DSL uses automatic differentiation using Enzyme to calculate the necessary jacobians, and JIT compilation (using either LLVM or Cranelift) to generate efficient native code at runtime. The DSL is ideal for using diffsol from a higher-level language like Python or R while still maintaining similar performance to pure rust.

Installation

You can add diffsol using cargo add diffsol or directly in your Cargo.toml:

toml [dependencies] diffsol = "0.10"

Diffsol has the following features that can be enabled or disabled:

  • nalgebra: Use nalgebra for linear algebra containers and solvers (enabled by default).
  • faer: Use faer for linear algebra containers and solvers (enabled by default).
  • cuda: Use in-built CUDA linear algebra containers and solvers (disabled by default, experimental).
  • diffsl-llvm15, diffsl-llvm16, diffsl-llvm17, diffsl-llvm18, diffsl-llvm19, diffsl-llvm20, diffsl-cranelift: Enable DiffSL with the specified JIT backend (disabled by default). You will need to set the LLVM_SYS_XXX_PREFIX (see llvm-sys) and LLVM_DIR environment variables to point to your LLVM installation, where XXX is the version number (150, 160, 170, 181, 191, 201, 211).
  • suitesparse: Enable SuiteSparse KLU sparse linear solver (disabled by default, requires faer).

You can add any of the above features by specifying them in your Cargo.toml. For example, to enable the diffsl-cranelift JIT backend, you would add:

toml [dependencies] diffsol = { version = "0.10", features = "diffsl-cranelift" }

See the Cargo.toml documentation for more information on specifying features.

Usage

The diffsol book describes how to use diffsol using examples taken from several application areas (e.g. population dynamics, electrical circuits and pharmacological modelling), as well as more detailed information on the various APIs used to specify the ODE equations. For a more complete description of the API, please see the docs.rs API documentation.

For a quick start, see the following example of solving the Lorenz system of equations using the BDF solver and the DiffSL DSL with the LLVM JIT backend:

```rust use diffsol::{LlvmModule, NalgebraLU, NalgebraMat, OdeBuilder, OdeSolverMethod};

pub fn lorenz() -> Result<(), Box> { let problem = OdeBuilder::>::new().buildfromdiffsl::( " a { 14.0 } b { 10.0 } c { 8.0 / 3.0 } ui { x = 1.0, y = 0.0, z = 0.0, } Fi { b * (y - x); x * (a - z) - y; x * y - c * z; } ", )?; let mut solver = problem.bdf::>()?; let (_ys, _ts) = solver.solve(0.0)?; Ok(()) } ```

ODE solvers

The following ODE solvers are available in diffsol

  1. A variable order Backwards Difference Formulae (BDF) solver, suitable for stiff problems and singular mass matrices. The basic algorithm is derived in (Byrne & Hindmarsh, 1975), however this particular implementation follows that implemented in the Matlab routine ode15s (Shampine & Reichelt, 1997) and the SciPy implementation (Virtanen et al., 2020), which features the NDF formulas for improved stability
  2. A Singly Diagonally Implicit Runge-Kutta (SDIRK or ESDIRK) solver, suitable for moderately stiff problems and singular mass matrices. Two different butcher tableau are provided, TR-BDF2 (Hosea & Shampine, 1996) and ESDIRK34 (Jørgensen et al., 2018), or users can supply their own.
  3. A variable order Explict Runge-Kutta (ERK) solver, suitable for non-stiff problems. One butcher tableau is provided, the 4th order TSIT45 (Tsitouras, 2011), or users can supply their own.

All solvers feature:

  • Linear algebra containers and linear solvers from the nalgebra or faer crates, including both dense and sparse matrix support.
  • Adaptive step-size control to given relative and absolute tolerances. Tolerances can be set separately for the main equations, quadrature of the output function, and sensitivity analysis.
  • Dense output, interpolating to times provided by the user.
  • Event handling, stopping when a given condition $g_e(t, y , p)$ is met or at a specific time.
  • Numerical quadrature of an optional output $g_o(t, y, p)$ function over time.
  • Forward sensitivity analysis, calculating the gradient of an output function or the solver states $y$ with respect to the parameters $p$.
  • Adjoint sensitivity analysis, calculating the gradient of cost function $G(p)$ with respect to the parameters $p$. The cost function can be the integral of a continuous output function $g(t, y, p)$ or a sum of a set of discrete functions $hi(ti, yi, p)$ at time points $ti$.

Contributing

Contributions are very welcome, as are bug reports! Please see the contributing guidelines for more information, but in summary:

  • Please open an issue or discussion to report any issues or problems using diffsol
  • There are a number of repositories in the diffsol ecosystem, please route your issue/request to the appropriate repository:
    • diffsol - the core ODE solver library
    • diffsl - the DiffSL DSL compiler and JIT backends
    • pydiffsol - Python bindings
  • Feel free to submit a pull request with your changes or improvements, but please open an issue first if the change is significant. The contributing guidelines describe how to set up a development environment, run tests, and format code.

Wanted - Developers for higher-level language wrappers

Diffsol is designed to be easy to use from higher-level languages like Python or R. I'd prefer not to split my focus away from the core library, so I'm looking for developers who would like to lead the development of these wrappers. If you're interested, please get in touch.

References

  • Byrne, G. D., & Hindmarsh, A. C. (1975). A polyalgorithm for the numerical solution of ordinary differential equations. ACM Transactions on Mathematical Software (TOMS), 1(1), 71–96.81
  • Hosea, M., & Shampine, L. (1996). Analysis and implementation of TR-BDF2. Applied Numerical Mathematics, 20(1-2), 21–37.
  • Jørgensen, J. B., Kristensen, M. R., & Thomsen, P. G. (2018). A family of ESDIRK integration methods. arXiv Preprint arXiv:1803.01613.
  • Shampine, L. F., & Reichelt, M. W. (1997). The matlab ode suite. SIAM Journal on Scientific Computing, 18(1), 1–22.
  • Virtanen, P., Gommers, R., Oliphant, T. E., Haberland, M., Reddy, T., Cournapeau, D., Burovski, E., Peterson, P., Weckesser, W., Bright, J., & others. (2020). SciPy 1.0: Fundamental algorithms for scientific computing in python. Nature Methods, 17(3), 261–272.
    • Tsitouras, C. (2011). Runge–Kutta pairs of order 5 (4) satisfying only the first column simplifying assumption. Computers & Mathematics with Applications, 62(2), 770-775.

Owner

  • Name: Martin Robinson
  • Login: martinjrobins
  • Kind: user
  • Location: Oxford, United Kingdom
  • Company: University of Oxford

Head of Oxford Research Software Engineering

JOSS Publication

diffsol: Rust crate for solving differential equations
Published
January 24, 2026
Volume 11, Issue 117, Page 9384
Authors
Martin Robinson ORCID
Oxford Research Software Engineering Group, Doctoral Training Centre, University of Oxford, Oxford, UK
Alex Allmont ORCID
Oxford Research Software Engineering Group, Doctoral Training Centre, University of Oxford, Oxford, UK
Editor
Neea Rusch ORCID
Tags
rust scientific computing solver ordinary differential equations differential algebraic equations runge-kutta backward differentiation formula

GitHub Events

Total
  • Release event: 11
  • Delete event: 49
  • Pull request event: 105
  • Fork event: 1
  • Issues event: 36
  • Watch event: 48
  • Issue comment event: 71
  • Push event: 353
  • Pull request review comment event: 1
  • Pull request review event: 9
  • Create event: 68
Last Year
  • Release event: 8
  • Delete event: 40
  • Pull request event: 82
  • Fork event: 1
  • Issues event: 24
  • Watch event: 31
  • Issue comment event: 61
  • Push event: 264
  • Pull request review comment event: 1
  • Pull request review event: 9
  • Create event: 53

Committers

Last synced: 2 months ago

All Time
  • Total Commits: 388
  • Total Committers: 8
  • Avg Commits per committer: 48.5
  • Development Distribution Score (DDS): 0.18
Past Year
  • Commits: 94
  • Committers: 7
  • Avg Commits per committer: 13.429
  • Development Distribution Score (DDS): 0.085
Top Committers
Name Email Commits
martinjrobins m****s@g****m 318
Julian D. Otalvaro j****7@g****m 54
Markus Hovd 6****d 10
CGMossa c****a@g****m 2
Tim Taylor t****r@h****k 1
Gregor Decristoforo g****o@g****m 1
Copilot 1****t 1
Brady Planden 5****n 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 28 days ago

All Time
  • Total issues: 52
  • Total pull requests: 216
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 1 day
  • Total issue authors: 6
  • Total pull request authors: 6
  • Average comments per issue: 0.38
  • Average comments per pull request: 0.28
  • Merged pull requests: 186
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 13
  • Pull requests: 81
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 1 day
  • Issue authors: 3
  • Pull request authors: 5
  • Average comments per issue: 0.15
  • Average comments per pull request: 0.35
  • Merged pull requests: 68
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • martinjrobins (47)
  • JEMH (1)
  • Siel (1)
  • alexallmont (1)
  • dpastoor (1)
  • BradyPlanden (1)
Pull Request Authors
  • martinjrobins (189)
  • mhovd (11)
  • Siel (9)
  • CGMossa (4)
  • TimTaylor (2)
  • BradyPlanden (1)
Top Labels
Issue Labels
enhancement (8) refactor (2) optimisation (1) documentation (1) help wanted (1)
Pull Request Labels
codex (14)

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 42,852 total
  • Total dependent packages: 2
  • Total dependent repositories: 0
  • Total versions: 44
  • Total maintainers: 1
crates.io: diffsol

A library for solving ordinary differential equations (ODEs) in Rust.

  • Versions: 44
  • Dependent Packages: 2
  • Dependent Repositories: 0
  • Downloads: 42,852 Total
Rankings
Dependent repos count: 29.2%
Dependent packages count: 34.4%
Average: 53.3%
Downloads: 96.4%
Maintainers (1)
Last synced: about 1 month ago

Dependencies

examples/bouncing-ball/Cargo.toml cargo
examples/compartmental-models-drug-delivery/Cargo.toml cargo
examples/custom-ode-equations/Cargo.toml cargo
examples/intro-logistic-closures/Cargo.toml cargo
examples/intro-logistic-diffsl/Cargo.toml cargo
examples/neural-ode-weather-prediction/Cargo.toml cargo
examples/pde-heat/Cargo.toml cargo
examples/physics-based-battery-simulation/Cargo.toml cargo
examples/population-dynamics/Cargo.toml cargo
examples/population-dynamics-wasm-yew/Cargo.toml cargo
examples/predator-prey-fitting-forward/Cargo.toml cargo
examples/python-diffsol/Cargo.toml cargo
examples/spring-mass-system/Cargo.toml cargo
examples/neural-ode-weather-prediction/requirements.txt pypi
  • equinox *
  • jax *
  • jaxlib *
  • numpy ==1.26.4
  • pandas *
  • pydot *
  • tensorflow *
  • tf2onnx *
examples/python-diffsol/pyproject.toml pypi
  • numpy *
examples/electrical-circuits/Cargo.toml cargo
examples/lorenz-attractor-diffsl-llvm/Cargo.toml cargo
examples/mass-spring-fitting-adjoint/Cargo.toml cargo
diffsol/Cargo.toml cargo
  • colog 1.4.0 development
  • criterion 0.7.0 development
  • insta 1.43 development
  • paste 1.0.15 development
  • skeptic 0.13.7 development
  • diffsl 0.8.3
  • faer-traits 0.23.2
  • log 0.4.29
  • nalgebra-sparse 0.11.0
  • num-traits 0.2.17
  • petgraph 0.8.3
  • serde 1.0
  • serde_json 1.0
  • suitesparse_sys 0.1.3
  • thiserror 2.0.17
Cargo.toml cargo
.github/workflows/rust.yml actions
  • actions/checkout v3 composite