PyBaMM provides several solvers suited to different use cases. All solvers accept a common set of tolerance parameters and are interchangeable — you pass a solver instance toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pybamm-team/PyBaMM/llms.txt
Use this file to discover all available pages before exploring further.
pybamm.Simulation.
Solver overview
CasadiSolver
The recommended general-purpose solver. Uses CasADi for JIT-compiled, efficient integration. Supports DAEs, events, and multiple operating modes.
IDAKLUSolver
High-performance solver using SUNDIALS IDA with the KLU sparse direct solver. The fastest option for most PyBaMM models, especially in experiment mode or when solving many steps.
ScipySolver
Wraps
scipy.integrate.solve_ivp. Easy to use and well-understood, but does not support DAEs or sensitivity analysis. Good for ODE-only models and debugging.JaxSolver
JAX-compiled solver, enabling JIT compilation and automatic differentiation. Requires Python ≥ 3.11 and is not available on Intel macOS.
CasadiSolver
The default solver for most models. It compiles the model to a CasADi function and integrates using the CVODES/IDA integrators inside CasADi.Modes
Themode parameter controls the integration strategy:
| Mode | Description | When to use |
|---|---|---|
"safe" (default) | Step-and-check in global steps of size dt_max, looking for events | Full charge/discharge simulations |
"fast" | Direct integration without event detection | Drive cycles or simulations where no events should be triggered |
"fast with events" | Direct integration, then retrospectively check for events | Experimental |
"safe without grid" | Step-by-step without pre-computing the time grid | Experimental; can be faster in some cases |
Key options
IDAKLUSolver
The fastest solver for PyBaMM models. Uses the SUNDIALS IDA time integrator with the KLU sparse linear solver, called via thepybammsolvers package.
Key options
output_variables for speed
When you only need a small set of outputs, specifying output_variables avoids computing and storing the full state vector:
Parallel solving
IDAKLUSolver can solve multiple input sets in parallel using OpenMP threads:
ScipySolver
Wrapsscipy.integrate.solve_ivp. Only supports ODE models (no algebraic equations), so it cannot solve DFN or SPMe without modification.
JaxSolver
A JAX-based solver that enables JIT compilation and compatibility with JAX’s automatic differentiation.Passing a solver to Simulation
Choosing a solver
| Scenario | Recommended solver |
|---|---|
| General-purpose charge/discharge | CasadiSolver(mode="safe") |
| Drive cycle (no events expected) | CasadiSolver(mode="fast") |
| Maximum performance / experiment cycling | IDAKLUSolver() |
| Only need a few output variables | IDAKLUSolver(output_variables=[...]) |
| ODE-only model, quick debugging | ScipySolver() |
| JAX ecosystem / AD through solve | JaxSolver() |
Adjusting tolerances
All solvers acceptrtol (relative) and atol (absolute) tolerance parameters. Tighter tolerances improve accuracy at the cost of speed: