baselooper.Looper#

class baselooper.Looper(modules: Dict[str, Union[baselooper.module.Module, str]], **kwargs)[source]#

Bases: baselooper.module.Module

A module which takes a list of other modules and loops over it.

A step on a Looper module is not a single iteration of the loop but the whole loop. That means a single step on a Looper is a loop that might run forever.

The state inside the loop is separated from the state outside the loop. The modules which the Looper loops over never see the state the lopper lives in.

initialise(modules: Optional[Dict[str, baselooper.module.Module]] = None)[source]#

Perform initialization steps of all modules in the loop.

Modules in the loop should not depend on modules outside the loop. Therefore the modules of the loop can only access other modules in the same loop. The given modules dictionary will be ignored.

Parameters

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

load_state_dict(state_dict: Dict[str, any], strict: bool = True)[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)[source]#

Log information from the Looper and from all included modules.

Parameters

state (State) – The current 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: baselooper.state.State)[source]#

Perform a step of the Looper on the state.

A step on a Looper module is not a single iteration of the loop but the whole loop. That means a single step on a Looper might be a loop that runs forever.

Parameters

state (State) – The current state

step_callback_modules()[source]#

Call the callbacks of all included modules.

teardown(state: baselooper.state.State)[source]#

Teardown all modules in the loop.

Parameters

state (State) – The final state