From 33da1189d2a954260fbc46eb269b90fb376c3fa2 Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Tue, 10 Oct 2023 16:07:26 +0200 Subject: [PATCH] {id} in history storage filename (#1118) * 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 --- pypesto/optimize/util.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pypesto/optimize/util.py b/pypesto/optimize/util.py index a620ae37d..4e2e86383 100644 --- a/pypesto/optimize/util.py +++ b/pypesto/optimize/util.py @@ -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) @@ -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")