Skip to main content
pybamm.IDAKLUSolver is generally the fastest solver for lithium-ion battery models. It wraps the SUNDIALS IDA DAE integrator with the KLU sparse-direct linear solver, provided by the pybammsolvers package.

Constructor

pybamm.IDAKLUSolver(
    rtol=1e-4,
    atol=1e-6,
    root_method="casadi",
    root_tol=1e-6,
    extrap_tol=None,
    on_extrapolation=None,
    on_failure="error",
    output_variables=None,
    options=None,
)
rtol
float
default:"1e-4"
Relative tolerance for the IDA integrator.
atol
float
default:"1e-6"
Absolute tolerance for the IDA integrator.
root_method
str
default:"\"casadi\""
Method for consistent initial conditions. "casadi" uses CasADi’s Newton solver; any scipy.optimize.root method string is also accepted.
root_tol
float
default:"1e-6"
Tolerance for the root-finding step.
extrap_tol
float | None
default:"0"
Tolerance for detecting extrapolation beyond the solved interval.
on_extrapolation
str
default:"\"warn\""
Behaviour on extrapolation: "warn", "error", or "ignore".
on_failure
str
default:"\"error\""
Behaviour when the solver returns an error flag: "error", "warn", or "ignore".
output_variables
list[str] | None
default:"[]"
If provided, only these variables are computed during the solve. This can significantly reduce memory usage and solve time for large models.
options
dict | None
default:"{}"
Advanced solver options. See the Options reference below.

Options Reference

The options dict exposes the full SUNDIALS IDA configuration. All keys and their defaults:
KeyDefaultDescription
print_statsFalsePrint solver statistics after each solve
num_threads1Number of OpenMP threads
num_solversnum_threadsNumber of parallel solvers (for input-parameter sweeps)
linear_solver"SUNLinSol_KLU"SUNDIALS linear solver. Options: "SUNLinSol_KLU", "SUNLinSol_Dense", "SUNLinSol_Band", "SUNLinSol_SPBCGS", "SUNLinSol_SPGMR", etc.
jacobian"sparse"Jacobian form: "none", "dense", "banded", "sparse", "matrix-free"
preconditioner"BBDP"Preconditioner for iterative solvers: "none" or "BBDP"
max_order_bdf5Maximum order of the BDF linear multistep method
max_num_steps100000Maximum steps to reach the next output time
dt_init0.0Initial step size (0 = solver chooses)
dt_min0.0Minimum absolute step size (0 = solver chooses)
dt_max0.0Maximum absolute step size (0 = solver chooses)
max_error_test_failures10Maximum error-test failures per step
max_nonlinear_iterations40Maximum nonlinear iterations per step
max_convergence_failures100Maximum nonlinear convergence failures per step
hermite_interpolationTrueStore Hermite interpolation data. Disabled when output_variables are given.
hermite_reduction_factor1.0Compression factor for Hermite spline (values > 1 reduce storage with a small accuracy cost)
suppress_algebraic_errorFalseExclude algebraic variables from the error test
silence_sundials_errorsFalseSuppress SUNDIALS error messages during solve
calc_icTrueCalculate consistent initial conditions
init_all_y_icFalseIf True, compute all y₀ given ẏ₀; if False, compute algebraic y₀ and differential ẏ₀ given differential y₀

Examples

import pybamm

solver = pybamm.IDAKLUSolver()

sim = pybamm.Simulation(
    pybamm.lithium_ion.DFN(),
    parameter_values=pybamm.ParameterValues("Chen2020"),
    solver=solver,
)
sol = sim.solve([0, 3600])
print(sol["Terminal voltage [V]"].entries[-1])
IDAKLUSolver is the default solver used by pybamm.Simulation when no solver is specified. For most lithium-ion simulations, the defaults are a good starting point.

Build docs developers (and LLMs) love