Experiments module

This module contains basic tag types to define an experiment with MLDev.

  • GenericPipeline is a sequence of steps (staged) with added services

  • BasicStage is a simple step in a pipeline

  • MonitoringService is a base class for services

  • FilePath is a utility data type that defines a path with several files within

class BasicStage(name='', params={}, env={}, inputs={}, outputs={}, script=[])[исходный код]

Базовые классы: object

A main class for non-versioned pipeline stages

Defines a step in a pipeline that can be recalculated given inputs to product outputs.

The pipeline, the stage participated in, first calls stage.prepare(name) method. The stage has to initialize all its dependencies and return with no error if it is ready to be run. If stage cannot run, it should raise an exception to prevent the pipeline from proceeding.

If a stage does not define the prepare method, it is skipped.

After that the pipeline call the stage instance via __call__ method, that is stage(name). This method should check if actual execution is needed or results are already fresh enough and then call stage.run().

The stage.run() method does the actual execution. It runs the script by default using the default shell via utils.exec_command.

Any configuration for pipeline and stage execution comes from MLDevSettings().

  • inputs – lists files and folders that this stage depends upon

  • outputs – lists files and folders that this stage produces and that will be added to version control

  • params – parameters for the commands being invoked

  • env – additional environmental variables to pass to commands

  • script – a list of command to invoke

prepare(stage_name)[исходный код]

Called by the pipeline. By default does nothing.


stage_name – a name of the stage


run(stage_name)[исходный код]

Called by the pipeline. Enter the stage_context and executes the script.


stage_name – a name of the stage


class FilePath(*args, **kwargs)[исходный код]

Базовые классы: object

Implements a collection of files prefixed with a common path

If cast to str, produces a space separated list of absolute paths. > Note: this could cause problems if path of files contain unescaped spaces.

When converted to json via to_json() produces a list of files from get_files()


path – (optional) a base path for the files and folders,

defaults to experiment root if absent :param files: (optional) a list of files relative to the path

get_files(start=None)[исходный код]

Returns a list of paths to files in this FilePath


start – (optional) if present, paths are relative to start, otherwise they are absolute


get_path(start=None)[исходный код]

Returns a base path for this FilePath


start – (optional) if present, paths are relative to start, otherwise they are absolute


to_json()[исходный код]
class GenericPipeline(*args, **kwargs)[исходный код]

Базовые классы: object

This is a basic pipeline to run stages and services in a sequence

Supports the following kinds of operation
  • sequence of runs - then use runs attribute in experiment.yml, expects instances of stages, for example using yaml anchors.

  • services and stages separately - first runs services, then stages, expects attribute names of top-level services and stages in the experiment spec in yaml. This does not requre use of yaml anchors.

When using runs, it executes „prepare“ and then calls the items in the order specified

The pipeline is a Callable and invoked as pipeline(). The pipeline can be called in mode='prepare' then it iterates over

  • runs – (optional) a list of stages or services in this pipeline, in the order to be run

  • stages – (optional) alternative list of stages in the pipeline, runs after services

  • services – (optional) a list of services, runs before stages

exec_item(run, experiment_config, run_name=None, exec_type='run')[исходный код]
exec_runs(experiment_config, exec_type)[исходный код]
exec_stages(experiment_config, exec_type)[исходный код]
run_services(experiment_config, exec_type)[исходный код]
class MonitoringService(name=None, params={})[исходный код]

Базовые классы: object

A common superclass for services accompanying the experiment

Uses the following configuration parameters: - MLDevSettings().temp_dir for the directory for mldev temp files - MLDevSettings().tool_dir for the install directory of mldev

prepare(service_name)[исходный код]
class PythonFunction(*args, **kwargs)[исходный код]

Базовые классы: object

Use this to load a specific python function into object graph from experiment.yaml

This is a string scalar specifying a fully qualified name of the function

experiment_tag(loader=<function _mapping_loader>, representer=<function _mapping_representer>, name=None, pattern=None)[исходный код]

Use this tag to mark classes invoked from experiment.yml

Note: use experiment_tag(), not just experiment_tag

  • loader – a loader (deserializer) for the specified class to pass to YAML loader

  • representer – a representer (serializer) for the class to pass to YAML loader

  • name – a tag name to use, will use classname if absent

  • pattern – a regexp pattern to use when extracting from scalar strings (see also yaml.add_implicit_resolver)


wrapped class