Solver Comparison
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
str
default:"None"
Integration method name. Meaning is solver-specific.
float
default:"1e-6"
Relative tolerance.
float
default:"1e-6"
Absolute tolerance.
str | algebraic solver
default:"None"
Method used to compute consistent initial conditions for DAE problems. Options include
"casadi", "lm", "hybr", or a PyBaMM algebraic solver class.float
default:"1e-6"
Tolerance for the initial-condition root-finding step.
float
default:"-1e-10"
Tolerance for detecting extrapolation beyond the solved time span.
str
default:"\"warn\""
Behaviour when extrapolation is detected. One of
"warn", "error", or "ignore".list[str]
default:"[]"
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.