PyBOP: Python Battery Optimisation and Parameterisation

repository·develop·Indexed 42 days ago

https://github.com/pybop-team/pybop

A 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.

Tokens
17.9K
Snippets
57
Records
81
Agent score
53%

What's inside PyBOP

  1. Overview of PyBOP

    develop
    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.
  2. Use cases for PyBOP

    develop

    PyBOP is designed for two primary use cases:

    1. Parameter inference: Estimating battery model parameters from experimental battery test data.
    2. 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.models module.

  3. Explore the PyBOP examples directory structure

    develop

    The 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.
  4. Perform battery model parameterisation

    develop

    Parameterisation 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

    1. 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.
    2. 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.

  5. Perform battery design optimisation

    develop

    Design optimisation aims to identify parameter sensitivities to maximize a specific design metric (e.g., gravimetric energy density) rather than minimizing error against observed data.

    PyBOP implements design optimisation by minimizing the negative of the design metric.

    Workflow

    1. Define the design metric $\mathcal{L}(\theta)$ (e.g., integral of discharge energy normalized by cell mass).
    2. Define the set of allowable parameter values $\Omega$ (constraints).
    3. Run the optimizer to find $\theta$ that maximizes the metric.

    Example use case: Optimizing electrode thickness and active material volume fraction in a PyBaMM SPMe model to maximize gravimetric energy density at a specific discharge rate (e.g., 1C).

  6. Use Pints Optimisers for solving optimisation problems

    develop
    PyBOP provides a suite of optimisers via the pybop.optimisers.pints_optimisers module. These are specialized optimisers designed for the PyBOP framework. You can use these classes to solve specific optimisation problems by instantiating them from the pints_optimisers package.
  7. Define EIS experiments for synthetic data

    develop

    Experiments 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 uses pybop.pybamm.EISSimulator for these paths.

    EIS Configuration Details:

    • Frequencies [Hz]: Can be a list of values OR an object containing Min, Max, Count, and optional Spacing.
    • Input amplitude [V]: Included in the specification for completeness, though not used by the linear EIS solver.
  8. Understand the PyBOP core architecture

    develop

    PyBOP is structured around four core components that form an optimisation workflow. To perform parameter identification or design optimisation, you construct these classes in sequence:

    1. Simulator: Generates model predictions. For example, pybop.pybamm.Simulator interfaces with PyBaMM to solve models for candidate parameter values.
    2. Cost: Evaluates an error measure, likelihood, or design metric for the candidate parameters and simulation results. Multiple costs can be summed with optional weighting.
    3. Problem: Coordinates the Simulator and Cost evaluation.
    4. Optimiser or Sampler: 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.

  9. Use SciPy Optimisers for solving optimisation problems

    develop
    PyBOP integrates with the SciPy ecosystem through the pybop.optimisers.scipy_optimisers module. This allows you to leverage standard SciPy optimisation algorithms within a PyBOP workflow. These optimisers are available as classes within the scipy_optimisers package.
  10. Perform parameter inference from EIS simulations

    develop

    For 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 Cost classes used in time-domain simulations.

  11. How PyBOP components work together

    develop

    PyBOP 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:

    1. Define a Simulator: A pybop.pybamm.Simulator is designed to simulate a pybamm.BaseModel (from PyBaMM).
    2. Define a Cost: Specifies how the simulation results are compared to data.
    3. Define a Problem: The Simulator and Cost together define the optimisation Problem.
    4. Define an Optimiser or Sampler: The Optimiser or Sampler processes the Problem to generate a Result.

    Optimisation parameters can be passed through a pybamm.ParameterValues class.