mllooper.Module#

class mllooper.Module(name: Optional[str] = None, log_level: int = 10, log_time_delta: timedelta = datetime.timedelta(seconds=10))[source]#

Bases: ABC

initialise(modules: Dict[str, Module]) None[source]#

Perform initialization steps of the module.

This might be needed to preform initialization steps that rely on other modules. The method receives a dictionary with other already initialised modules. Theses can be used for the own initialization.

This method should always be called before mllooper.module.Module.step() is called.

This method should only be used when the initialisation depends on other modules. If this is not the case use self.__init__().

Parameters:

modules (Dict[str, Module]) – Dictionary of other modules which are already initialised

load_state_dict(state_dict: Dict[str, any], strict: bool = True) None[source]#

Load the modules state from a dictionary.

Parameters:
  • state_dict (Dict[str, any]) – The state dictionary to load

  • strict (bool) – If true rise an error on missing or additional keys in the state dict. If false these keys will be ignored.

log(state: State) bool[source]#

Log information from the module.

The logic for logging should be implemented in mllooper.module.Module._log()

Parameters:

state (State) – The current state

run(state: Optional[State] = None) State[source]#

Initialise all modules, perform a step and teardown all modules.

Parameters:

state (Optional[State]) – A initial state to run on, defaults to None

Returns:

The resulting state of the run

Return type:

State

state_dict() Dict[str, Any][source]#

Return the state of the module as dictionary.

All items of the dictionary should be serializable by pickle.

Returns:

The modules current state as dictionary

Return type:

Dict[str, Any]

step(state: State) None[source]#

Perform a step of the module on the state.

Parameters:

state (State) – The current state

step_callback(state: State) None[source]#

Callback which should be called after a single step of all modules.

Parameters:

state (State) – The current state

teardown(state: State) None[source]#

Perform teardown steps of the module.

After calling no more calls to mllooper.module.Module.step() should be made. The provided state should not be modified.

Parameters:

state (State) – The final state