Skip to content

Commit

Permalink
Merge branch 'develop' into jax-bdf-refactor-bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins authored Sep 25, 2024
2 parents dfb2624 + 1390ea3 commit 48fff9a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@
"profile": "https://github.com/AbhishekChaudharii",
"contributions": [
"doc",
"code"
"code",
"test"
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- Added sensitivity calculation support for `pybamm.Simulation` and `pybamm.Experiment` ([#4415](https://github.com/pybamm-team/PyBaMM/pull/4415))
- Added OpenMP parallelization to IDAKLU solver for lists of input parameters ([#4449](https://github.com/pybamm-team/PyBaMM/pull/4449))
- Added phase-dependent particle options to LAM #4369
- Added phase-dependent particle options to LAM
([#4369](https://github.com/pybamm-team/PyBaMM/pull/4369))
- Added a lithium ion equivalent circuit model with split open circuit voltages for each electrode (`SplitOCVR`). ([#4330](https://github.com/pybamm-team/PyBaMM/pull/4330))

## Optimizations
Expand All @@ -19,6 +20,8 @@

## Breaking changes

- Removed the deprecation warning for the chemistry argument in
ParameterValues ([#4466](https://github.com/pybamm-team/PyBaMM/pull/4466))
- The parameters "... electrode OCP entropic change [V.K-1]" and "... electrode volume change" are now expected to be functions of stoichiometry only instead of functions of both stoichiometry and maximum concentration ([#4427](https://github.com/pybamm-team/PyBaMM/pull/4427))
- Renamed `set_events` function to `add_events_from` to better reflect its purpose. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421))

Expand Down
2 changes: 1 addition & 1 deletion all_contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Agnik7"><img src="https://avatars.githubusercontent.com/u/77234005?v=4?s=100" width="100px;" alt="Agnik Bakshi"/><br /><sub><b>Agnik Bakshi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=Agnik7" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RuiheLi"><img src="https://avatars.githubusercontent.com/u/84007676?v=4?s=100" width="100px;" alt="RuiheLi"/><br /><sub><b>RuiheLi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=RuiheLi" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=RuiheLi" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chmabaur"><img src="https://avatars.githubusercontent.com/u/127507466?v=4?s=100" width="100px;" alt="chmabaur"/><br /><sub><b>chmabaur</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Achmabaur" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=chmabaur" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AbhishekChaudharii"><img src="https://avatars.githubusercontent.com/u/91185083?v=4?s=100" width="100px;" alt="Abhishek Chaudhari"/><br /><sub><b>Abhishek Chaudhari</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Documentation">📖</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AbhishekChaudharii"><img src="https://avatars.githubusercontent.com/u/91185083?v=4?s=100" width="100px;" alt="Abhishek Chaudhari"/><br /><sub><b>Abhishek Chaudhari</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Documentation">📖</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/shubhambhar007"><img src="https://avatars.githubusercontent.com/u/32607282?v=4?s=100" width="100px;" alt="Shubham Bhardwaj"/><br /><sub><b>Shubham Bhardwaj</b></sub></a><br /><a href="#infra-shubhambhar007" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jlauber18"><img src="https://avatars.githubusercontent.com/u/28939653?v=4?s=100" width="100px;" alt="Jonathan Lauber"/><br /><sub><b>Jonathan Lauber</b></sub></a><br /><a href="#infra-jlauber18" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
Expand Down
16 changes: 7 additions & 9 deletions src/pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ class ParameterValues:
"""

def __init__(self, values, chemistry=None):
if chemistry is not None:
raise ValueError(
"The 'chemistry' keyword argument has been deprecated. "
"Call `ParameterValues` with a dictionary dictionary of "
"parameter values, or the name of a parameter set (string), "
"as the single argument, e.g. `ParameterValues('Chen2020')`.",
)

def __init__(self, values):
# add physical constants as default values
self._dict_items = pybamm.FuzzyDict(
{
Expand Down Expand Up @@ -930,3 +922,9 @@ def print_evaluated_parameters(self, evaluated_parameters, output_file):
file.write((s + " : {:10.4g}\n").format(name, value))
else:
file.write((s + " : {:10.3E}\n").format(name, value))

def __contains__(self, key):
return key in self._dict_items

def __iter__(self):
return iter(self._dict_items)
27 changes: 21 additions & 6 deletions tests/unit/test_parameters/test_parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from pybamm.expression_tree.exceptions import OptionError
import casadi
from pybamm.parameters.parameter_values import ParameterValues


class TestParameterValues:
Expand All @@ -36,12 +37,6 @@ def test_init(self):
param = pybamm.ParameterValues({"a": 1, "chemistry": "lithium-ion"})
assert "chemistry" not in param.keys()

# chemistry kwarg removed
with pytest.raises(
ValueError, match="'chemistry' keyword argument has been deprecated"
):
pybamm.ParameterValues(None, chemistry="lithium-ion")

# junk param values rejected
with pytest.raises(ValueError, match="'Junk' is not a valid parameter set."):
pybamm.ParameterValues("Junk")
Expand Down Expand Up @@ -1029,3 +1024,23 @@ def test_exchange_current_density_plating(self):
match="referring to the reaction at the surface of a lithium metal electrode",
):
parameter_values.evaluate(param)

def test_contains_method(self):
"""Test for __contains__ method to check the functionality of 'in' keyword"""
parameter_values = ParameterValues(
{"Negative particle radius [m]": 1e-6, "Positive particle radius [m]": 2e-6}
)
assert (
"Negative particle radius [m]" in parameter_values
), "Key should be found in parameter_values"
assert (
"Invalid key" not in parameter_values
), "Non-existent key should not be found"

def test_iter_method(self):
"""Test for __iter__ method to check if we can iterate over keys"""
parameter_values = ParameterValues(
values={"Negative particle radius [m]": 1e-6}
)
pv = [i for i in parameter_values]
assert len(pv) == 5, "Should have 5 keys"

0 comments on commit 48fff9a

Please sign in to comment.