Parameter Sets

class ionworkspipeline.parameter_values.ParameterValues(values: dict[str, Any] | str | ParameterValues)
apply_degradation_state(degradation_state, inplace=True, composite=None)

Apply a degradation state to the parameter values. Can account for loss of (cyclable) lithium inventory, loss of active material and resistance change via an additional ohmic resistance (the model option “contact resistance” must be “true” for PyBaMM models to include a contact resistance).

API inspired by aepybamm (About-Energy-OpenSource/AEPyBaMM).

Note: this is not valid for composite electrodes.

Parameters

degradation_statedict

The degradation state to apply to the parameter values. Can have the following keys:

  • “LAM_ne [%]”: Loss of active material in negative electrode (%)

  • “LAM_pe [%]”: Loss of active material in positive electrode (%)

  • “LLI [%]”: Loss of lithium inventory (%)

  • “R0_addn [Ohm]”: Additional ohmic resistance (Ohm). This is achieved by adding to the contact resistance.

Each of these keys is optional, and if not provided, the default value of 0 will be used.

inplacebool, optional

If True, update the parameter values in place. Otherwise, return a new parameter values object.

composite: str, optional

Specifies a composite electrode. Can be “negative”, “positive”, “both”, or None. If None, the parameter values are assumed to be for a single-phase electrode. If specified, for the electrode specified, the LAM and LLI should have an additional parenthetical statement specifying the phase, such as LAM_ne (primary) [%].

copy()

Returns a copy of the parameter values. Makes sure to copy the internal dictionary.

classmethod from_config(filename_or_dict: str | Path | dict, resolve: bool = True) → ParameterValues

Load from JSON, rebuilding calculated parameters.

Parameters

filename_or_dictstr, Path or dict

A JSON file, or the dict to_json() returns.

resolvebool, optional

When True (the default), calculated parameters are replaced by the numbers their calculations produce, so callers that only read values never meet one. Pass False to keep them, e.g. to apply overrides first.

Returns

ParameterValues

The loaded parameter values.

classmethod from_json(filename_or_dict: str | Path | dict, resolve: bool = True) → ParameterValues

Load from JSON, rebuilding calculated parameters.

Parameters

filename_or_dictstr, Path or dict

A JSON file, or the dict to_json() returns.

resolvebool, optional

When True (the default), calculated parameters are replaced by the numbers their calculations produce, so callers that only read values never meet one. Pass False to keep them, e.g. to apply overrides first.

Returns

ParameterValues

The loaded parameter values.

scale_parameter(name, scale_factor=None, inplace=True)

Apply a scale factor to a parameter in the ParameterValues object. The updated parameter returns the original parameter value multiplied by the scale factor. If the parameter is a callable function, the updated parameter is returned as a function-like object, so that it can be used in expressions as a function of other parameters. If the parameter is not a callable function, the updated parameter is returned as a float or int equal to the original parameter value multiplied by the scale factor.

Parameters

namestr

The name of the parameter to apply the scale factor to. Must be a key in parameter_values.

scale_factorfloat, int, or pybamm.Parameter, optional

The scale factor to apply to the parameter. If None, adds a parameter with the name name + “ (scale factor)”.

inplacebool, optional

If True, update the parameter values in place. Otherwise, return a new parameter values object.

to_config(filename: str | None = None) → dict

Convert to a JSON-serializable dict, keeping calculated parameters.

pybamm’s serializer only knows pybamm types, so calculated parameters are written as their tagged form and everything else goes through pybamm.

Parameters

filenamestr, optional

If given, the dict is also written to this file.

Returns

dict

The JSON-serializable parameter values.

to_json(filename: str | None = None) → dict

Convert to a JSON-serializable dict, keeping calculated parameters.

pybamm’s serializer only knows pybamm types, so calculated parameters are written as their tagged form and everything else goes through pybamm.

Parameters

filenamestr, optional

If given, the dict is also written to this file.

Returns

dict

The JSON-serializable parameter values.

Calculated Parameters

class ionworkspipeline.CalculatedParameter(calculation: dict[str, Any], output: str)

A parameter value that is one output of a calculation.

Unlike a pybamm expression, the calculation may solve or interpolate (e.g. ElectrodeSOH), so pybamm cannot evaluate it lazily. It is replaced by a number in resolve_calculated_parameters(), and pybamm never sees it.

Parameters

calculationdict

Calculation config, in the form parse_calculation accepts and Calculation.to_config returns.

outputstr

Which of the calculation’s outputs this parameter takes.

property calculation_key: str

Canonical form of calculation; equal configs share one run.

classmethod from_json(data: dict[str, Any]) → CalculatedParameter

Rebuild from the form to_json() returns.

Raises

UserConfigurationError

If data lacks a calculation dict or an output string. Stored forms can arrive from SDK uploads, so they are checked.

static is_json(value: Any) → bool

Whether value is the stored form of a calculated parameter.

to_json() → dict[str, Any]

Return the stored form, tagged with TYPE_TAG.

ionworkspipeline.resolve_calculated_parameters(parameter_values, failures=None)

Replace every calculated parameter with the number its calculation gives.

Calculated parameters sharing a calculation config run it once. Calculations run in dependency order, each against the values resolved so far.

Parameters

parameter_valuesionworkspipeline.ParameterValues

Parameter values that may hold CalculatedParameter values.

failuresdict, optional

If given, a calculation that cannot run does not stop the others: its parameters (and those of calculations that read them) stay unresolved, and each is recorded here as name -> reason. Without it, the first failure raises.

Returns

ionworkspipeline.ParameterValues

A copy with numbers in place of calculated parameters, or parameter_values itself when it holds none.

Raises

UserConfigurationError

Unless failures is given: if a calculation config is invalid, does not produce the stored output, needs a parameter the set does not provide, or the calculations depend on each other in a cycle. The message names the parameter.

ionworkspipeline.calculation_dependencies(parameter_values) → set[str]

Every parameter some calculated parameter’s calculation reads, transitively.

Follows each calculation’s declared inputs, and the parameters any expression among those inputs references. A change to a parameter outside this set cannot change a calculated parameter.

Parameters

parameter_valuesionworkspipeline.ParameterValues

Parameter values that may hold CalculatedParameter values.

Returns

set[str]

Parameter names. A calculated parameter is included only when another calculation reads it, since overriding it then changes that one.

ionworkspipeline.declared_inputs(calculation) → list[str]

A calculation’s declared inputs, or [] when it declares none.

Parameters

calculationCalculation or dict

A calculation, or a config parse_calculation accepts.

Returns

list[str]

The parameter names the calculation reads.