Life Cycle Manager
Manager of ordering- and constraint-based contracts in the simulation
- class vivarium.engine.framework.lifecycle.manager.LifeCycleManager[source]
Manages ordering- and constraint-based contracts in the simulation.
- add_phase(phase_name, states, loop=False)[source]
Add a new phase to the lifecycle.
Phases must be added in order.
- Return type:
- Parameters:
- Raises:
LifeCycleError – If the phase or state names are non-unique.
- set_state(state)[source]
Sets the current life cycle state to the provided state.
- Return type:
- Parameters:
state (str) – The name of the state to set.
- Raises:
LifeCycleError – If the requested state doesn’t exist in the life cycle.
InvalidTransitionError – If setting the provided state represents an invalid life cycle transition.
- add_handlers(state_name, 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 lifecycle constraint has already been applied to the provided method.