Skip to content

Commit

Permalink
Use copy(deepcopy=true) for checkpointing (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminRodenberg authored Aug 23, 2024
1 parent b04e6c9 commit 8716694
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
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

0 comments on commit 8716694

Please sign in to comment.