timor.utilities.callbacks
Attributes
Classes
Holds all possible return values of a callback function. None will be interpreted as TRUE. |
Functions
|
Chains any number of callback functions together. |
Module Contents
- class timor.utilities.callbacks.CallbackReturn(*args, **kwds)

Holds all possible return values of a callback function. None will be interpreted as TRUE.
This Enum can be used by iterative algorithms to give feedback to the caller about the status of the algorithm. It’s values can be interpreted as follows:
TRUE: The callback was evaluated without any problems and the algorithm should continue.
- FALSE: The callback detected a problem (e.g., a constraint violation) that can potentially be resolved in
future iterations. However, the current state is not considered valid/successful.
BREAK: The callback detected a problem that cannot be resolved in future iterations. Interrupt the algorithm.
- BREAK = 'BREAK'
- FALSE = False
- TRUE = True
- classmethod _missing_(value)
Allow some aliases
- timor.utilities.callbacks.chain_callbacks(*callbacks)
Chains any number of callback functions together.
The callbacks will be executed in order until either one returns BREAK or all have been evaluated. The chain method casts all return values to a CallbackReturn automatically. Note that no return (None) will be considered as TRUE, indicating a callback evaluation without problems. If zero callbacks are chained (i.e., the chain is empty), the returned callback will always return TRUE.
- Parameters:
callbacks (Callable[[any], CallbackReturn]) – Any number of callbacks to be chained together. They should all return a CallbackReturn value.
- Returns:
A callback function that chains all input callbacks together. It takes any number of arguments.
- Return type:
Callable[[any], CallbackReturn]