Life Cycle Interface
This module provides an interface to the LifeCycleManager.
- class vivarium.engine.framework.lifecycle.interface.LifeCycleInterface(manager)[source]
Interface to the life cycle management system.
The life cycle management system allows components to constrain methods so that they’re only available during certain simulation life cycle states.
- Parameters:
manager (LifeCycleManager)
- add_handlers(state, handlers)[source]
Registers a set of functions to be called during a life cycle state.
This method does not apply any constraints, rather it is used to build up an execution order for introspection.
- add_constraint(method, allow_during=(), restrict_during=())[source]
Constrains a function to be executable only during certain states.
- Return type:
- Parameters:
method (Callable[[...], Any]) – The method to add constraints to.
allow_during (tuple[str, ...] | list[str]) – An optional list of life cycle states in which the provided method is allowed to be called.
restrict_during (tuple[str, ...] | list[str]) – An optional list of life cycle states in which the provided method is restricted from being called.
- Raises:
ValueError – If neither
allow_duringnorrestrict_duringare provided, or if both are provided.LifeCycleError – If states provided as arguments are not in the life cycle.
ConstraintError – If a life cycle constraint has already been applied to the provided method.