Parameter Store#

The ParameterStore class provides clean parameter storage with FuzzyDict lookup and explicit control over update behavior.

ParameterStore#

class pybamm.parameters.ParameterStore(initial_data: dict[str, Any] | None = None)[source]#

Manages parameter key-value storage with FuzzyDict lookup.

This class provides a clean interface for storing and retrieving parameters with explicit control over update behavior.

Parameters:

initial_data (dict | None) – Initial parameter data. If None, starts empty.

Examples

>>> store = ParameterStore({"Temperature [K]": 298.15})
>>> store["Temperature [K]"]
298.15
>>> store.set("New param", 42, allow_new=True)
>>> store.get_info("Temperature [K]")
ParameterInfo(name='Temperature [K]', value=298.15, units='K', ...)
categories() dict[str, list[str]][source]#

Return all parameters grouped by category.

Returns:

Dictionary mapping category names to lists of parameter names.

Return type:

dict[str, list[str]]

Example

>>> store = ParameterStore({"Temperature [K]": 298.15})
>>> cats = store.categories()
>>> "thermal" in cats
True
copy() ParameterStore[source]#

Return a shallow copy of the store.

Example

>>> store = ParameterStore({"a": 1})
>>> store_copy = store.copy()
>>> store_copy["a"] = 99
>>> store["a"]  # Original unchanged
1
diff(other: ParameterStore, *, rtol: float = 0.0) ParameterDiff[source]#

Compare this store with another and return differences.

Parameters:
  • other (ParameterStore) – The other parameter store to compare against.

  • rtol (float, optional) – Relative tolerance for numerical comparisons. Differences smaller than rtol * max(|a|, |b|) are ignored. Default is 0.0 (exact comparison). Set to e.g. 1e-6 to ignore tiny floating-point differences.

Returns:

Object containing added, removed, and changed parameters.

Return type:

ParameterDiff

Examples

>>> store1 = ParameterStore({"a": 1, "b": 2})
>>> store2 = ParameterStore({"b": 3, "c": 4})
>>> diff = store1.diff(store2)
>>> diff.added
{'c': 4}
>>> diff.removed
{'a': 1}
>>> diff.changed
{'b': (2, 3)}

With tolerance to ignore small differences:

>>> store1 = ParameterStore({"x": 1.0})
>>> store2 = ParameterStore({"x": 1.0 + 1e-10})
>>> diff = store1.diff(store2, rtol=1e-9)
>>> diff.changed  # Empty because difference is within tolerance
{}
get(key: str, default: Any = None) Any[source]#

Get a parameter value, returning default if not found.

Example

>>> store = ParameterStore({"a": 1})
>>> store.get("a")
1
>>> store.get("missing", default=0)
0
get_info(key: str) ParameterInfo[source]#

Get metadata about a parameter.

Parameters:

key (str) – The parameter name.

Returns:

Metadata including value, units, category, and type information.

Return type:

ParameterInfo

Examples

>>> store = ParameterStore({"Maximum concentration [mol.m-3]": 51765})
>>> info = store.get_info("Maximum concentration [mol.m-3]")
>>> info.units
'mol.m-3'
>>> info.is_function
False
items()[source]#

Return parameter items.

keys()[source]#

Return parameter keys.

list_by_category(category: ParameterCategory | str) list[str][source]#

Return all parameter names in a given category.

Parameters:

category (ParameterCategory or str) – The category to filter by. Can be a ParameterCategory enum value or a string like “negative electrode”.

Returns:

List of parameter names in the category.

Return type:

list[str]

Example

>>> store = ParameterStore({"Negative electrode thickness [m]": 1e-4})
>>> store.list_by_category("negative electrode")
['Negative electrode thickness [m]']
pop(key: str, *args) Any[source]#

Remove and return a parameter value.

Example

>>> store = ParameterStore({"a": 1, "b": 2})
>>> store.pop("a")
1
>>> "a" in store
False
search(key: str, print_values: bool = True) None[source]#

Search for parameters containing the given key.

Example

>>> store = ParameterStore({"Temperature [K]": 298.15, "Voltage [V]": 3.7})
>>> store.search("Temperature", print_values=False)
Results for 'Temperature': ...
set(key: str, value: Any, *, allow_new: bool = True) None[source]#

Set a parameter value.

Parameters:
  • key (str) – Parameter name.

  • value (Any) – Parameter value.

  • allow_new (bool) – If False, raises KeyError when key doesn’t exist. If True (default), allows adding new parameters.

Raises:

KeyError – If allow_new=False and the key doesn’t exist.

Example

>>> store = ParameterStore({"a": 1})
>>> store.set("a", 10)  # Update existing
>>> store.set("b", 2)   # Add new (allow_new=True by default)
to_dict() dict[str, Any][source]#

Return a plain dictionary copy of the parameters.

Example

>>> store = ParameterStore({"a": 1, "b": 2})
>>> store.to_dict()
{'a': 1, 'b': 2}
update(values: Mapping[str, Any], *, allow_new: bool = True, conflict: Literal['raise', 'warn', 'ignore'] = 'ignore') None[source]#

Bulk update parameters.

Parameters:
  • values (Mapping[str, Any]) – Dictionary of parameter values to update.

  • allow_new (bool) – If False, raises KeyError for unknown parameters. If True (default), allows adding new parameters.

  • conflict ({"raise", "warn", "ignore"}) – How to handle conflicts when a parameter already exists with a different value: - “raise”: Raise ValueError - “warn”: Emit a warning and update - “ignore”: Silently update (default)

Example

>>> store = ParameterStore({"a": 1, "b": 2})
>>> store.update({"a": 10, "c": 3})
>>> store["a"], store["c"]
(10, 3)
values()[source]#

Return parameter values.

ParameterInfo#

class pybamm.parameters.ParameterInfo(name: str, value: Any, units: str | None, category: str | None, is_function: bool, is_input: bool)[source]#

Metadata about a parameter.

name#

The parameter name (key).

Type:

str

value#

The parameter value.

Type:

Any

units#

Units parsed from the parameter name (e.g., “K” from “Temperature [K]”).

Type:

str | None

category#

Category of the parameter (e.g., “negative electrode”, “thermal”).

Type:

str | None

is_function#

True if the value is callable.

Type:

bool

is_input#

True if the value is an InputParameter.

Type:

bool

ParameterDiff#

class pybamm.parameters.ParameterDiff(added: dict[str, Any], removed: dict[str, Any], changed: dict[str, tuple[Any, Any]])[source]#

Result of comparing two parameter sets.

added#

Parameters in other but not in self.

Type:

dict[str, Any]

removed#

Parameters in self but not in other.

Type:

dict[str, Any]

changed#

Parameters with different values: (self_value, other_value).

Type:

dict[str, tuple[Any, Any]]

ParameterCategory#

class pybamm.parameters.ParameterCategory(*values)[source]#

Categories for grouping battery parameters.

Extends: enum.Enum

ELECTRICAL = 'electrical'#
ELECTROLYTE = 'electrolyte'#
GEOMETRIC = 'geometric'#
KINETIC = 'kinetic'#
NEGATIVE_ELECTRODE = 'negative electrode'#
OTHER = 'other'#
POSITIVE_ELECTRODE = 'positive electrode'#
SEPARATOR = 'separator'#
THERMAL = 'thermal'#