PyBaMM
raw JSON → 26.4.2 verified Sat May 09 auth: no python
Python Battery Mathematical Modelling (PyBaMM) is an open-source battery simulation package written in Python, currently at version 26.4.2. It provides a framework for building and solving continuum models for batteries, with support for experimental protocols and parameter estimation. PyBaMM releases on a monthly cadence.
pip install pybamm Common errors
error ModuleNotFoundError: No module named 'pybamm' ↓
cause PyBaMM is not installed.
fix
Run 'pip install pybamm' in your environment.
error ValueError: Expected solver to be 'casadi' or 'scikits.odes', got ... ↓
cause Unsupported solver specified.
fix
Use one of the supported solvers: 'casadi', 'scikits.odes', or leave default.
error pybamm.ModelError: Assigning a variable/parameter that does not exist in the model ↓
cause Trying to set a parameter or variable that is not part of the selected model.
fix
Check the model's parameter list using model.parameters or model.variables.
error pybamm.SolverError: Could not find valid consistent initial conditions ↓
cause The model's initial conditions are inconsistent or missing.
fix
Manually set initial conditions via model.set_initial_conditions or use a model with known consistent defaults.
Warnings
breaking In v26.4.0, Simulation was split into BaseSimulation and Simulation. Custom subclasses of Simulation may break if they relied on internal methods that moved to BaseSimulation. ↓
fix If you have custom subclasses, inherit from BaseSimulation instead, or override as needed.
gotcha EISSimulation.solve(initial_soc=..., inputs=...) does not forward inputs to build pre-v26.4.2. This was fixed in v26.4.2. ↓
fix Upgrade to v26.4.2 or later, or manually set inputs before calling solve.
deprecated The 'pybamm.get_parameters_collections' function is deprecated and will be removed in a future release. Use 'pybamm.ParameterValues' directly. ↓
fix Replace calls to pybamm.get_parameters_collections with pybamm.ParameterValues.create_from_... methods.
gotcha Serialise.load_custom_model may silently fall back to pybamm.BaseModel if the saved base class cannot be imported. This was fixed in v26.4.2 to walk the recorded MRO. ↓
fix Upgrade to v26.4.2 or later to avoid silent fallback.
Imports
- pybamm
import pybamm - Simulation
from pybamm import Simulation - model wrong
pybamm.SPM()correctpybamm.lithium_ion.SPM()
Quickstart
import pybamm
# Create a model
model = pybamm.lithium_ion.SPM()
# Create a simulation
sim = pybamm.Simulation(model)
# Solve
solution = sim.solve()
# Plot
solution.plot()