Skip to content

Commit

Permalink
Merge pull request #2 from michellab/bugfix_avoid_reading_incomplete_pkl
Browse files Browse the repository at this point in the history
Avoid pickling simulation runners before complete initialisation
  • Loading branch information
fjclark authored Jul 4, 2024
2 parents d1f8937 + 4a1493d commit 76916ef
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion a3fe/run/_simulation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
dg_multiplier: int = 1,
ensemble_size: int = 5,
update_paths: bool = True,
dump: bool = True,
) -> None:
"""
base_dir : str, Optional, default: None
Expand All @@ -80,6 +81,8 @@ def __init__(
update_paths: bool, Optional, default: True
If True, if the simulation runner is loaded by unpickling, then
update_paths() is called.
dump: bool, Optional, default: True
If True, the state of the simulation runner is saved to a pickle file.
"""
# Set up the directories (which may be overwritten if the
# simulation runner is subsequently loaded from a pickle file)
Expand Down Expand Up @@ -140,7 +143,8 @@ def __init__(
self._set_up_logging()

# Save state
self._dump()
if dump:
self._dump()

def _set_up_logging(self, null: bool = False) -> None:
"""
Expand Down
1 change: 1 addition & 0 deletions a3fe/run/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(
stream_log_level=stream_log_level,
ensemble_size=ensemble_size,
update_paths=update_paths,
dump=False,
)

if not self.loaded_from_pickle:
Expand Down
1 change: 1 addition & 0 deletions a3fe/run/lambda_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(
stream_log_level=stream_log_level,
ensemble_size=ensemble_size,
update_paths=update_paths,
dump=False,
)

if not self.loaded_from_pickle:
Expand Down
1 change: 1 addition & 0 deletions a3fe/run/leg.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __init__(
stream_log_level=stream_log_level,
ensemble_size=ensemble_size,
update_paths=update_paths,
dump=False,
)

if not self.loaded_from_pickle:
Expand Down
1 change: 1 addition & 0 deletions a3fe/run/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(
output_dir=output_dir,
stream_log_level=stream_log_level,
update_paths=update_paths,
dump=False,
)

if not self.loaded_from_pickle:
Expand Down
1 change: 1 addition & 0 deletions a3fe/run/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def __init__(
stream_log_level=stream_log_level,
ensemble_size=ensemble_size,
update_paths=update_paths,
dump=False,
)

if not self.loaded_from_pickle:
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Change Log
===============

v0.1.1

- Ensured that ``simulation_runner`` objects only get pickled once they've been fully initialised. This avoids issues where an error occurs during initialisation and the object is pickled in an incomplete state. Addresses https://github.com/michellab/a3fe/issues/1.

v0.1.0
====================

Expand Down

0 comments on commit 76916ef

Please sign in to comment.