mlair.run_modules.run_environment

Implementation of run environment.

Module Contents

Classes

RunEnvironment

Basic run class to measure execution time.

Attributes

__author__

__date__

mlair.run_modules.run_environment.__author__ = Lukas Leufen
mlair.run_modules.run_environment.__date__ = 2019-11-25
class mlair.run_modules.run_environment.RunEnvironment(name=None, log_level_stream=None)

Bases: object

Basic run class to measure execution time.

Either call this class by ‘with’ statement or delete the class instance after finishing the measurement. The duration result is logged.

>>> with RunEnvironment():
        <your code>
INFO: RunEnvironment started
...
INFO: RunEnvironment finished after 00:00:04 (hh:mm:ss)

If you want to embed your custom module in a RunEnvironment, you can easily call it inside the with statement. If you want to exchange between different modules in addition, create your module as inheritance of the RunEnvironment and call it after you initialised the RunEnvironment itself.

class CustomClass(RunEnvironment):

    def __init__(self):
        super().__init__()
        ...
    ...


>>> with RunEnvironment():
        CustomClass()
INFO: RunEnvironment started
INFO: CustomClass started
INFO: CustomClass finished after 00:00:04 (hh:mm:ss)
INFO: RunEnvironment finished after 00:00:04 (hh:mm:ss)

All data that is stored in the data store will be available for all other modules that inherit from RunEnvironment as long the RunEnvironemnt base class is running. If the base class is deleted either by hand or on exit of the with statement, this storage is cleared.

class CustomClassA(RunEnvironment):

    def __init__(self):
        super().__init__()
        self.data_store.set("testVar", 12)


class CustomClassB(RunEnvironment):

    def __init__(self):
        super().__init__()
        self.test_var = self.data_store.get("testVar")
        logging.info(f"testVar = {self.test_var}")


>>> with RunEnvironment():
        CustomClassA()
        CustomClassB()
INFO: RunEnvironment started
INFO: CustomClassA started
INFO: CustomClassA finished after 00:00:01 (hh:mm:ss)
INFO: CustomClassB started
INFO: testVar = 12
INFO: CustomClassB finished after 00:00:02 (hh:mm:ss)
INFO: RunEnvironment finished after 00:00:03 (hh:mm:ss)
del_by_exit = False
data_store
logger
tracker_list = []
__del__(self)

Finalise class.

Only stop time tracking, if not already called by exit method to prevent duplicated logging (__exit__ is always executed before __del__) it this class was used in a with statement. If instance is called as base class and not as inheritance from this class, log file is copied and data store is cleared.

__enter__(self)

Enter run environment.

__exit__(self, exc_type, exc_val, exc_tb)

Exit run environment.

__move_log_file(self)
__save_tracking(self)
__plot_tracking(self)
__find_file_pattern(self, name)
classmethod update_datastore(cls, new_data_store: mlair.helpers.datastore.DataStoreByScope, excluded_params=None, apply_full_replacement=False)
static do_stuff(length=2)

Just a placeholder method for testing without any sense.