profit.run.command

Command Worker

The default Worker to run an executable simulation. The Preprocessor allows for a customized preparation of the environment for the simulation. The output of the simulation is retrieved by a Postprocessor.

  • CommandWorker: run an executable simulation

  • Preprocessor: new Component to prepare the environment for the simulation * TemplatePreprocessor: fill a directory according to a template directory

  • Postprocessor: new Component to retrieve the simulation output * JSONPostprocessor: read a simple JSON * NumpytxtPostprocessor: read a CSV/TSV (using numpy) * HDF5Postprocessor: read a simple HDF5

Module Contents

Classes

CommandWorker

Helper class that provides a standard way to create an ABC using

Preprocessor

Helper class that provides a standard way to create an ABC using

TemplatePreprocessor

Preprocessor which substitutes the variables with a given template

Postprocessor

Helper class that provides a standard way to create an ABC using

Functions

JSONPostprocessor(self, data)

Postprocessor to read output from a JSON file

NumpytxtPostprocessor(self, data)

Postprocessor to read output from a tabular text file (e.g. csv, tsv) with numpy genfromtxt

HDF5Postprocessor(self, data)

Postprocessor to read output from a HDF5 file

class profit.run.command.CommandWorker(run_id: int, *, pre='template', post='numpytxt', command='./simulation', stdout='stdout', stderr=None, **kwargs)[source]

Bases: profit.run.worker.Worker

Helper class that provides a standard way to create an ABC using inheritance.

work()[source]
class profit.run.command.Preprocessor(run_dir: str, *, clean=True, logger_parent=None)[source]

Bases: profit.run.worker.Component

Helper class that provides a standard way to create an ABC using inheritance.

abstract prepare(data: Mapping)[source]
post()[source]
classmethod wrap(label, config={})[source]
class profit.run.command.TemplatePreprocessor(run_dir: str, *, clean=True, path='template', param_files=None, logger_parent=None)[source]

Bases: Preprocessor

Preprocessor which substitutes the variables with a given template

  • copies the given template directory to the target run directory

  • searches all files for variables templates of the form {name} and replaces them with their values

  • for file formats which use curly braces (e.g. json) the template identifier is {{name}}

  • substitution can be restricted to certain files by specifying param_files, None means no restriction

  • relative symbolic links are converted to absolute symbolic links on copying

  • linked files are ignored with param_files = None, but if specified explicitly the link target is copied to the run directory and then substituted

property template_path
prepare(data: Mapping)[source]
fill_run_dir_single(params, template_dir, run_dir_single, param_files=None, overwrite=False, ignore_path_exists=False)[source]
classmethod copy_template(template_dir, out_dir, dont_copy=None)[source]

When copying the template directory to the single run directories, relative paths in symbolic links are converted to absolute paths.

fill_template(out_dir, params, param_files=None)[source]
Parameters:

param_files (list) – a list of filenames which are to be substituted or None for all

classmethod fill_template_file(template_filepath, output_filepath, params, copy_link=True)[source]

Fill template in template_filepath by params and output into output_filepath. If copy_link is set (default), do not write into symbolic links but copy them instead.

static replace_template(content, params)[source]

Returns filled template by putting values of params in content.

# Escape ‘{*}’ for e.g. json templates by replacing it with ‘{{*}}’. # Variables then have to be declared as ‘{{*}}’ which is replaced by a single ‘{*}’.

class profit.run.command.Postprocessor(*, logger_parent: logging.Logger = None)[source]

Bases: profit.run.worker.Component

Helper class that provides a standard way to create an ABC using inheritance.

abstract retrieve(data: MutableMapping)[source]
classmethod wrap(label, config={})[source]
profit.run.command.JSONPostprocessor(self, data)[source]

Postprocessor to read output from a JSON file

  • variables are assumed to be stored with the correct key and able to be converted immediately

  • not extensively tested

profit.run.command.NumpytxtPostprocessor(self, data)[source]

Postprocessor to read output from a tabular text file (e.g. csv, tsv) with numpy genfromtxt

  • the data is assumed to be row oriented

  • vector variables are spread across the row and have to be in the right order, only the name of the variable should be specified once in names

  • names which are not specified as output variables are ignored

  • additional options are passed directly to ``numpy.genfromtxt()`

profit.run.command.HDF5Postprocessor(self, data)[source]

Postprocessor to read output from a HDF5 file

  • variables are assumed to be stored with the correct key and able to be converted immediately

  • not extensively tested