{"id":23919653,"url":"https://github.com/martinjrobins/diffsol","last_synced_at":"2026-04-06T09:02:54.618Z","repository":{"id":214451942,"uuid":"736562064","full_name":"martinjrobins/diffsol","owner":"martinjrobins","description":"ODE solver library in Rust","archived":false,"fork":false,"pushed_at":"2026-04-05T10:58:22.000Z","size":4023,"stargazers_count":108,"open_issues_count":15,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-04-05T12:19:12.019Z","etag":null,"topics":["bdf","dsl","jacobian","mass-matrix","ode","ode-integrator","ode-solver","runge-kutta","rust","scientific-computing","solver","sparse-matrix"],"latest_commit_sha":null,"homepage":"https://martinjrobins.github.io/diffsol/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martinjrobins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"martinjrobins","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2023-12-28T08:37:25.000Z","updated_at":"2026-04-05T10:58:24.000Z","dependencies_parsed_at":"2026-01-16T11:09:35.449Z","dependency_job_id":null,"html_url":"https://github.com/martinjrobins/diffsol","commit_stats":{"total_commits":249,"total_committers":3,"mean_commits":83.0,"dds":"0.24096385542168675","last_synced_commit":"9f326d8af459b294f172ef14d21b1f1cecb4d69d"},"previous_names":["martinjrobins/diffsol","martinjrobins/diffeq"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/martinjrobins/diffsol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinjrobins%2Fdiffsol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinjrobins%2Fdiffsol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinjrobins%2Fdiffsol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinjrobins%2Fdiffsol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinjrobins","download_url":"https://codeload.github.com/martinjrobins/diffsol/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinjrobins%2Fdiffsol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31466228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdf","dsl","jacobian","mass-matrix","ode","ode-integrator","ode-solver","runge-kutta","rust","scientific-computing","solver","sparse-matrix"],"created_at":"2025-01-05T14:54:04.934Z","updated_at":"2026-04-06T09:02:54.612Z","avatar_url":"https://github.com/martinjrobins.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n\u003cp\u003e\u003c/p\u003e\u003cimg src=\"https://raw.githubusercontent.com/martinjrobins/diffsol/refs/heads/main/assets/diffsol_rectangle.svg\" alt=\"diffsol logo\" width=\"300\"/\u003e\u003c/p\u003e\n\u003ca href=\"https://martinjrobins.github.io/diffsol/\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/diffsol.svg?label=mdbook\u0026color=green\u0026logo=mdbook\" alt=\"mdbook badge\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://docs.rs/diffsol\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/diffsol.svg?label=docs\u0026color=blue\u0026logo=rust\" alt=\"docs.rs badge\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/martinjrobins/diffsol/actions/workflows/rust.yml\"\u003e\n    \u003cimg src=\"https://github.com/martinjrobins/diffsol/actions/workflows/rust.yml/badge.svg\" alt=\"CI build status badge\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/martinjrobins/diffsol\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/martinjrobins/diffsol/branch/main/graph/badge.svg\" alt=\"code coverage\"\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\nDiffsol 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:\n\n```math\nM \\frac{dy}{dt} = f(t, y, p)\n```\n\nwhere $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.\n\nThe equations can be given by either rust code or the [DiffSL](https://martinjrobins.github.io/diffsl/) Domain Specific Language (DSL). The DSL uses automatic differentiation using [Enzyme](https://enzyme.mit.edu/) to calculate the necessary jacobians, and JIT compilation (using either [LLVM](https://llvm.org/) or [Cranelift](https://cranelift.dev/)) 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.\n\n## Installation\n\nYou can add diffsol using `cargo add diffsol` or directly in your `Cargo.toml`:\n\n```toml\n[dependencies]\ndiffsol = \"0.10\"\n```\n\nDiffsol has the following features that can be enabled or disabled:\n\n- `nalgebra`: Use nalgebra for linear algebra containers and solvers (enabled by default).\n- `faer`: Use faer for linear algebra containers and solvers (enabled by default).\n- `cuda`: Use in-built CUDA linear algebra containers and solvers (disabled by default, experimental).\n- `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`](https://gitlab.com/taricorp/llvm-sys.rs)) and `LLVM_DIR` environment variables to point to your LLVM installation, where `XXX` is the version number (`150`, `160`, `170`, `181`, `191`, `201`, `211`).\n- `suitesparse`: Enable SuiteSparse KLU sparse linear solver (disabled by default, requires `faer`).\n\nYou 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:\n\n```toml\n[dependencies]\ndiffsol = { version = \"0.10\", features = \"diffsl-cranelift\" }\n```\n\nSee the [Cargo.toml documentation](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html) for more information on specifying features.\n\n# Usage\n\nThe [diffsol book](https://martinjrobins.github.io/diffsol/) 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](https://docs.rs/diffsol).\n\nFor 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:\n\n```rust\nuse diffsol::{LlvmModule, NalgebraLU, NalgebraMat, OdeBuilder, OdeSolverMethod};\n\npub fn lorenz() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let problem = OdeBuilder::\u003cNalgebraMat\u003cf64\u003e\u003e::new().build_from_diffsl::\u003cLlvmModule\u003e(\n        \"\n            a { 14.0 } b { 10.0 } c { 8.0 / 3.0 }\n            u_i {\n                x = 1.0,\n                y = 0.0,\n                z = 0.0,\n            }\n            F_i {\n                b * (y - x);\n                x * (a - z) - y;\n                x * y - c * z;\n            }\n        \",\n    )?;\n    let mut solver = problem.bdf::\u003cNalgebraLU\u003cf64\u003e\u003e()?;\n    let (_ys, _ts, _stop_reason) = solver.solve(0.0)?;\n    Ok(())\n}\n```\n\n## ODE solvers\n\nThe following ODE solvers are available in diffsol\n\n1. A variable order Backwards Difference Formulae (BDF) solver, suitable for stiff problems and singular mass matrices. The basic algorithm is derived in [(Byrne \u0026 Hindmarsh, 1975)](#1), however this particular implementation follows that implemented in the Matlab routine ode15s [(Shampine \u0026 Reichelt, 1997)](#4) and the SciPy implementation [(Virtanen et al., 2020)](#5), which features the NDF formulas for improved stability\n2. 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 \u0026 Shampine, 1996)](#2) and ESDIRK34 [(Jørgensen et al., 2018)](#3), or users can supply their own.\n3. A variable order Explict Runge-Kutta (ERK) solver, suitable for non-stiff problems. One butcher tableau is provided, the 4th order TSIT45 [(Tsitouras, 2011)](#5), or users can supply their own.\n\nAll solvers feature:\n\n- Linear algebra containers and linear solvers from the nalgebra or faer crates, including both dense and sparse matrix support.\n- 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.\n- Dense output, interpolating to times provided by the user.\n- Event handling, stopping when a given condition $g_e(t, y , p)$ is met or at a specific time.\n- Numerical quadrature of an optional output $g_o(t, y, p)$ function over time.\n- Forward sensitivity analysis, calculating the gradient of an output function or the solver states $y$ with respect to the parameters $p$.\n- 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 $h_i(t_i, y_i, p)$ at time points $t_i$.\n\n## Citation\n\nIf you use diffsol in your research, please cite it:\n\n[Robinson et al., (2026). diffsol: Rust crate for solving differential equations. Journal of Open Source Software, 11(117), 9384, https://doi.org/10.21105/joss.09384](https://doi.org/10.21105/joss.09384)\n\n## Contributing\n\nContributions are very welcome, as are bug reports! Please see the [contributing guidelines](CONTRIBUTING.md) for more information, but in summary:\n\n- Please open an [issue](https://github.com/martinjrobins/diffsol/issues) or [discussion](https://github.com/martinjrobins/diffsol/discussions) to report any issues or problems using diffsol\n- There are a number of repositories in the diffsol ecosystem, please route your issue/request to the appropriate repository:\n  - [diffsol](https://github.com/martinjrobins/diffsol) - the core ODE solver library\n  - [diffsl](https://github.com/martinjrobins/diffsl) - the DiffSL DSL compiler and JIT backends\n  - [pydiffsol](https://github.com/alexallmont/pydiffsol) - Python bindings\n- 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](CONTRIBUTING.md) describe how to set up a development environment, run tests, and format code.\n\n## Wanted - Developers for higher-level language wrappers\n\nDiffsol 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.\n\nDiffsol makes heavy use of generic programming, which can make it difficult to use from other languages. To help with this, the diffsol-c crate provides a wrapper around the core library using runtime polymorphism, and a C API that can be called via FFI. Combined with the DiffSL DSL, this allows for efficient use of diffsol from other languages without needing to write rust code. The following wrappers are currently planned:\n\n- [x] Python (e.g. using [PyO3](https://pyo3.rs/v0.24.0/)). \u003chttps://github.com/alexallmont/pydiffsol\u003e.\n- [ ] Python ML frameworks (e.g. [JAX](https://docs.jax.dev/en/latest/ffi.html), [PyTorch](https://pytorch.org/tutorials/advanced/cpp_extension.html))\n- [ ] R (e.g. using [extendr](https://extendr.github.io/)).\n- [ ] Julia\n- [ ] Matlab\n- [ ] Javascript in backend (e.g using [Neon](https://neon-rs.dev/))\n- [ ] Javascript in browser (e.g. using [wasm-pack](https://rustwasm.github.io/wasm-pack/))\n- [ ] Others, feel free to suggest your favourite language.\n\n## References\n\n- \u003ca id=\"1\"\u003e\u003c/a\u003e Byrne, G. D., \u0026 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\n- \u003ca id=\"2\"\u003e\u003c/a\u003e Hosea, M., \u0026 Shampine, L. (1996). Analysis and implementation of TR-BDF2. Applied Numerical Mathematics, 20(1-2), 21–37.\n- \u003ca id=\"3\"\u003e\u003c/a\u003e Jørgensen, J. B., Kristensen, M. R., \u0026 Thomsen, P. G. (2018). A family of ESDIRK integration methods. arXiv Preprint arXiv:1803.01613.\n- \u003ca id=\"4\"\u003e\u003c/a\u003e Shampine, L. F., \u0026 Reichelt, M. W. (1997). The matlab ode suite. SIAM Journal on Scientific Computing, 18(1), 1–22.\n- \u003ca id=\"5\"\u003e\u003c/a\u003e Virtanen, P., Gommers, R., Oliphant, T. E., Haberland, M., Reddy, T., Cournapeau, D., Burovski, E., Peterson, P., Weckesser, W., Bright, J., \u0026 others. (2020). SciPy 1.0: Fundamental algorithms for scientific computing in python. Nature Methods, 17(3), 261–272.\n - \u003ca id=\"5\"\u003e\u003c/a\u003e Tsitouras, C. (2011). Runge–Kutta pairs of order 5 (4) satisfying only the first column simplifying assumption. Computers \u0026 Mathematics with Applications, 62(2), 770-775.\n","funding_links":["https://github.com/sponsors/martinjrobins"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinjrobins%2Fdiffsol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinjrobins%2Fdiffsol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinjrobins%2Fdiffsol/lists"}