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

{id} in history storage filename #1118

Merged
merged 7 commits into from
Oct 10, 2023
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