Skip to content

Commit e1bc738

Browse files
0.14.25
1 parent de7e8aa commit e1bc738

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.14.24"
10+
version = "0.14.25"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotPython/utils/file.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def get_experiment_filename(PREFIX):
9292
def load_experiment(PKL_NAME):
9393
"""
9494
Loads the experiment from a pickle file.
95+
If the spot tuner object and the fun control dictionary do not exist, an error is thrown.
96+
If the design control, surrogate control, and optimizer control dictionaries do not exist, a warning is issued
97+
and `None` is assigned to the corresponding variables.
9598
9699
Args:
97100
PKL_NAME (str): Name of the pickle file.
@@ -109,11 +112,32 @@ def load_experiment(PKL_NAME):
109112
"""
110113
with open(PKL_NAME, "rb") as handle:
111114
experiment = pickle.load(handle)
115+
# assign spot_tuner and fun_control only if they exist otherwise throw an error
116+
if "spot_tuner" not in experiment:
117+
raise ValueError("The spot tuner object does not exist in the pickle file.")
118+
if "fun_control" not in experiment:
119+
raise ValueError("The fun control dictionary does not exist in the pickle file.")
112120
spot_tuner = experiment["spot_tuner"]
113121
fun_control = experiment["fun_control"]
114-
design_control = experiment["design_control"]
115-
surrogate_control = experiment["surrogate_control"]
116-
optimizer_control = experiment["optimizer_control"]
122+
# assign the rest of the dictionaries if they exist otherwise assign None
123+
if "design_control" not in experiment:
124+
design_control = None
125+
# issue a warning
126+
print("The design control dictionary does not exist in the pickle file. Returning None.")
127+
else:
128+
design_control = experiment["design_control"]
129+
if "surrogate_control" not in experiment:
130+
surrogate_control = None
131+
# issue a warning
132+
print("The surrogate control dictionary does not exist in the pickle file. Returning None.")
133+
else:
134+
surrogate_control = experiment["surrogate_control"]
135+
if "optimizer_control" not in experiment:
136+
# issue a warning
137+
print("The optimizer control dictionary does not exist in the pickle file. Returning None.")
138+
optimizer_control = None
139+
else:
140+
optimizer_control = experiment["optimizer_control"]
117141
return spot_tuner, fun_control, design_control, surrogate_control, optimizer_control
118142

119143

0 commit comments

Comments
 (0)