Skip to content

Commit

Permalink
Add keys to ParameterSet and update ECM OCV check (#388)
Browse files Browse the repository at this point in the history
* Add keys to ParameterSet

* Remove pybamm import from exp_UKF

* Update CHANGELOG.md

* Update standalone model
  • Loading branch information
NicolaCourtier authored Jul 4, 2024
1 parent 1fa9d36 commit b49ede4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

## Bug Fixes

- [#387](https://github.com/pybop-team/PyBOP/issues/387) - Adds keys to ParameterSet and updates ECM OCV check.
- [#380](https://github.com/pybop-team/PyBOP/pull/380) - Restore self._boundaries construction for `pybop.PSO`
- [#372](https://github.com/pybop-team/PyBOP/pull/372) - Converts `np.array` to `np.asarray` for Numpy v2.0 support.
- [#165](https://github.com/pybop-team/PyBOP/issues/165) - Stores the attempted and best parameter values and the best cost for each iteration in the log attribute of the optimiser and updates the associated plots.
Expand Down
3 changes: 1 addition & 2 deletions examples/scripts/exp_UKF.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import numpy as np
import pybamm

import pybop
from examples.standalone.model import ExponentialDecay

# Parameter set and model definition
parameter_set = pybamm.ParameterValues({"k": "[input]", "y0": "[input]"})
parameter_set = {"k": "[input]", "y0": "[input]"}
model = ExponentialDecay(parameter_set=parameter_set, n_states=1)

# Fitting parameters
Expand Down
8 changes: 5 additions & 3 deletions examples/standalone/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def __init__(
parameter_set: pybamm.ParameterValues = None,
n_states: int = 1,
):
super().__init__()
super().__init__(name=name, parameter_set=parameter_set)

self.n_states = n_states
if n_states < 1:
raise ValueError("The number of states (n_states) must be greater than 0")
Expand All @@ -38,10 +39,11 @@ def __init__(
)

self._unprocessed_model = self.pybamm_model
self.name = name

self.default_parameter_values = (
default_parameter_values if parameter_set is None else parameter_set
default_parameter_values
if self._parameter_set is None
else self._parameter_set
)
self._parameter_set = self.default_parameter_values
self._unprocessed_parameter_set = self._parameter_set
Expand Down
6 changes: 3 additions & 3 deletions pybop/models/empirical/base_ecm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def __init__(
# Correct OCP if set to default
if (
parameter_set is not None
and "Open-circuit voltage [V]" in parameter_set.params
and "Open-circuit voltage [V]" in parameter_set.keys()
):
default_ocp = self.pybamm_model.default_parameter_values[
"Open-circuit voltage [V]"
]
if parameter_set.params["Open-circuit voltage [V]"] == "default":
if parameter_set["Open-circuit voltage [V]"] == "default":
print("Setting open-circuit voltage to default function")
parameter_set.params["Open-circuit voltage [V]"] = default_ocp
parameter_set["Open-circuit voltage [V]"] = default_ocp

super().__init__(name=name, parameter_set=parameter_set)

Expand Down
5 changes: 1 addition & 4 deletions pybop/models/lithium_ion/base_echem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ def __init__(
solver=None,
**model_kwargs,
):
super().__init__(
name=name,
parameter_set=parameter_set,
)
super().__init__(name=name, parameter_set=parameter_set)

model_options = dict(build=False)
for key, value in model_kwargs.items():
Expand Down
7 changes: 7 additions & 0 deletions pybop/parameters/parameter_set.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import types
from typing import List

from pybamm import ParameterValues, parameter_sets

Expand Down Expand Up @@ -34,6 +35,12 @@ def __setitem__(self, key, value):
def __getitem__(self, key):
return self.params[key]

def keys(self) -> List:
"""
A list of parameter names
"""
return list(self.params.keys())

def import_parameters(self, json_path=None):
"""
Imports parameters from a JSON file specified by the `json_path` attribute.
Expand Down

0 comments on commit b49ede4

Please sign in to comment.