Manage
Functions to manage the generation and execution of experiments.
All functions can be accessed under the module: exputils.manage
Experiments are recommended to be stored in a specific folder structure which allows to save and load experimental data in a structured manner. Please note that it represents a default structure which can be adapted if required. Elements in brackets (<custom name>) can have custom names.
Folder structure:
- <experiments> folder: Holds all your campaigns.
- <experimental campaign> folders:
- <analyze> folder: Scripts such as Jupyter notebooks to analyze the different experiments in this experimental campaign.
- experiment_configurations.ods file: ODS file that contains the configuration parameters of the different experiments in this campaign.
- src folder: Holds code templates of the experiments.
- rep folder: Code templates that are used under the repetition folders of th experiments. These contain the acutal experimental code that should be run.
- exp folder: Code templates that are used under the experiment folder of the experiment. These contain usually code to compute statistics over all repetitions of an experiment.
- experiments folder: Contains generated code for experiments and the collected experimental data.
- experiment_{id} folders:
- repetition_{id} folders:
- data folder: Experimental data for the single repetitions, such as logs.
- code files: Generated code and resource files.
- repetition_{id} folders:
- experiment_{id} folders:
- <experimental campaign> folders:
Generation & Execution
generate_experiment_files
Generates experiments based on a configuration ODS file (LibreOffice Spreadsheet) and template source code.
The configuration ODS has to be in a specific form.
See resources/experiment_configurations.ods
for an example file.
The template source code is usually located in .\src\exp
for code on the experiment level
and .\src\rep
for code on the repetition level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ods_filepath
|
str
|
Path to the ODS configuration file that defines the experiments.
Default is |
None
|
directory
|
str
|
Path to directory where the experiments will be generated.
Default is |
None
|
verbose
|
bool
|
Should verbose output with more information given. Default is |
False
|
copy_operator
|
str
|
Define the copy operator for source code files. Either 'shutil' (default) for the python copy function or 'cp' for the linux terminal cp operator. The choice of the 'cp' copy operator was introduced as for some OS systems the 'shutil' did not work under python 3.8. |
'shutil'
|
Notes:
- Sheets in the configuration ODS file define groups of experiments for which an extra subfolder in the output directory will be generated.
Source code in exputils/manage/experimentgenerator.py
start_experiments
Searches all the start scripts of experiments and/or repetitions in the experiments folder and executes them either in parallel or sequentially.
It also documents their execution status (todo, running, finished, error) in a status file that allows it to identify if a script should be executed or not when used again on the same target directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Directory in which the start scripts are searched.
Default is |
None
|
start_scripts
|
str
|
Filename of the start script file that are searched under the given target directory.
Can include '' to search for scripts, for example 'run_.py'.
The default |
'run_*.py'
|
parallel
|
(bool, int)
|
Defines if scripts should be started in parallel and how many are allowed to run in parallel.
If |
True
|
is_chdir
|
bool
|
Before starting a script, should the main process change to its working directory. |
True
|
verbose
|
bool
|
Should verbose output with more information given. Default is |
False
|
post_start_wait_time
|
float
|
Time waited before one process is started after another. |
0.0
|
write_status_files_automatically
|
bool
|
Should status files that document if scripts were started and executed be written by the manager. These are important to identify if an experiment or repetition did run already. |
True
|
Source code in exputils/manage/experimentstarter.py
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 |
|
Helper
A couple of extra functions exist that can be used to determine how to best start experiments. For example by identifying how many scripts need to be executed and asking a cluster manager to provide to required resources such as the number of cores.
get_scripts
Searches all start scripts in the experiments directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Directory in which the start scripts are searched.
Default is |
None
|
start_scripts
|
str
|
Filename of the start script file that are searched under the given target directory.
Can include '' to search for scripts, for example 'run_.py'.
The default |
'run_*.py'
|
Returns:
Name | Type | Description |
---|---|---|
scripts |
list
|
List of filepaths to the start scripts. |
Source code in exputils/manage/experimentstarter.py
get_script_status
Returns the execution status of a certain start script.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script_file
|
str
|
Path to the script file. |
required |
Returns:
Name | Type | Description |
---|---|---|
status |
(str, None)
|
Status as a string. Usually |
Source code in exputils/manage/experimentstarter.py
get_number_of_scripts
Identifies the number of all scripts in the experiments directory regardless of their execution status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Directory in which the start scripts are searched.
Default is |
None
|
start_scripts
|
str
|
Filename of the start script file that are searched under the given target directory.
Can include '' to search for scripts, for example 'run_.py'.
The default |
'run_*.py'
|
Returns:
Name | Type | Description |
---|---|---|
n_scripts |
int
|
Number of scripts. |
Source code in exputils/manage/experimentstarter.py
get_number_of_scripts_to_execute
Identifies the number of scripts that have to be executed in the experiments directory. Scripts that have to be executed have either the status 'none', 'todo', 'error', or 'unfinished'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Directory in which the start scripts are searched.
Default is |
None
|
start_scripts
|
str
|
Filename of the start script file that are searched under the given target directory.
Can include '' to search for scripts, for example 'run_.py'.
The default |
'run_*.py'
|
Returns:
Name | Type | Description |
---|---|---|
n_scripts |
int
|
Number of scripts that have to be executed. |