|
29 | 29 | from spotpython.utils.compare import selectNew |
30 | 30 | from spotpython.utils.aggregate import aggregate_mean_var, select_distant_points |
31 | 31 | 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 |
33 | 33 | from spotpython.budget.ocba import get_ocba_X |
34 | 34 | import logging |
35 | 35 | import time |
@@ -1062,9 +1062,43 @@ def write_tensorboard_log(self) -> None: |
1062 | 1062 | self.spot_writer.add_hparams(config, {"hp_metric": y_j}) |
1063 | 1063 | self.spot_writer.flush() |
1064 | 1064 |
|
| 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 | + |
1065 | 1095 | def save_experiment(self, filename=None, path=None, overwrite=True, unpickleables="file_io", verbosity=0) -> None: |
1066 | 1096 | """ |
1067 | 1097 | 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". |
1068 | 1102 |
|
1069 | 1103 | Args: |
1070 | 1104 | filename (str): |
|
0 commit comments