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:
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
Adjusting tolerances
All solvers acceptrtol (relative) and atol (absolute) tolerance parameters. Tighter tolerances improve accuracy at the cost of speed: