Reference

Decu is a library for experimental computation scripts.

core.py

Main decu classes and decorators.

class decu.core.Script(project_dir='', module=None)[source]

Bases: object

Base class for experimental computation scripts.

data_dir = 'data/'
figure_fmt = 'png'
figures_dir = 'pics/'
gendata_dir = 'data/'
make_figure_basename(fig_name, suffix=None)[source]
make_result_basename(exp_name, run)[source]
results_dir = 'results/'
scripts_dir = 'src/'
decu.core.experiment(data_param=None)[source]

Decorator that adds logging functionality to experiment methods.

Parameters:
  • data_param (str) – Parameter treated by the method as data
  • All other parameters are treated as experimental parameters. (input.) –
Returns:

A decorator that adds bookkeeping functionality to its argument.

Return type:

func

decu.core.figure(show=False, save=True)[source]

Create the figure decorator.

Parameters:
  • show (bool) – Whether or not the figure should be shown.
  • save (bool) – Whether or not the figure should be saved to disk.
Returns:

A decorator that adds figure logging functionality to its argument.

Return type:

func

decu.core.run_parallel(exp, params)[source]

Run an experiment in parallel.

For each element p in params, call exp(*p). These calls are made in parallel using multiprocessing.

Parameters:
  • exp (method) – A @experiment-decorated method.
  • params (list) – Each element is a set of arguments to call exp with.
Returns:

The result of calling exp(*pi) over each element of params.

Return type:

list

exception decu.core.DecuException[source]

Bases: Exception

io.py

Reading and writing functionality for decu.

decu.io.write(result, basename)[source]

Write result to disk.

decu.io.read(infile)[source]

Read result from disk.

logging.py

Logging system setup for decu, specially, make multiprocessing and logging play nicely together.

class decu.logging.DecuLogger(start_time, project_dir, module)[source]

Bases: object

critical(msg)[source]
debug(msg)[source]
error(msg)[source]
info(msg)[source]
log(level, msg)[source]
warning(msg)[source]

config.py

Custom configuration parsing for decu, based on configparser.

class decu.config.DecuParser(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object>, converters=<object object>)[source]

Bases: configparser.ConfigParser

ConfigParser subclass for decu.

Treat every option in the config file as a string.Template object.

subs(section, option, **kwargs)[source]

Perform the named substitutions on the option.

Each option in the decu configuration file is treated as a string.Template object, and thus accepts named variables for substitution. To read a raw option from the configuration file, do decu.config[section][option]. To read a substituted option, do decu.config.subs(section, option, kwargs) or decu.config.subs[section].subs(option, kwargs), where every keyword argument is a name=string pair to be substituted in the option.

Parameters:
  • section (str) – the desired section.
  • option (str) – the desired option.
  • kwargs (dict) – every keyword argument is a name=string pair to be substituted in the option template.
Returns:

the option template with the named strings substituted in.

Return type:

str