diff --git a/mlair/run_modules/run_environment.py b/mlair/run_modules/run_environment.py index ecb55282f25c369d6f5eddd81907a7d28ec7d62b..5414b21cb0cb26674c699a02c22400959e11f1aa 100644 --- a/mlair/run_modules/run_environment.py +++ b/mlair/run_modules/run_environment.py @@ -92,17 +92,18 @@ class RunEnvironment(object): logger = None tracker_list = [] - def __init__(self): + def __init__(self, name=None): """Start time tracking automatically and logs as info.""" if RunEnvironment.data_store is None: RunEnvironment.data_store = DataStoreObject() if RunEnvironment.logger is None: RunEnvironment.logger = Logger() - self.time = TimeTracking() - logging.info(f"{self.__class__.__name__} started") + self._name = name if name is not None else self.__class__.__name__ + self.time = TimeTracking(name=name) + logging.info(f"{self._name} started") # atexit.register(self.__del__) self.data_store.tracker.append({}) - self.tracker_list.extend([{self.__class__.__name__: self.data_store.tracker[-1]}]) + self.tracker_list.extend([{self._name: self.data_store.tracker[-1]}]) def __del__(self): """ @@ -114,7 +115,7 @@ class RunEnvironment(object): """ if not self.del_by_exit: self.time.stop() - logging.info(f"{self.__class__.__name__} finished after {self.time}") + logging.info(f"{self._name} finished after {self.time}") self.del_by_exit = True # copy log file and clear data store only if called as base class and not as super class if self.__class__.__name__ == "RunEnvironment": diff --git a/mlair/workflows/abstract_workflow.py b/mlair/workflows/abstract_workflow.py index d3fe480fdfe09393fbf2051d8795735e9217a8ad..bced90bbe848cc9ebe36c583d05b62549f0ae80b 100644 --- a/mlair/workflows/abstract_workflow.py +++ b/mlair/workflows/abstract_workflow.py @@ -15,8 +15,9 @@ class Workflow: method is sufficient. It must be taken care for inter-stage dependencies, this workflow class only handles the execution but not the dependencies (workflow would probably fail in this case).""" - def __init__(self): + def __init__(self, name=None): self._registry = OrderedDict() + self._name = name if name is not None else self.__class__.__name__ def add(self, stage, **kwargs): """Add a new stage with optional kwargs.""" @@ -24,6 +25,6 @@ class Workflow: def run(self): """Run workflow embedded in a run environment and according to the stage's ordering.""" - with RunEnvironment(): + with RunEnvironment(name=self._name): for stage, kwargs in self._registry.items(): stage(**kwargs)