Coverage for mlair/workflows/abstract_workflow.py: 100%
15 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-12-02 15:24 +0000
« prev ^ index » next coverage.py v6.4.2, created at 2022-12-02 15:24 +0000
1"""Abstract workflow."""
3__author__ = "Lukas Leufen"
4__date__ = '2020-06-26'
6from mlair import RunEnvironment
9class Workflow:
10 """Abstract workflow class to handle sequence of stages (run modules). An inheriting class has to first initialise
11 this mother class and can afterwards add an arbitrary number of stages by using the add method. The execution order
12 is equal to the ordering of the stages have been added. To run the workflow, finally, a single call of the run
13 method is sufficient. It must be taken care for inter-stage dependencies, this workflow class only handles the
14 execution but not the dependencies (workflow would probably fail in this case)."""
16 def __init__(self, name=None, log_level_stream=None):
17 self._registry_kwargs = {}
18 self._registry = []
19 self._log_level_stream = log_level_stream
20 self._name = name if name is not None else self.__class__.__name__
22 def add(self, stage, **kwargs):
23 """Add a new stage with optional kwargs."""
24 self._registry.append(stage)
25 self._registry_kwargs[len(self._registry) - 1] = kwargs
27 def run(self):
28 """Run workflow embedded in a run environment and according to the stage's ordering."""
29 with RunEnvironment(name=self._name, log_level_stream=self._log_level_stream):
30 for pos, stage in enumerate(self._registry):
31 stage(**self._registry_kwargs[pos])