Skip to content

Commit

Permalink
{id} in history storage filename (#1118)
Browse files Browse the repository at this point in the history
* allow {id} in history filename together with multiprocessing

* Black rework

---------

Co-authored-by: Paul Jonas Jost <70631928+PaulJonasJost@users.noreply.github.com>
Co-authored-by: PaulJonasJost <jost.pauljonas@gmail.com>
  • Loading branch information
3 people committed Oct 10, 2023
1 parent 9b0d7fd commit 33da118
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pypesto/optimize/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ def preprocess_hdf5_history(
return False

# create directory with same name as original file stem
template_path = (
path.parent / path.stem / (path.stem + "_{id}" + path.suffix)
)
if "{id}" in path.stem:
template_path = (
path.parent
/ path.stem.replace("{id}", "")
/ (path.stem + path.suffix)
)
else:
template_path = (
path.parent / path.stem / (path.stem + "_{id}" + path.suffix)
)
template_path.parent.mkdir(parents=True, exist_ok=True)
# set history file to template path
history_options.storage_file = str(template_path)
Expand Down Expand Up @@ -92,6 +99,8 @@ def postprocess_hdf5_history(
History options used in the optimization.
"""
# create hdf5 file that gathers the others within history group
if "{id}" in storage_file:
storage_file = storage_file.replace("{id}", "")
with h5py.File(storage_file, mode='w') as f:
# create file and group
f.require_group("history")
Expand Down

0 comments on commit 33da118

Please sign in to comment.