pybop.models.base_model#

Attributes#

Classes#

BaseModel

A base class for constructing and simulating models using PyBaMM.

TimeSeriesState

The current state of a time series model that is a pybamm model

Module Contents#

class pybop.models.base_model.BaseModel(name='Base Model')[source]#

A base class for constructing and simulating models using PyBaMM.

This class serves as a foundation for building specific models in PyBaMM. It provides methods to set up the model, define parameters, and perform simulations. The class is designed to be subclassed for creating models with custom behavior.

_check_params(inputs=None, allow_infeasible_solutions=True)[source]#

A compatibility check for the model parameters which can be implemented by subclasses if required, otherwise it returns True by default.

Parameters:
  • inputs (dict) – The input parameters for the simulation.

  • allow_infeasible_solutions (bool, optional) – If True, infeasible parameter values will be allowed in the optimisation (default: True).

Returns:

A boolean which signifies whether the parameters are compatible.

Return type:

bool

abstract approximate_capacity(x)[source]#

Calculate a new estimate for the nominal capacity based on the theoretical energy density and an average voltage.

This method must be implemented by subclasses.

Parameters:

x (array-like) – An array of values representing the model inputs.

Raises:

NotImplementedError – If the method has not been implemented by the subclass.

build(dataset=None, parameters=None, check_model=True, init_soc=None)[source]#

Construct the PyBaMM model if not already built, and set parameters.

This method initializes the model components, applies the given parameters, sets up the mesh and discretisation if needed, and prepares the model for simulations.

Parameters:
  • dataset (pybamm.Dataset, optional) – The dataset to be used in the model construction.

  • parameters (dict, optional) – A dictionary containing parameter values to apply to the model.

  • check_model (bool, optional) – If True, the model will be checked for correctness after construction.

  • init_soc (float, optional) – The initial state of charge to be used in simulations.

abstract cell_mass(parameter_set=None)[source]#

Calculate the cell mass in kilograms.

This method must be implemented by subclasses.

Parameters:

parameter_set (dict, optional) – A dictionary containing the parameter values necessary for the mass calculations.

Raises:

NotImplementedError – If the method has not been implemented by the subclass.

abstract cell_volume(parameter_set=None)[source]#

Calculate the cell volume in m3.

This method must be implemented by subclasses.

Parameters:

parameter_set (dict, optional) – A dictionary containing the parameter values necessary for the volume calculation.

Raises:

NotImplementedError – If the method has not been implemented by the subclass.

check_params(inputs=None, parameter_set=None, allow_infeasible_solutions=True)[source]#

Check compatibility of the model parameters.

Parameters:
  • inputs (dict) – The input parameters for the simulation.

  • allow_infeasible_solutions (bool, optional) – If True, infeasible parameter values will be allowed in the optimisation (default: True).

Returns:

A boolean which signifies whether the parameters are compatible.

Return type:

bool

classify_and_update_parameters(parameters)[source]#

Update the parameter values according to their classification as either ‘matched_parameters’ which require a model rebuild and ‘non_matched_parameters’ which are standard inputs.

Parameters:

parameters (pybop.ParameterSet)

copy()[source]#

Return a copy of the model.

Returns:

A copy of the model.

Return type:

BaseModel

get_state(inputs: Inputs, t: float, x: numpy.ndarray) TimeSeriesState[source]#

Returns the given state for the problem (inputs are assumed constant since last reinit)

predict(inputs=None, t_eval=None, parameter_set=None, experiment=None, init_soc=None)[source]#

Solve the model using PyBaMM’s simulation framework and return the solution.

This method sets up a PyBaMM simulation by configuring the model, parameters, experiment (if any), and initial state of charge (if provided). It then solves the simulation and returns the resulting solution object.

Parameters:
  • inputs (dict or array-like, optional) – Input parameters for the simulation. If the input is array-like, it is converted to a dictionary using the model’s fitting keys. Defaults to None, indicating that the default parameters should be used.

  • t_eval (array-like, optional) – An array of time points at which to evaluate the solution. Defaults to None, which means the time points need to be specified within experiment or elsewhere.

  • parameter_set (pybamm.ParameterValues, optional) – A PyBaMM ParameterValues object or a dictionary containing the parameter values to use for the simulation. Defaults to the model’s current ParameterValues if None.

  • experiment (pybamm.Experiment, optional) – A PyBaMM Experiment object specifying the experimental conditions under which the simulation should be run. Defaults to None, indicating no experiment.

  • init_soc (float, optional) – The initial state of charge for the simulation, as a fraction (between 0 and 1). Defaults to None.

Returns:

The solution object returned after solving the simulation.

Return type:

pybamm.Solution

Raises:

ValueError – If the model has not been configured properly before calling this method or if PyBaMM models are not supported by the current simulation method.

rebuild(dataset=None, parameters=None, parameter_set=None, check_model=True, init_soc=None)[source]#

Rebuild the PyBaMM model for a given parameter set.

This method requires the self.build() method to be called first, and then rebuilds the model for a given parameter set. Specifically, this method applies the given parameters, sets up the mesh and discretisation if needed, and prepares the model for simulations.

Parameters:
  • dataset (pybamm.Dataset, optional) – The dataset to be used in the model construction.

  • parameters (dict, optional) – A dictionary containing parameter values to apply to the model.

  • parameter_set (pybop.parameter_set, optional) – A PyBOP parameter set object or a dictionary containing the parameter values

  • check_model (bool, optional) – If True, the model will be checked for correctness after construction.

  • init_soc (float, optional) – The initial state of charge to be used in simulations.

reinit(inputs: Inputs, t: float = 0.0, x: numpy.ndarray | None = None) TimeSeriesState[source]#

Initialises the solver with the given inputs and returns the initial state of the problem

set_init_soc(init_soc)[source]#

Set the initial state of charge for the battery model.

Parameters:

init_soc (float) – The initial state of charge to be used in the model.

set_params(rebuild=False)[source]#

Assign the parameters to the model.

This method processes the model with the given parameters, sets up the geometry, and updates the model instance.

simulate(inputs, t_eval) numpy.ndarray[numpy.float64][source]#

Execute the forward model simulation and return the result.

Parameters:
  • inputs (dict or array-like) – The input parameters for the simulation. If array-like, it will be converted to a dictionary using the model’s fit keys.

  • t_eval (array-like) – An array of time points at which to evaluate the solution.

Returns:

The simulation result corresponding to the specified signal.

Return type:

array-like

Raises:

ValueError – If the model has not been built before simulation.

simulateS1(inputs, t_eval)[source]#

Perform the forward model simulation with sensitivities.

Parameters:
  • inputs (dict or array-like) – The input parameters for the simulation. If array-like, it will be converted to a dictionary using the model’s fit keys.

  • t_eval (array-like) – An array of time points at which to evaluate the solution and its sensitivities.

Returns:

A tuple containing the simulation result and the sensitivities.

Return type:

tuple

Raises:

ValueError – If the model has not been built before simulation.

step(state: TimeSeriesState, time: numpy.ndarray) TimeSeriesState[source]#

Step forward in time from the given state until the given time.

Parameters:
  • state (TimeSeriesState) – The current state of the model

  • time (np.ndarray) – The time to simulate the system until (in whatever time units the model is in)

property built_model[source]#
property geometry[source]#
property mesh[source]#
property model_with_set_params[source]#
property parameter_set[source]#
property solver[source]#
property spatial_methods[source]#
property submesh_types[source]#
property var_pts[source]#
class pybop.models.base_model.TimeSeriesState[source]#

Bases: object

The current state of a time series model that is a pybamm model

__len__()[source]#
as_ndarray() numpy.ndarray[source]#
inputs: Inputs[source]#
sol: pybamm.Solution[source]#
t: float = 0.0[source]#
pybop.models.base_model.Inputs[source]#