Values Manager

class vivarium.engine.framework.values.manager.ValuesManager[source]

Manager for the dynamic value system.

Notes

This is the only manager for the values system; different methods exist for working with generic value Pipelines and AttributePipelines.

property name: str
setup(builder)[source]

Defines custom actions this manager needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the manager. By default, it does nothing.

Return type:

None

Parameters:

builder (Builder) – The builder object used to set up the manager.

on_post_setup(_event)[source]

Finalizes dependency structure for the pipelines.

Return type:

None

Parameters:

_event (Event)

register_value_producer(value_name, source, required_resources=(), preferred_combiner=<function replace_combiner>, preferred_post_processor=())[source]

Registers a Pipeline as the producer of a named value.

Return type:

Pipeline

Parameters:
  • value_name (str) – The name of the new dynamic value pipeline.

  • source (Callable[[...], Any]) – A callable source for the dynamic value pipeline.

  • required_resources (Iterable[str | Resource]) – A list of resources that the producer requires. A string represents a population attribute.

  • preferred_combiner (ValueCombiner) – A strategy for combining the source and the results of any calls to mutators in the pipeline. vivarium provides the strategies replace_combiner (the default) and list_combiner, which are importable from vivarium.engine.framework.values. Client code may define additional strategies as necessary.

  • preferred_post_processor (PostProcessor | Sequence[PostProcessor]) – A strategy for processing the final output of the pipeline. vivarium provides the strategies rescale_post_processor and union_post_processor which are importable from vivarium.engine.framework.values. Client code may define additional strategies as necessary. If a sequence of post processors is provided, they will be applied in the order they are provided.

Returns:

The Pipeline that is registered as the producer of the named value.

register_attribute_producer(value_name, source, required_resources=(), preferred_combiner=<function replace_combiner>, preferred_post_processor=(), source_is_private_column=False)[source]

Registers an AttributePipeline as the producer of a named attribute.

Parameters:
  • value_name (str) – The name of the new dynamic attribute pipeline.

  • source (Callable[[pd.Index[int]], Any] | list[str]) – The source for the dynamic attribute pipeline. This can be a callable, a list containing a single name of a private column created by this component, or a list of population attributes. If a private column name is passed, source_is_private_column must also be set to True.

  • required_resources (Iterable[str | Resource]) – A list of resources that the producer requires. A string represents a population attribute.

  • preferred_combiner (ValueCombiner) – A strategy for combining the source and the results of any calls to mutators in the pipeline. vivarium provides the strategies replace_combiner (the default) and list_combiner, which are importable from vivarium.engine.framework.values. Client code may define additional strategies as necessary.

  • preferred_post_processor (AttributePostProcessor | Sequence[AttributePostProcessor]) – A strategy for processing the final output of the pipeline. vivarium provides the strategies rescale_post_processor and union_post_processor which are importable from vivarium.engine.framework.values. Client code may define additional strategies as necessary. If a sequence of post processors is provided, they will be applied in the order they are provided.

  • source_is_private_column (bool) – Whether or not the source is the name of a private column created by this component.

Return type:

None

register_value_modifier(value_name, modifier, required_resources=())[source]

Marks a Callable as the modifier of a named value.

Return type:

None

Parameters:
  • value_name (str) – The name of the dynamic value Pipeline to be modified.

  • modifier (Callable[[...], Any]) – A function that modifies the source of the dynamic value Pipeline when called. If the pipeline has a replace_combiner, the modifier must have the same arguments as the pipeline source with an additional last positional argument for the results of the previous stage in the pipeline. For the list_combiner strategy, the pipeline modifiers should have the same signature as the pipeline source.

  • required_resources (Iterable[str | Resource]) – A list of resources that the producer requires. A string represents a population attribute.

register_attribute_modifier(value_name, modifier, required_resources=())[source]

Marks a Callable as the modifier of a named attribute.

Return type:

None

Parameters:
  • value_name (str) – The name of the dynamic AttributePipeline to be modified.

  • modifier (Callable[[...], Any] | str) – A function that modifies the source of the dynamic AttributePipeline when called. If a string is passed, it refers to the name of an AttributePipeline. If the pipeline has a replace_combiner, the modifier should accept the same arguments as the pipeline source with an additional last positional argument for the results of the previous stage in the pipeline. For the list_combiner strategy, the pipeline modifiers should have the same signature as the pipeline source.

  • required_resources (Iterable[str | Resource]) – A list of resources that need to be properly sourced before the pipeline modifier is called. This is a list of attribute names, pipelines, or randomness streams.

get_value(name)[source]

Retrieves the Pipeline representing the named value.

Return type:

Pipeline

Parameters:

name (str) – Name of the Pipeline to return.

Returns:

The requested Pipeline.

Notes

This will create a new Pipeline if one does not already exist.

get_value_pipelines()[source]

Retrieves a dictionary of all registered value Pipelines.

To get all AttributePipelines, use get_attribute_pipelines().

Return type:

dict[str, Pipeline]

Returns:

A dictionary mapping value names to their corresponding Pipelines.

get_attribute(name)[source]

Retrieves the AttributePipeline representing the named attribute.

To get a value Pipeline, use get_value().

Return type:

AttributePipeline

Parameters:

name (str) – Name of the AttributePipeline to return.

Returns:

The requested AttributePipeline.

Notes

This will create a new AttributePipeline if one does not already exist.

get_attribute_pipelines()[source]

Returns a dictionary of AttributePipelines.

Return type:

dict[str, AttributePipeline]

Returns:

A dictionary mapping all registered attribute names to their corresponding AttributePipelines.

Notes

This is not the preferred access method to getting population attributes since it does not implement various features (e.g. querying, simulant tracking, etc); it exists for other managers to use if needed. Use vivarium.engine.framework.population.population_view.PopulationView.get() or vivarium.engine.framework.population.population_view.PopulationView.get_frame() instead.