Constraint Maker

Factory for making state-based constraints on component methods.

class vivarium.engine.framework.lifecycle.constraint_maker.ConstraintMaker(lifecycle_manager)[source]

Factory for making state-based constraints on component methods.

Parameters:

lifecycle_manager (LifeCycleManager)

check_valid_state(method, permitted_states)[source]

Ensures a component method is being called during an allowed state.

Return type:

None

Parameters:
  • method (Callable[[...], Any]) – The method the constraint is applied to.

  • permitted_states (list[str]) – The states in which the method is permitted to be called.

Raises:

ConstraintError – If the method is being called outside the permitted states.

constrain_normal_method(method, permitted_states)[source]

Only permit a method to be called during the provided states.

Constraints are applied by dynamically wrapping and binding a method to an existing component at run time.

Return type:

Callable[..., Any]

Parameters:
  • method (Callable[[...], Any]) – The method to constrain.

  • permitted_states (list[str]) – The life cycle states in which the method can be called.

Returns:

The constrained method.

static to_guid(method)[source]

Convert a method on to a global id.

Because we dynamically rebind methods, the old ones will get garbage collected, making id() unreliable for checking if a method has been constrained before.

Return type:

str

Parameters:

method (Callable[[...], Any]) – The method to convert to a global id.

Returns:

The global id of the method.