Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keys to ParameterSet and update ECM OCV check #388

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading