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 _from_json functionality for pybamm.sign #4517

Merged
merged 4 commits into from
Oct 15, 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 @@ -21,6 +21,7 @@

## Bug Fixes

- Added `_from_json()` functionality to `Sign` which was erroneously omitted previously. ([#4517](https://github.com/pybamm-team/PyBaMM/pull/4517))
- Fixed bug where IDAKLU solver failed when `output variables` were specified and an extrapolation event is present. ([#4440](https://github.com/pybamm-team/PyBaMM/pull/4440))

## Breaking changes
Expand Down
3 changes: 2 additions & 1 deletion src/pybamm/expression_tree/unary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def __init__(self, child):

@classmethod
def _from_json(cls, snippet: dict):
raise NotImplementedError()
"""See :meth:`pybamm.UnaryOperator._from_json()`."""
return cls(snippet["children"][0])

def diff(self, variable):
"""See :meth:`pybamm.Symbol.diff()`."""
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/test_expression_tree/test_unary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,20 @@ def test_sign(self):
)

# Test from_json
with pytest.raises(NotImplementedError):
# signs are always scalar/array types in a discretised model
pybamm.Sign._from_json({})
c = pybamm.Multiplication(pybamm.Variable("a"), pybamm.Scalar(3))
sign_json = {
"name": "sign",
"id": 5341515228900508018,
"domains": {
"primary": [],
"secondary": [],
"tertiary": [],
"quaternary": [],
},
"children": [c],
}

assert pybamm.sign(c) == pybamm.Sign._from_json(sign_json)

def test_floor(self, mocker):
a = pybamm.Symbol("a")
Expand Down
Loading