Solver Comparison
| Solver | Backend | ODE | DAE | Sensitivity | Notes |
|---|---|---|---|---|---|
CasadiSolver | CasADi / SUNDIALS | Yes | Yes | Yes | General-purpose; safe mode handles events |
IDAKLUSolver | SUNDIALS IDA + KLU | Yes | Yes | Yes | Fastest for most problems; recommended default |
ScipySolver | SciPy solve_ivp | Yes | No | No | Simple; no DAE support |
JaxSolver | JAX | Yes | BDF only | No | GPU/TPU capable; requires Python ≥ 3.11 |
AlgebraicSolver | SciPy root-finding | No | Algebraic only | No | For purely algebraic (steady-state) problems |
CompositeSolver | Multiple backends | Yes | Yes | Varies | Tries multiple solvers until one succeeds |
CasadiAlgebraicSolver | CasADi | No | Algebraic only | No | CasADi-based algebraic solver |
Choosing a Solver
- Most lithium-ion models (SPM, SPMe, DFN) include algebraic equations (DAEs). Use
IDAKLUSolver(default inpybamm.Simulation) for best performance. - Drive-cycle simulations with no voltage events: use
CasadiSolver(mode="fast")orIDAKLUSolver. - Simple ODE-only models (equivalent circuit, 0D):
ScipySolverworks well and has minimal dependencies. - Batch parameter sweeps on GPU/TPU:
JaxSolverwithmethod="RK45"enables JIT compilation.
BaseSolver Common Interface
All solvers inherit frompybamm.BaseSolver and share the following constructor parameters and methods.
Constructor Parameters
Integration method name. Meaning is solver-specific.
Relative tolerance.
Absolute tolerance.
Method used to compute consistent initial conditions for DAE problems. Options include
"casadi", "lm", "hybr", or a PyBaMM algebraic solver class.Tolerance for the initial-condition root-finding step.
Tolerance for detecting extrapolation beyond the solved time span.
Behaviour when extrapolation is detected. One of
"warn", "error", or "ignore".If specified, only these variables are computed and returned (reduces memory usage).
solve
t_eval and return a pybamm.Solution object.
step
dt. Useful for online / real-time simulation.