baselooper.Module#
- class baselooper.Module(name: Optional[str] = None, log_level: int = 10, log_time_delta: datetime.timedelta = datetime.timedelta(seconds=10))[source]#
Bases:
abc.ABC- initialise(modules: Dict[str, baselooper.module.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
baselooper.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: baselooper.state.State) None[source]#
Log information from the module.
The logic for logging should be implemented in
baselooper.module.Module._log()- Parameters
state (State) – The current state
- run(state: Optional[baselooper.state.State] = None) baselooper.state.State[source]#
Initialise all modules, perform a step and teardown all modules.
- 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: baselooper.state.State) None[source]#
Perform a step of the module on the state.
- Parameters
state (State) – The current state
- step_callback(state: baselooper.state.State) None[source]#
Callback which should be called after a single step of all modules.
- Parameters
state (State) – The current state
- teardown(state: baselooper.state.State) None[source]#
Perform teardown steps of the module.
After calling no more calls to
baselooper.module.Module.step()should be made. The provided state should not be modified.- Parameters
state (State) – The final state