PyBOP: Python Battery Optimisation and Parameterisation
repository·develop·Indexed 42 days ago
https://github.com/pybop-team/pybopA Python package for the parameterisation and optimisation of battery models, supporting both Bayesian and frequentist approaches. PyBOP integrates with PyBaMM to simulate electrochemical and equivalent circuit models (ECM) and is designed for parameter inference and design optimisation. Version 26.3 includes tools for defining simulators, costs, and problems, with optimisers available via Pints and SciPy.
What's inside PyBOP
- PyBOP is a Python package dedicated to the optimisation and parameterisation of battery models. It is designed to streamline workflows for academic research, industrial applications, and general battery technology modelling.
Use cases for PyBOP
developPyBOP is designed for two primary use cases:
- Parameter inference: Estimating battery model parameters from experimental battery test data.
- Design optimisation: Optimising battery designs under specific manufacturing or usage constraints.
PyBOP can be used with various battery models, including electrochemical and equivalent circuit models (ECM) available in PyBaMM. It also includes purpose-built grouped-parameter versions of common models found in the
pybop.modelsmodule.Explore the PyBOP examples directory structure
developThe
examples/directory is organized into three main sections for different usage patterns:notebooks/: Interactive Jupyter notebooks containing detailed explanations, code snippets, and visualizations.scripts/: Standalone Python scripts intended for quick reference and command-line execution of specific workflows.standalone/: Example scripts specifically demonstrating how to use standalone classes.
Use Pints Samplers for stochastic optimisation
developFor problems requiring sampling-based approaches, PyBOP provides samplers via thepybop.samplers.pints_samplersmodule. These samplers can be used alongside optimisers to explore the parameter space.Perform battery model parameterisation
developParameterisation involves finding the model parameters $\theta$ that best match observed experimental data $(\hat{\mathbf{y}_i})$. This is formulated as minimizing a cost function $\mathcal{L}$ that quantifies the agreement between model output and observations.
Approaches to Parameterisation
- Optimization (Maximum Likelihood / MAP): Formulate the problem as a minimization task. For gradient-based optimizers, the Jacobian of the cost function with respect to parameters is required.
- Tip: If parameters differ significantly in magnitude (e.g., diffusivity vs. contact resistance), apply a logarithmic transformation to the search space to allow for a common step size and improve convergence.
- Bayesian Inference (Sampling): Instead of a single point estimate, use sampling methods to reconstruct the full posterior distribution $P(\theta|D)$. This provides uncertainty quantification (e.g., variance or credible intervals) for the identified parameters.
Available Methods
- Gradient-based: e.g., BFGS (via
SciPy), NUTS, or Hamiltonian Monte Carlo. - Evolutionary/Heuristic: e.g., Differential Evolution.
- Sampling: e.g., Adaptive covariance-based samplers (Haario Bardenet) or Metropolis-Hastings.
For practical implementations, refer to the example notebooks in the repository.
- Optimization (Maximum Likelihood / MAP): Formulate the problem as a minimization task. For gradient-based optimizers, the Jacobian of the cost function with respect to parameters is required.
Perform battery design optimisation
developDesign optimisation aims to identify parameter sensitivities to maximize a specific design metric (e.g., gravimetric energy density) rather than minimizing error against observed data.
PyBOPimplements design optimisation by minimizing the negative of the design metric.Workflow
- Define the design metric $\mathcal{L}(\theta)$ (e.g., integral of discharge energy normalized by cell mass).
- Define the set of allowable parameter values $\Omega$ (constraints).
- Run the optimizer to find $\theta$ that maximizes the metric.
Example use case: Optimizing electrode thickness and active material volume fraction in a
PyBaMMSPMe model to maximize gravimetric energy density at a specific discharge rate (e.g., 1C).Use Pints Optimisers for solving optimisation problems
developPyBOP provides a suite of optimisers via thepybop.optimisers.pints_optimisersmodule. These are specialized optimisers designed for the PyBOP framework. You can use these classes to solve specific optimisation problems by instantiating them from thepints_optimiserspackage.Define EIS experiments for synthetic data
developExperiments are typically defined as lists of PyBaMM experiment step strings. However, to define an Electrochemical Impedance Spectroscopy (EIS) experiment, you must add
"Type": "EIS"and EIS-specific fields to the experiment object. The generator usespybop.pybamm.EISSimulatorfor these paths.EIS Configuration Details:
Frequencies [Hz]: Can be a list of values OR an object containingMin,Max,Count, and optionalSpacing.Input amplitude [V]: Included in the specification for completeness, though not used by the linear EIS solver.
Understand the PyBOP core architecture
developPyBOP is structured around four core components that form an optimisation workflow. To perform parameter identification or design optimisation, you construct these classes in sequence:
Simulator: Generates model predictions. For example,pybop.pybamm.Simulatorinterfaces withPyBaMMto solve models for candidate parameter values.Cost: Evaluates an error measure, likelihood, or design metric for the candidate parameters and simulation results. Multiple costs can be summed with optional weighting.Problem: Coordinates theSimulatorandCostevaluation.OptimiserorSampler: Performs the actual parameter inference through optimisation algorithms (deterministic) or Monte Carlo sampling (stochastic).
This modular structure allows for extensibility, enabling new models or optimisers to be used with a consistent interface.
Use SciPy Optimisers for solving optimisation problems
developPyBOP integrates with the SciPy ecosystem through thepybop.optimisers.scipy_optimisersmodule. This allows you to leverage standard SciPy optimisation algorithms within a PyBOP workflow. These optimisers are available as classes within thescipy_optimiserspackage.Perform parameter inference from EIS simulations
developFor Electrochemical Impedance Spectroscopy (EIS) tasks, use the
pybop.pybamm.EISSimulator.This simulator discretises and linearises the EIS forward model into a sparse mass matrix form with an auto-differentiated Jacobian. The results are returned in the frequency domain, making them compatible with the standard
Costclasses used in time-domain simulations.How PyBOP components work together
developPyBOP provides tools for the parameterisation and optimisation of battery models using both Bayesian and frequentist approaches.
As of v25.10, the core workflow has been restructured. Instead of setting up a model, problem, cost, and then optimiser, the new workflow follows this sequence:
- Define a Simulator: A
pybop.pybamm.Simulatoris designed to simulate apybamm.BaseModel(from PyBaMM). - Define a Cost: Specifies how the simulation results are compared to data.
- Define a Problem: The
SimulatorandCosttogether define the optimisationProblem. - Define an Optimiser or Sampler: The
OptimiserorSamplerprocesses theProblemto generate aResult.
Optimisation parameters can be passed through a
pybamm.ParameterValuesclass.- Define a Simulator: A