pybop.parameters.parameter_set#

Classes#

ParameterSet

Handles the import and export of parameter sets for battery models.

Functions#

set_formation_concentrations(parameter_set)

Compute the concentration of lithium in the positive electrode assuming that

Module Contents#

class pybop.parameters.parameter_set.ParameterSet(parameter_set: str | dict | pybamm.ParameterValues = None, json_path: str | None = None, formation_concentrations: bool | None = False)[source]#

Handles the import and export of parameter sets for battery models.

This class provides methods to load parameters from a JSON file and to export them back to a JSON file. It also includes custom logic to handle special cases, such as parameter values that require specific initialization.

Parameters:
  • parameter_set (Union[str, dict, ParameterValues], optional) – A dictionary of parameters to initialise the ParameterSet with. If not provided, an empty dictionary is used.

  • json_path (str, optional) – Path to a JSON file containing parameter data. If provided, parameters will be imported from this file during initialisation.

  • formation_concentrations (bool, optional) – If True, re-calculates the initial concentrations of lithium in the active material (default: False).

__getitem__(key)[source]#
__setitem__(key, value)[source]#
copy()[source]#
static evaluate_symbol(symbol: pybamm.Symbol | numbers.Number, params: dict)[source]#

Evaluate a parameter in the parameter set.

Parameters:

symbol (pybamm.Symbol or Number) – The parameter to evaluate.

Returns:

The value of the parameter.

Return type:

float

export_parameters(output_json_path, fit_params=None)[source]#

Exports parameters to a JSON file specified by output_json_path.

The current state of the params attribute is written to the file. If fit_params is provided, these parameters are updated before export. Non-serializable values are handled and noted in the output JSON.

Parameters:
  • output_json_path (str) – The file path where the JSON output will be saved.

  • fit_params (list of fitted parameter objects, optional) – Parameters that have been fitted and need to be included in the export.

Raises:

ValueError – If there are no parameters to export.

import_parameters(json_path: str | None = None)[source]#

Imports parameters from a JSON file specified by the json_path attribute.

If a json_path is provided at initialization or as an argument, that JSON file is loaded and the parameters are stored in the params attribute. Special cases are handled appropriately.

Parameters:

json_path (str, optional) – Path to the JSON file from which to import parameters. If provided, it overrides the instance’s json_path.

Returns:

The dictionary containing the imported parameters.

Return type:

dict

Raises:

FileNotFoundError – If the specified JSON file cannot be found.

is_json_serializable(value)[source]#

Determines if the given value can be serialized to JSON format.

Parameters:

value (any) – The value to check for JSON serializability.

Returns:

True if the value is JSON serializable, False otherwise.

Return type:

bool

keys() list[source]#

A list of parameter names

classmethod pybamm(name)[source]#

Retrieves a PyBaMM parameter set by name.

Parameters:

name (str) – The name of the PyBaMM parameter set to retrieve.

Returns:

A PyBaMM parameter set corresponding to the provided name.

Return type:

pybamm.ParameterValues

classmethod to_pybamm(parameter_set)[source]#

Converts a parameter set to a new PyBaMM ParameterValues object.

update(params_dict: dict = None, check_already_exists: bool = True)[source]#

Update the parameter dictionary.

Parameters:
  • params_dict (dict) – A dictionary of parameters and values used to update the parameter values

  • check_already_exists (bool, optional) – Whether to check that a parameter in params_dict already exists when trying to update it. This is to avoid cases where an intended change in the parameters is ignored due a typo in the parameter name (default: True).

_json_path = None[source]#
chemistry = None[source]#
formation_concentrations = False[source]#
parameter_values = None[source]#
pybop.parameters.parameter_set.set_formation_concentrations(parameter_set)[source]#

Compute the concentration of lithium in the positive electrode assuming that all lithium in the active material originated from the positive electrode.

Only perform the calculation if an initial concentration exists for both electrodes, i.e. it is not a half cell.

Parameters:

parameter_set (pybamm.ParameterValues) – A PyBaMM parameter set containing standard lithium ion parameters.