Life Cycle Interface

This module provides an interface to the LifeCycleManager.

class vivarium.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.

Return type:

None

Parameters:
  • state (str) – The name of the state to register the handlers for.

  • handlers (list[Callable[[Event], None]]) – A list of functions that will execute during the state.

add_constraint(method, allow_during=(), restrict_during=())[source]

Constrains a function to be executable only during certain states.

Return type:

None

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_during nor restrict_during are 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.

current_state()[source]

Returns a callable that gets the current simulation lifecycle state.

Return type:

Callable[[], str]

Returns:

A callable that returns the current simulation lifecycle state.