class composer.Engine(state, logger)[source]#

Coordinator for running algorithms and resolving ordering conflicts among them for composition.

  • state (State) โ€“ The initial State of the trainer. state will be modified in-place.

  • logger (Logger) โ€“ A Logger instance to be used for logging algorithm and callback specific metrics.


Shutdown the engine.

As part of the shutdown procedure, Callback.close() and Callback.post_close() are invoked for each callback. Note that Callback.post_close() is invoked only for callbacks that did not raise an exception during Callback.close().

This method does not re-raise any exceptions from Callback.close() and Callback.post_close(). Instead, these exceptions are logged as errors.

register_pass(algorithm_pass, index=- 1)[source]#

Registers an algorithm pass with the Engine.

  • algorithm_pass (passes.AlgorithmPass) โ€“ A method that maps a list of algorithms to a list of algorithms.

  • index (int, optional) โ€“ The index to insert into the list of passes. If -1 (default), the pass will be insert to the end of the list.


Runs the sequence of algorithms and callbacks (see Callback).

Filters algorithms by calling each oneโ€™s Algorithm.match() method, internally checks for conflicting algorithms, then runs each algorithmโ€™s Algorithm.apply() method to make in-place changes to the state.

The default order of execution for algorithms is determined by the provided list. However, Engine makes changes to this order internally to resolve ordering conflicts.

Returns Traces of the execution, a dictionary with keys formatted as <algorithm_name>/<event> (e.g., Blurpool/INIT), and values are an instance of Trace.

Callbacks are always run after algorithms and do not return a trace.

This method can be called with either the Event enum member values or a string of the event name.


>>> engine = Engine(state, logger)
>>> engine.run_event(Event.BEFORE_LOSS)
>>> # calling with a string of the event name also works
>>> engine.run_event('before_loss')

event (Event | str) โ€“ The current Event. It can be the enum member values or a string with the event value.


traces (Traces) โ€“ Ordered dictionary of trace for each algorithm.


Runs the marker for an event if the profiler is enabled.

This is primarily used to complete the dataloader marker at the end of the dataloader. In this scenario, the dataloader marker has started from Event.BEFORE_DATALOADER, but Event.AFTER_DATALOADER cannot be called as no batch was yielded from the dataloader.


event (Event | str) โ€“ The current Event. It can be the enum member values or a string with the event value.