Skip to content

Commit e3d3672

Browse files
0.22.6
PKL_NAME -> filename
1 parent 684343b commit e3d3672

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

notebooks/00_spotMinimal.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"outputs": [],
7676
"source": [
7777
"PREFIX=\"RELEVANTE_AERO_VARIABLEN_3551a_04a\" # Prefix unbedingt ändern!\n",
78-
"DATA_PKL_NAME = \"RELEVANTE_AERO_VARIABLEN_DATA.pickle\"\n",
78+
"DATA_filename = \"RELEVANTE_AERO_VARIABLEN_DATA.pickle\"\n",
7979
"MAX_TIME = 300\n",
8080
"FUN_EVALS = inf\n",
8181
"FUN_REPEATS = 2\n",
@@ -132,7 +132,7 @@
132132
"metadata": {},
133133
"outputs": [],
134134
"source": [
135-
"filename = DATA_PKL_NAME\n",
135+
"filename = DATA_filename\n",
136136
"dataset = loadFeaturesFromPkl(param_list=param_list, filename=filename, return_X_y=False)"
137137
]
138138
},
@@ -212,7 +212,7 @@
212212
" surrogate_control=surrogate_control)\n",
213213
"spot_tuner.run()\n",
214214
"\n",
215-
"SPOT_PKL_NAME = save_experiment(spot_tuner, fun_control)\n",
215+
"SPOT_filename = save_experiment(spot_tuner, fun_control)\n",
216216
"\n",
217217
"# tensorboard --logdir=\"runs/\""
218218
]
@@ -301,7 +301,7 @@
301301
"# Prefix unbedingt anpassen, wenn ein altes Experiment geladen wird!\n",
302302
"# Ansonsten wird das oben für das Tuning erstellte PREFIX verwendet.\n",
303303
"# PREFIX=\"033allbartz09d\" \n",
304-
"spot_tuner, fun_control = load_experiment(SPOT_PKL_NAME)"
304+
"spot_tuner, fun_control = load_experiment(SPOT_filename)"
305305
]
306306
},
307307
{

notebooks/00_spotPython_tests.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,7 +3119,7 @@
31193119
" surrogate_control=surrogate_control,\n",
31203120
" optimizer_control=optimizer_control)\n",
31213121
" # Call the save_experiment function\n",
3122-
" pkl_name = save_experiment(\n",
3122+
" filename = save_experiment(\n",
31233123
" spot_tuner=spot_tuner,\n",
31243124
" fun_control=fun_control,\n",
31253125
" design_control=None,\n",
@@ -3128,16 +3128,16 @@
31283128
" )\n",
31293129
"\n",
31303130
" # Verify that the pickle file is created\n",
3131-
" assert os.path.exists(pkl_name)\n",
3131+
" assert os.path.exists(filename)\n",
31323132
"\n",
31333133
" # Call the load_experiment function\n",
3134-
" spot_tuner_1, fun_control_1, design_control_1, surrogate_control_1, optimizer_control_1 = load_experiment(pkl_name)\n",
3134+
" spot_tuner_1, fun_control_1, design_control_1, surrogate_control_1, optimizer_control_1 = load_experiment(filename)\n",
31353135
"\n",
31363136
" # Verify the name of the pickle file\n",
3137-
" assert pkl_name == f\"spot_{fun_control['PREFIX']}experiment.pickle\"\n",
3137+
" assert filename == f\"spot_{fun_control['PREFIX']}experiment.pickle\"\n",
31383138
"\n",
31393139
" # Clean up the temporary directory\n",
3140-
" os.remove(pkl_name)\n"
3140+
" os.remove(filename)\n"
31413141
]
31423142
},
31433143
{

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.5"
10+
version = "0.22.6"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/utils/file.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ def load_result(PREFIX) -> tuple:
141141
if PREFIX is None:
142142
raise ValueError("No PREFIX provided.")
143143
filename = get_result_filename(PREFIX)
144-
spot_tuner, fun_control, design_control, surrogate_control, optimizer_control = load_experiment(PKL_NAME=filename)
144+
spot_tuner, fun_control, design_control, surrogate_control, optimizer_control = load_experiment(filename=filename)
145145
return spot_tuner, fun_control, design_control, surrogate_control, optimizer_control
146146

147147

148-
def load_experiment(PREFIX=None, PKL_NAME=None):
148+
def load_experiment(PREFIX=None, filename=None):
149149
"""
150150
Loads the experiment from a pickle file.
151-
If PKL_NAME is None and PREFIX is not None, the experiment is loaded based on the PREFIX
151+
If filename is None and PREFIX is not None, the experiment is loaded based on the PREFIX
152152
using the get_experiment_filename function.
153153
If the spot tuner object and the fun control dictionary do not exist, an error is thrown.
154154
If the design control, surrogate control, and optimizer control dictionaries do not exist, a warning is issued
155155
and `None` is assigned to the corresponding variables.
156156
157157
Args:
158158
PREFIX (str, optional): Prefix of the experiment. Defaults to None.
159-
PKL_NAME (str): Name of the pickle file. Defaults to None.
159+
filename (str): Name of the pickle file. Defaults to None.
160160
161161
Returns:
162162
spot_tuner (object): The spot tuner object.
@@ -170,14 +170,14 @@ def load_experiment(PREFIX=None, PKL_NAME=None):
170170
171171
Examples:
172172
>>> from spotpython.utils.file import load_experiment
173-
>>> spot_tuner, fun_control, design_control, _, _ = load_experiment(PKL_NAME="RUN_0.pkl")
173+
>>> spot_tuner, fun_control, design_control, _, _ = load_experiment(filename="RUN_0.pkl")
174174
175175
"""
176-
if PKL_NAME is None and PREFIX is not None:
177-
PKL_NAME = get_experiment_filename(PREFIX)
178-
with open(PKL_NAME, "rb") as handle:
176+
if filename is None and PREFIX is not None:
177+
filename = get_experiment_filename(PREFIX)
178+
with open(filename, "rb") as handle:
179179
experiment = pickle.load(handle)
180-
print(f"Loaded experiment from {PKL_NAME}")
180+
print(f"Loaded experiment from {filename}")
181181
# assign spot_tuner and fun_control only if they exist otherwise throw an error
182182
if "spot_tuner" not in experiment:
183183
raise ValueError("The spot tuner object does not exist in the pickle file.")
@@ -283,11 +283,11 @@ def get_experiment_from_PREFIX(PREFIX, return_dict=True) -> dict:
283283
return config, fun_control, design_control, surrogate_control, optimizer_control
284284

285285

286-
def load_and_run_spot_python_experiment(spot_pkl_name) -> tuple:
286+
def load_and_run_spot_python_experiment(spot_filename) -> tuple:
287287
"""Loads and runs a spot experiment.
288288
289289
Args:
290-
spot_pkl_name (str):
290+
spot_filename (str):
291291
The name of the spot experiment file.
292292
293293
Returns:
@@ -305,7 +305,7 @@ def load_and_run_spot_python_experiment(spot_pkl_name) -> tuple:
305305
306306
"""
307307
p_open = None
308-
(spot_tuner, fun_control, design_control, surrogate_control, optimizer_control) = load_experiment(spot_pkl_name)
308+
(spot_tuner, fun_control, design_control, surrogate_control, optimizer_control) = load_experiment(spot_filename)
309309
print("\nLoaded fun_control in spotRun():")
310310
# pprint.pprint(fun_control)
311311
print(gen_design_table(fun_control))

test/test_load_experiment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_save_and_load_experiment(tmp_path):
5858
assert os.path.exists(filepath), f"File {filepath} should exist."
5959

6060
# Load the experiment
61-
spot_tuner, loaded_fun_control, loaded_design_control, loaded_surrogate_control, loaded_optimizer_control = load_experiment(PKL_NAME=filepath)
61+
spot_tuner, loaded_fun_control, loaded_design_control, loaded_surrogate_control, loaded_optimizer_control = load_experiment(filename=filepath)
6262

6363
# Check if the loaded data matches the original data
6464
assert compare_dicts(loaded_fun_control, fun_control), "Loaded fun_control should match the original fun_control."

0 commit comments

Comments
 (0)