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

Use copy(deepcopy=true) for checkpointing #172

Merged
merged 6 commits into from
Aug 23, 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 @@ -2,6 +2,7 @@

## latest

* Use `copy(deepcopy=True)` when checkpointing to make checkpointing more user-friendly and secure. IMPORTANT: might increase runtime, please open an issue if you face serious problems. [#172](https://github.com/precice/fenics-adapter/pull/172)
* Add unit tests for checkpointing. [#173](https://github.com/precice/fenics-adapter/pull/173)

## 2.1.0
Expand Down
12 changes: 6 additions & 6 deletions fenicsprecice/solverstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def __init__(self, payload, t, n):
Iteration number.
"""
try:
self.payload = payload.copy()
except AttributeError: # if .copy() does not exist, it probably is a list
self.payload = [item.copy() for item in payload]
self.payload = payload.copy(deepcopy=True)
except (AttributeError, TypeError): # AttributeError, if .copy() does not exist; TypeError, if .copy(deepcopy) does not exist. -> Probably a list
self.payload = [item.copy(deepcopy=True) for item in payload]

self.t = t
self.n = n
Expand All @@ -34,9 +34,9 @@ def get_state(self):
Iteration number.
"""
try:
return self.payload.copy(), self.t, self.n
except AttributeError: # if .copy() does not exist, it probably is a list
return [item.copy() for item in self.payload], self.t, self.n
return self.payload.copy(deepcopy=True), self.t, self.n
except (AttributeError, TypeError): # AttributeError, if .copy() does not exist; TypeError, if .copy(deepcopy) does not exist. -> Probably a list
return [item.copy(deepcopy=True) for item in self.payload], self.t, self.n

def print_state(self):
payload, t, n = self.get_state()
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_fenicsprecice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def assign(self, new_value):
"""
self.value = new_value.value

def copy(self):
def copy(self, deepcopy=False):
"""
mock of dolfin.Function.copy
:param deepcopy: has no effect but we need to provide it to avoid throwing TypeError if copy(deepcopy=True) is called
"""
returned_array = MockedArray()
returned_array.value = self.value
return returned_array
Expand Down
Loading