Skip to content

Commit aae5155

Browse files
Update spot.py
1 parent e3d3672 commit aae5155

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

src/spotpython/spot/spot.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from spotpython.utils.compare import selectNew
3030
from spotpython.utils.aggregate import aggregate_mean_var, select_distant_points
3131
from spotpython.utils.repair import remove_nan
32-
from spotpython.utils.file import get_experiment_filename
32+
from spotpython.utils.file import get_experiment_filename, get_result_filename
3333
from spotpython.budget.ocba import get_ocba_X
3434
import logging
3535
import time
@@ -1062,9 +1062,43 @@ def write_tensorboard_log(self) -> None:
10621062
self.spot_writer.add_hparams(config, {"hp_metric": y_j})
10631063
self.spot_writer.flush()
10641064

1065+
def save_results(self, filename=None, path=None, overwrite=True, verbosity=0) -> None:
1066+
"""
1067+
Save the results to a file.
1068+
If filename is not provided, the filename is generated based on the PREFIX using the
1069+
`get_result_filename()` function. The results file is saved in the current working directory
1070+
unless a path is provided. The file is saved in pickle format using the highest protocol.
1071+
If no arguments are provided, the file is saved with the default name PREFIX + "_res.pkl".
1072+
1073+
Args:
1074+
filename (str):
1075+
The filename of the results file. If not provided,
1076+
the filename is generated based on the PREFIX using the
1077+
`get_result_filename()` function. Default is `None`.
1078+
path (str):
1079+
The path to the results file. If not provided, the file
1080+
is saved in the current working directory. Default is `None`.
1081+
overwrite (bool):
1082+
If `True`, the file will be overwritten if it already exists.
1083+
Default is `True`.
1084+
verbosity (int):
1085+
The level of verbosity. Default is 0.
1086+
1087+
Returns:
1088+
None
1089+
"""
1090+
PREFIX = self.fun_control.get("PREFIX", "result")
1091+
if filename is None:
1092+
filename = get_result_filename(PREFIX)
1093+
self.save_experiment(self, filename=filename, path=None, overwrite=True, unpickleables="file_io", verbosity=0)
1094+
10651095
def save_experiment(self, filename=None, path=None, overwrite=True, unpickleables="file_io", verbosity=0) -> None:
10661096
"""
10671097
Save the experiment to a file.
1098+
If no filename is provided, the filename is generated based on the PREFIX using the
1099+
`get_experiment_filename()` function. The experiment file is saved in the current working directory
1100+
unless a path is provided. The file is saved in pickle format using the highest protocol.
1101+
If no arguments are provided, the file is saved with the default name PREFIX + "_exp.pkl".
10681102
10691103
Args:
10701104
filename (str):

0 commit comments

Comments
 (0)