pybop.parameters.parameter_set#

Classes#

ParameterSet

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

Module Contents#

class pybop.parameters.parameter_set.ParameterSet(json_path=None, params_dict=None)[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:
  • json_path (str, optional) – Path to a JSON file containing parameter data. If provided, parameters will be imported from this file during initialization.

  • params_dict (dict, optional) – A dictionary of parameters to initialize the ParameterSet with. If not provided, an empty dictionary is used.

_handle_special_cases()[source]#

Processes special cases for parameter values that require custom handling.

For example, if the open-circuit voltage is specified as ‘default’, it will fetch the default value from the PyBaMM empirical Thevenin model.

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=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

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