Starting example: square¶
This small example will you demonstrate the basic methodology how our package works. We use a very simple model represented by only one function that squares the input data and we create a project to investigate trigonmetric functions (sine, cosine, etc.).
So let’s define our model function
"""A small example for a computational model
"""
def compute(x):
return x ** 2
and save it in a file called 'calculate.py'
file. This function runs
only in python and does not know anything about where the input is from and
where it is saved.
We start from the pure ModelOrganizer
to manage our model named
square
#!/usr/bin/env python
from model_organization import ModelOrganizer
class SquareModelOrganizer(ModelOrganizer):
name = 'square'
if __name__ == '__main__':
SquareModelOrganizer.main()
and save it in the file called 'square.py'
. If we run our model from the
command line, (for technical reasons we run it here from inside IPython), we
see already several preconfigured commands
In [1]: !./square.py -h
usage: square [-h] [-id str] [-l] [-n] [-v] [-vl str or int] [-nm] [-E]
{setup,init,set-value,get-value,del-value,info,unarchive,configure,archive,remove}
...
The main function for parsing global arguments
positional arguments:
{setup,init,set-value,get-value,del-value,info,unarchive,configure,archive,remove}
setup Perform the initial setup for the project
init Initialize a new experiment
set-value Set a value in the configuration
get-value Get one or more values in the configuration
del-value Delete a value in the configuration
info Print information on the experiments
unarchive Extract archived experiments
configure Configure the project and experiments
archive Archive one or more experiments or a project instance
remove Delete an existing experiment and/or projectname
optional arguments:
-h, --help show this help message and exit
-id str, --experiment str
experiment: str
The id of the experiment to use. If the `init` argument is called, the `new` argument is automatically set. Otherwise, if not specified differently, the last created experiment is used.
-l, --last If True, the last experiment is used
-n, --new If True, a new experiment is created
-v, --verbose Increase the verbosity level to DEBUG. See also `verbosity_level`
for a more specific determination of the verbosity
-vl str or int, --verbosity-level str or int
The verbosity level to use. Either one of ``'DEBUG', 'INFO',
'WARNING', 'ERROR'`` or the corresponding integer (see pythons
logging module)
-nm, --no-modification
If True/set, no modifications in the configuration files will be
done
-E, --match If True/set, interprete `experiment` as a regular expression
(regex) und use the matching experiment
So to setup our new project, we use the setup()
method
In [2]: !./square.py setup . -p trigo
INFO:square.trigo:Initializing project trigo
And we initialize one experiment for the sine, one for the cosine, and one for the tangent functions
In [3]: !./square.py -id sine init -d "Squared Sine"
INFO:square.sine:Initializing experiment sine of project trigo
In [4]: !./square.py -id cosine init -d "Squared Cosine"