Skip to content

Commit 684343b

Browse files
0.22.5
new: get res filename
1 parent dcdf40b commit 684343b

2 files changed

Lines changed: 31 additions & 6 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.22.4"
10+
version = "0.22.5"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/utils/file.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def load_pickle(filename: str):
7171

7272

7373
def get_experiment_filename(PREFIX) -> str:
74-
"""Returns the name of the experiment.
75-
This is the PREFIX with the suffix ".pkl".
74+
"""Returns the name of the experiment file.
75+
This is the PREFIX with the suffix "_exp.pkl".
7676
It is none, if PREFIX is None.
7777
7878
Args:
@@ -91,7 +91,32 @@ def get_experiment_filename(PREFIX) -> str:
9191
if PREFIX is None:
9292
return None
9393
else:
94-
filename = PREFIX + ".pkl"
94+
filename = PREFIX + "_exp.pkl"
95+
return filename
96+
97+
98+
def get_result_filename(PREFIX) -> str:
99+
"""Returns the name of the result file.
100+
This is the PREFIX with the suffix "_res.pkl".
101+
It is none, if PREFIX is None.
102+
103+
Args:
104+
PREFIX (str): Prefix of the experiment.
105+
106+
Returns:
107+
filename (str): Name of the experiment.
108+
109+
Examples:
110+
>>> from spotpython.utils.file import get_experiment_name
111+
>>> from spotpython.utils.init import fun_control_init
112+
>>> fun_control = fun_control_init(PREFIX="branin")
113+
>>> PREFIX = fun_control["PREFIX"]
114+
>>> filename = get_experiment_filename(PREFIX)
115+
"""
116+
if PREFIX is None:
117+
return None
118+
else:
119+
filename = PREFIX + "_res.pkl"
95120
return filename
96121

97122

@@ -115,8 +140,8 @@ def load_result(PREFIX) -> tuple:
115140
"""
116141
if PREFIX is None:
117142
raise ValueError("No PREFIX provided.")
118-
PKL_NAME = PREFIX + "_res.pkl"
119-
spot_tuner, fun_control, design_control, surrogate_control, optimizer_control = load_experiment(PKL_NAME=PKL_NAME)
143+
filename = get_result_filename(PREFIX)
144+
spot_tuner, fun_control, design_control, surrogate_control, optimizer_control = load_experiment(PKL_NAME=filename)
120145
return spot_tuner, fun_control, design_control, surrogate_control, optimizer_control
121146

122147

0 commit comments

Comments
 (0)