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:
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:
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:
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
- 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:
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:
- 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)
ParameterInfo#
ParameterDiff#
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'#