From 675fba79b32f9dbffcf248220f55ab43da8dcfd9 Mon Sep 17 00:00:00 2001
From: Polina Lakrisenko
Date: Thu, 14 Sep 2023 16:56:15 +0200
Subject: [PATCH 1/2] allow {id} in history filename together with
multiprocessing
---
pypesto/optimize/util.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/pypesto/optimize/util.py b/pypesto/optimize/util.py
index a620ae37d..3ec0b0e35 100644
--- a/pypesto/optimize/util.py
+++ b/pypesto/optimize/util.py
@@ -61,9 +61,15 @@ 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 +98,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")
From 629732c8364f7e43b3b4dfc707c61daabdaca394 Mon Sep 17 00:00:00 2001
From: PaulJonasJost
Date: Tue, 10 Oct 2023 09:26:51 -0400
Subject: [PATCH 2/2] Black rework
---
pypesto/optimize/util.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/pypesto/optimize/util.py b/pypesto/optimize/util.py
index 3ec0b0e35..4e2e86383 100644
--- a/pypesto/optimize/util.py
+++ b/pypesto/optimize/util.py
@@ -63,8 +63,9 @@ def preprocess_hdf5_history(
# create directory with same name as original file stem
if "{id}" in path.stem:
template_path = (
- path.parent / path.stem.replace("{id}", "") / (
- path.stem + path.suffix)
+ path.parent
+ / path.stem.replace("{id}", "")
+ / (path.stem + path.suffix)
)
else:
template_path = (