Skip to content

Commit 6482831

Browse files
0.21.7
BUGS in test
1 parent bfcc98d commit 6482831

7 files changed

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

src/spotpython/data/lightdatamodule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _setup_full_data_provided(self, stage) -> None:
171171
self.data_predict, _, _ = random_split(self.data_full, [test_size, train_size, val_size], generator=generator_predict)
172172
if self.verbosity > 0:
173173
print(f"train_size: {train_size}, val_size: {val_size}, test_size (= predict_size): {test_size} for splitting predict data.")
174-
print(f"predict samples: {len(self.data_predict)} generated for train & val data.")
174+
print(f"predict samples: {len(self.data_predict)} generated for predict data.")
175175
if self.scaler is not None:
176176
# Transform the predict data
177177
self.data_predict = self.transform_dataset(self.data_predict)

src/spotpython/light/cvmodel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def cv_model(config: dict, fun_control: dict) -> float:
6464
dataset=fun_control["data_set"],
6565
data_full_train=fun_control["data_full_train"],
6666
data_test=fun_control["data_test"],
67+
data_val=fun_control["data_val"],
6768
num_workers=fun_control["num_workers"],
6869
batch_size=config["batch_size"],
6970
data_dir=fun_control["DATASET_PATH"],

src/spotpython/light/predictmodel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def predict_model(config: dict, fun_control: dict) -> Tuple[float, float]:
7070
dataset=fun_control["data_set"],
7171
data_full_train=fun_control["data_full_train"],
7272
data_test=fun_control["data_test"],
73+
data_val=fun_control["data_val"],
7374
batch_size=config["batch_size"],
7475
num_workers=fun_control["num_workers"],
7576
test_size=fun_control["test_size"],

src/spotpython/light/testmodel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_model(config: dict, fun_control: dict) -> Tuple[float, float]:
7070
dataset=fun_control["data_set"],
7171
data_full_train=fun_control["data_full_train"],
7272
data_test=fun_control["data_test"],
73+
data_val=fun_control["data_val"],
7374
batch_size=config["batch_size"],
7475
num_workers=fun_control["num_workers"],
7576
test_size=fun_control["test_size"],

src/spotpython/light/trainmodel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def train_model(config: dict, fun_control: dict, timestamp: bool = True) -> floa
110110
dataset=fun_control["data_set"],
111111
data_full_train=fun_control["data_full_train"],
112112
data_test=fun_control["data_test"],
113+
data_val=fun_control["data_val"],
113114
batch_size=config["batch_size"],
114115
num_workers=fun_control["num_workers"],
115116
test_size=fun_control["test_size"],

src/spotpython/spot/spot.py

Lines changed: 80 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ def __init__(
263263
matplotlib.use("TkAgg")
264264
self.verbosity = self.fun_control["verbosity"]
265265

266-
# Tensorboard:
267-
self.init_spot_writer()
266+
# # Tensorboard:
267+
# self.init_spot_writer()
268268

269269
# Bounds are internal, because they are functions of self.lower and self.upper
270270
# and used by the optimizer:
@@ -316,31 +316,31 @@ def __init__(
316316
if self.surrogate_control["n_theta"] > 1:
317317
surrogate_control.update({"n_theta": self.k})
318318

319-
# If no surrogate model is specified, use the internal
320-
# spotpython kriging surrogate:
321-
if self.surrogate is None:
322-
# Call kriging with surrogate_control parameters:
323-
self.surrogate = Kriging(
324-
name="kriging",
325-
noise=self.surrogate_control["noise"],
326-
model_optimizer=self.surrogate_control["model_optimizer"],
327-
model_fun_evals=self.surrogate_control["model_fun_evals"],
328-
seed=self.surrogate_control["seed"],
329-
log_level=self.log_level,
330-
min_theta=self.surrogate_control["min_theta"],
331-
max_theta=self.surrogate_control["max_theta"],
332-
metric_factorial=self.surrogate_control["metric_factorial"],
333-
n_theta=self.surrogate_control["n_theta"],
334-
theta_init_zero=self.surrogate_control["theta_init_zero"],
335-
p_val=self.surrogate_control["p_val"],
336-
n_p=self.surrogate_control["n_p"],
337-
optim_p=self.surrogate_control["optim_p"],
338-
min_Lambda=self.surrogate_control["min_Lambda"],
339-
max_Lambda=self.surrogate_control["max_Lambda"],
340-
var_type=self.surrogate_control["var_type"],
341-
spot_writer=self.spot_writer,
342-
counter=self.design_control["init_size"] * self.design_control["repeats"] - 1,
343-
)
319+
# # If no surrogate model is specified, use the internal
320+
# # spotpython kriging surrogate:
321+
# if self.surrogate is None:
322+
# # Call kriging with surrogate_control parameters:
323+
# self.surrogate = Kriging(
324+
# name="kriging",
325+
# noise=self.surrogate_control["noise"],
326+
# model_optimizer=self.surrogate_control["model_optimizer"],
327+
# model_fun_evals=self.surrogate_control["model_fun_evals"],
328+
# seed=self.surrogate_control["seed"],
329+
# log_level=self.log_level,
330+
# min_theta=self.surrogate_control["min_theta"],
331+
# max_theta=self.surrogate_control["max_theta"],
332+
# metric_factorial=self.surrogate_control["metric_factorial"],
333+
# n_theta=self.surrogate_control["n_theta"],
334+
# theta_init_zero=self.surrogate_control["theta_init_zero"],
335+
# p_val=self.surrogate_control["p_val"],
336+
# n_p=self.surrogate_control["n_p"],
337+
# optim_p=self.surrogate_control["optim_p"],
338+
# min_Lambda=self.surrogate_control["min_Lambda"],
339+
# max_Lambda=self.surrogate_control["max_Lambda"],
340+
# var_type=self.surrogate_control["var_type"],
341+
# spot_writer=self.spot_writer,
342+
# counter=self.design_control["init_size"] * self.design_control["repeats"] - 1,
343+
# )
344344

345345
# Internal attributes:
346346
self.X = None
@@ -791,6 +791,35 @@ def run(self, X_start: np.ndarray = None) -> Spot:
791791
3.7179535332164810e-04])
792792
793793
"""
794+
# Tensorboard:
795+
self.init_spot_writer()
796+
797+
# If no surrogate model is specified, use the internal
798+
# spotpython kriging surrogate:
799+
if self.surrogate is None:
800+
# Call kriging with surrogate_control parameters:
801+
self.surrogate = Kriging(
802+
name="kriging",
803+
noise=self.surrogate_control["noise"],
804+
model_optimizer=self.surrogate_control["model_optimizer"],
805+
model_fun_evals=self.surrogate_control["model_fun_evals"],
806+
seed=self.surrogate_control["seed"],
807+
log_level=self.log_level,
808+
min_theta=self.surrogate_control["min_theta"],
809+
max_theta=self.surrogate_control["max_theta"],
810+
metric_factorial=self.surrogate_control["metric_factorial"],
811+
n_theta=self.surrogate_control["n_theta"],
812+
theta_init_zero=self.surrogate_control["theta_init_zero"],
813+
p_val=self.surrogate_control["p_val"],
814+
n_p=self.surrogate_control["n_p"],
815+
optim_p=self.surrogate_control["optim_p"],
816+
min_Lambda=self.surrogate_control["min_Lambda"],
817+
max_Lambda=self.surrogate_control["max_Lambda"],
818+
var_type=self.surrogate_control["var_type"],
819+
spot_writer=self.spot_writer,
820+
counter=self.design_control["init_size"] * self.design_control["repeats"] - 1,
821+
)
822+
794823
self.initialize_design(X_start)
795824
self.update_stats()
796825
self.fit_surrogate()
@@ -801,6 +830,7 @@ def run(self, X_start: np.ndarray = None) -> Spot:
801830
self.update_writer()
802831
self.fit_surrogate()
803832
self.show_progress_if_needed(timeout_start)
833+
804834
if hasattr(self, "spot_writer") and self.spot_writer is not None:
805835
self.spot_writer.flush()
806836
self.spot_writer.close()
@@ -1052,7 +1082,7 @@ def write_tensorboard_log(self) -> None:
10521082
self.spot_writer.add_hparams(config, {"hp_metric": y_j})
10531083
self.spot_writer.flush()
10541084

1055-
def save_experiment(self, filename=None, path=None, overwrite=True, verbosity=0) -> None:
1085+
def save_experiment(self, filename=None, path=None, overwrite=True, unpickleables="file_io", verbosity=0) -> None:
10561086
"""
10571087
Save the experiment to a file.
10581088
@@ -1067,6 +1097,12 @@ def save_experiment(self, filename=None, path=None, overwrite=True, verbosity=0)
10671097
overwrite (bool):
10681098
If `True`, the file will be overwritten if it already exists.
10691099
Default is `True`.
1100+
unpickleables (str):
1101+
The type of unpickleable components to exclude. Default is "file_io", which
1102+
excludes file I/O components like the spot_writer and logger.
1103+
If set to any other value, the function will exclude the function, optimizer,
1104+
surrogate, data_set, scaler, rng, and design components.
1105+
Default is "file_io".
10701106
verbosity (int):
10711107
The level of verbosity. Default is 0.
10721108
@@ -1088,7 +1124,7 @@ def save_experiment(self, filename=None, path=None, overwrite=True, verbosity=0)
10881124
"design_control": design_control,
10891125
"fun_control": fun_control,
10901126
"optimizer_control": optimizer_control,
1091-
"spot_tuner": self._get_pickle_safe_spot_tuner(verbosity=verbosity),
1127+
"spot_tuner": self._get_pickle_safe_spot_tuner(unpickleables=unpickleables, verbosity=verbosity),
10921128
"surrogate_control": surrogate_control,
10931129
}
10941130

@@ -1135,21 +1171,29 @@ def _close_and_del_spot_writer(self) -> None:
11351171
self.spot_writer.close()
11361172
del self.spot_writer
11371173

1138-
def _get_pickle_safe_spot_tuner(self, verbosity=0) -> Spot:
1174+
def _get_pickle_safe_spot_tuner(self, unpickleables="file_io", verbosity=0) -> Spot:
11391175
"""
11401176
Create a copy of self excluding unpickleable components for safe pickling.
11411177
This ensures no unpicklable components are passed to pickle.dump().
11421178
11431179
Args:
1180+
unpickleables (str):
1181+
The type of unpickleable components to exclude. Default is "file_io", which
1182+
excludes file I/O components like the spot_writer and logger.
1183+
If set to any other value, the function will exclude the function, optimizer,
1184+
surrogate, data_set, scaler, rng, and design components.
1185+
Default is "file_io".
11441186
verbosity (int):
11451187
The level of verbosity. Default is 0.
11461188
11471189
Returns:
11481190
Spot: A copy of the Spot instance with unpickleable components removed.
11491191
"""
11501192
# List of attributes that can't be pickled
1151-
unpickleable_attrs = ["spot_writer", "logger", "fun", "optimizer", "surrogate", "data_set", "scaler", "rng", "design"]
1152-
1193+
if unpickleables == "file_io":
1194+
unpickleable_attrs = ["spot_writer", "logger"]
1195+
else:
1196+
unpickleable_attrs = ["spot_writer", "logger", "fun", "optimizer", "surrogate", "data_set", "scaler", "rng", "design"]
11531197
# Prepare a dictionary to store picklable state
11541198
picklable_state = {}
11551199

@@ -1184,8 +1228,12 @@ def init_spot_writer(self) -> None:
11841228
"""
11851229
if self.fun_control["tensorboard_log"] and self.fun_control["spot_tensorboard_path"] is not None:
11861230
self.spot_writer = SummaryWriter(log_dir=self.fun_control["spot_tensorboard_path"])
1231+
if self.verbosity > 0:
1232+
print(f"Created spot_tensorboard_path: {self.fun_control['spot_tensorboard_path']} for SummaryWriter()")
11871233
else:
11881234
self.spot_writer = None
1235+
if self.verbosity > 0:
1236+
print("No tensorboard log created.")
11891237

11901238
def should_continue(self, timeout_start) -> bool:
11911239
return (self.counter < self.fun_evals) and (time.time() < timeout_start + self.max_time * 60)

0 commit comments

Comments
 (0)