file
get_experiment_filename(PREFIX)
¶
Returns the name of the experiment file. This is the PREFIX with the suffix “_exp.pkl”. It is none, if PREFIX is None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PREFIX |
str
|
Prefix of the experiment. |
required |
Returns:
Name | Type | Description |
---|---|---|
filename |
str
|
Name of the experiment. |
Examples:
>>> from spotpython.utils.file import get_experiment_name
>>> from spotpython.utils.init import fun_control_init
>>> fun_control = fun_control_init(PREFIX="branin")
>>> PREFIX = fun_control["PREFIX"]
>>> filename = get_experiment_filename(PREFIX)
Source code in spotpython/utils/file.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
get_result_filename(PREFIX)
¶
Returns the name of the result file. This is the PREFIX with the suffix “_res.pkl”. It is none, if PREFIX is None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PREFIX |
str
|
Prefix of the experiment. |
required |
Returns:
Name | Type | Description |
---|---|---|
filename |
str
|
Name of the experiment. |
Examples:
>>> from spotpython.utils.file import get_experiment_name
>>> from spotpython.utils.init import fun_control_init
>>> fun_control = fun_control_init(PREFIX="branin")
>>> PREFIX = fun_control["PREFIX"]
>>> filename = get_experiment_filename(PREFIX)
Source code in spotpython/utils/file.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
load_and_run_spot_python_experiment(PREFIX=None, filename=None)
¶
Loads and runs a spot experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PREFIX |
str
|
Prefix of the experiment. Defaults to None. |
None
|
filename |
str
|
Name of the pickle file. Defaults to None |
None
|
Returns:
Name | Type | Description |
---|---|---|
spot_tuner |
Spot
|
The spot tuner object. |
Examples:
>>> from spotpython.utils.file import load_and_run_spot_python_experiment
>>> spot_tuner = load_and_run_spot_python_experiment(filename="spot_branin_experiment.pickle")
>>> # Or use PREFIX
>>> spot_tuner = load_and_run_spot_python_experiment(PREFIX="spot_branin_experiment")
Source code in spotpython/utils/file.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
load_cifar10_data(data_dir='./data')
¶
Loads the CIFAR10 dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir |
str
|
Directory to save the data. Defaults to “./data”. |
'./data'
|
Returns:
Name | Type | Description |
---|---|---|
trainset |
CIFAR10
|
Training dataset. |
Examples:
>>> from spotpython.utils.file import load_cifar10_data
>>> trainset = load_cifar10_data(data_dir="./data")
Source code in spotpython/utils/file.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
load_core_model_from_file(coremodel, dirname='userModel')
¶
Loads a core model from a python file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coremodel |
str
|
Name of the core model. |
required |
dirname |
str
|
Directory name. Defaults to “userModel”. |
'userModel'
|
Returns:
Name | Type | Description |
---|---|---|
coremodel |
object
|
Core model. |
Source code in spotpython/utils/file.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
load_dict_from_file(coremodel, dirname='userModel')
¶
Loads a dictionary from a json file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coremodel |
str
|
Name of the core model. |
required |
dirname |
str
|
Directory name. Defaults to “userModel”. |
'userModel'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Dictionary with the core model. |
Source code in spotpython/utils/file.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
load_experiment(PREFIX=None, filename=None)
¶
Loads the experiment from a pickle file.
If filename is None and PREFIX is not None, the experiment is loaded based on the PREFIX
using the get_experiment_filename function.
If the spot tuner object and the fun control dictionary do not exist, an error is thrown.
If the design control, surrogate control, and optimizer control dictionaries do not exist, a warning is issued
and None
is assigned to the corresponding variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PREFIX |
str
|
Prefix of the experiment. Defaults to None. |
None
|
filename |
str
|
Name of the pickle file. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
spot_tuner |
Spot
|
The spot tuner object. |
Notes
The corresponding save_experiment function is part of the class spot.
Examples:
>>> from spotpython.utils.file import load_experiment
>>> spot_tuner, fun_control, design_control, _, _ = load_experiment(filename="RUN_0.pkl")
Source code in spotpython/utils/file.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
load_pickle(filename)
¶
Loads a pickle file. Add .pkl to the filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Name of the pickle file. |
required |
Returns:
Type | Description |
---|---|
object
|
Loaded object. |
Examples:
>>> from spotpython.utils.file import load_pickle
>>> obj = load_pickle(filename="obj.pkl")
Source code in spotpython/utils/file.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
load_result(PREFIX=None, filename=None)
¶
Loads the result from a pickle file with the name
PREFIX + “_res.pkl”.
This is the standard filename for the result file,
when it is saved by the spot tuner using save_result()
, i.e.,
when fun_control[“save_result”] is set to True.
If a filename is provided, the result is loaded from this file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PREFIX |
str
|
Prefix of the experiment. Defaults to None. |
None
|
filename |
str
|
Name of the pickle file. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
spot_tuner |
Spot
|
The spot tuner object. |
Notes
The corresponding save_result function is part of the class spot.
Examples:
>>> from spotpython.utils.file import load_result
>>> load_result("branin")
Source code in spotpython/utils/file.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
save_pickle(obj, filename)
¶
Saves an object as a pickle file. Add .pkl to the filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
object
|
Object to be saved. |
required |
filename |
str
|
Name of the pickle file. |
required |
Examples:
>>> from spotpython.utils.file import save_pickle
>>> save_pickle(obj, filename="obj.pkl")
Source code in spotpython/utils/file.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|