Overview
The exputils package has several submodules that are organized according to functionality.
The submodules must not be imported individually.
After importing the exputils
module all can be accessed through it.
List of submodules:
exputils
: Basic functionality that contain theAttrDict
to define experiment configurations and functions that help to use the configuration.exputils.manage
: Functions to generate experiments from a configuration template and to execute them with support for parallel execution. See the Manage section for details.exputils.data
: Functions that are data related, such as Logging and Loading of experiment data.exputils.gui.jupyter
: Widgets and plotting functions to load and plot logged data in Jupyter notebook. See the Visualization section for details.exputils.io
: Basic IO helper functions which are used by the exputils package. They are usually not needed to log or load data which is done with the functions under theexputils.data
module.exputils.misc
: Various helper functions used by the exputils package. Not yet documented.
Note: As this is a one-person development project, not all functionality is documented yet. In question, please refer directly to the source code or contact me.
Basic Functions
AttrDict
Bases: dict
A dictionary that provides attribute-style access. Can be used to configure experiments.
Example:
>>> b = AttrDict()
>>> b.hello = 'world'
>>> b.hello
'world'
>>> b['hello'] += "!"
>>> b.hello
'world!'
>>> b.foo = AttrDict(lol=True)
>>> b.foo.lol
True
>>> b.foo is b['foo']
True
A AttrDict is a subclass of dict; it supports all the methods a dict does...
>>> sorted(b.keys())
['foo', 'hello']
Including update()...
>>> b.update({ 'ponies': 'are pretty!' }, hello=42)
>>> print (repr(b))
AttrDict({'ponies': 'are pretty!', 'foo': Munch({'lol': True}), 'hello': 42})
As well as iteration...
>>> sorted([ (k,b[k]) for k in b ])
[('foo', AttrDict({'lol': True})), ('hello', 42), ('ponies', 'are pretty!')]
And "splats".
>>> "The {knights} who say {ni}!".format(**AttrDict(knights='lolcats', ni='can haz'))
'The lolcats who say can haz!'
Source code in exputils/misc/attrdict.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 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 162 163 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
combine_dicts
Combines several AttrDicts recursively. This can be used to combine a given configuration with a default configuration.
Example
Output:Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Dictionaries that should be combined. The order is important as a dictionary that is given first overwrites the values of properties of all following dictionaries. |
()
|
|
is_recursive
|
bool
|
Should the dictionaries be recursively combined? |
True
|
copy_mode
|
str
|
Defines how the properties of the dictionaries should be copied ('deepcopy', 'copy', 'none') to the combined dictionary. |
'deepcopy'
|
Returns:
Name | Type | Description |
---|---|---|
comb_dict |
AttrDict
|
Combined AttrDict. |
Source code in exputils/misc/attrdict.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
|
create_object_from_config
Creates a class object that is defined as a config dictionary or AttrDict.
The configuration dictionary must contain a 'cls' property that holds the class type. All other properties are used as parameters for the constructor of the object.
Example
Output:Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
Configuration dictionary with |
required |
*args
|
Additional arguments to pass to the constructor of the object. |
()
|
|
*argv
|
Additional arguments to pass to the constructor of the object. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
obj |
object
|
The resulting object. |
Source code in exputils/misc/misc.py
call_function_from_config
Calls a function that is defined as a config dictionary or AttrDict.
The configuration dictionary must contain a property that holds the function handle. This is
by default called func
, but can be differently defined using the func_attribute_name
parameter.
All other properties of the configuration dictionary are used as parameters for the function call.
If the given config
argument is a function handle, then this function is called and the given
args and *argvs given as arguments.
If the given config
argument is not a dictionary or a function handle, then it is directly
returned.
Example
import exputils as eu
def calc_area(length, width, unit='sm'):
area = length * width
return f"{area} {unit}"
config = eu.AttrDict()
config.func = calc_area # function that should be called
config.unit = 'square meters'
# calls the function with: calc_area(length=3, width=4, unit='square meters')
out = eu.call_function_from_config(config, length=3, width=4)
print(out)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
Configuration dictionary func property that holds the function handle. |
required |
func_attribute_name
|
str
|
Name of the func attribute. |
'func'
|
*args
|
Additional arguments to pass to the function. |
()
|
|
*argv
|
Additional arguments to pass to the function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
res |
Any
|
The return value of the function. |
Source code in exputils/misc/misc.py
seed
Sets the random seed for random, numpy and pytorch (if it is installed).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed
|
(int, dict)
|
Seed (integer) or a configuration dictionary which contains a 'seed' property.
If |
None
|
is_set_random
|
bool
|
Should the random seed of the python |
True
|
is_set_numpy
|
bool
|
Should random seed of |
True
|
is_set_torch
|
bool
|
Should random seed of torch be set. |
True
|
Returns:
Name | Type | Description |
---|---|---|
seed |
int
|
Integer that was used as seed. |
Source code in exputils/misc/misc.py
update_status
Updates the status of the running experiment/repetition in its status file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status
|
str
|
Status in form of a string. |
required |
status_file
|
str
|
Optional path to the status file. By default, it is the status file of the running process. |
None
|
Source code in exputils/misc/misc.py
Default Variables
The package has a list of default variables located on the module level that mainly control the names of the generated directories. They can be adjusted if needed.
Name | Type | Description | Default |
---|---|---|---|
DEFAULT_ODS_CONFIGURATION_FILE |
str |
Filename of the ODS configuration file for campaigns. | 'experiment_configurations.ods' |
DEFAULT_EXPERIMENTS_DIRECTORY |
str |
Name of the directory in the campaign directory under which experiment directories are created. | 'experiments' |
EXPERIMENT_DIRECTORY_TEMPLATE |
str |
Name template of experiment directories. Has to contain a placeholder for the ID. | 'experiment_{:06d}' |
REPETITION_DIRECTORY_TEMPLATE |
str |
Name template of repetition directories. Has to contain a placeholder for the ID. | 'repetition_{:06d}' |
DEFAULT_DATA_DIRECTORY |
str |
Name of the directory that is used to store the logs under each repetition. | 'data' |
REPETITION_DATA_KEY |
str |
Keyname of the element in the AttrDict returned by the load_experiment_data function that holds all the repetition data. |
'repetition_data' |
To customize them they can be changed after the exputils package as been imported: