- class vivarium.engine.framework.values.pipeline.ValueSource(pipeline, source)[source]
A wrapper for the source of a value pipeline.
- Parameters:
pipeline (Pipeline)
source (Callable[..., Any])
- class vivarium.engine.framework.values.pipeline.MissingValueSource(pipeline)[source]
A placeholder value source representing a pipeline with no source.
This is used when a modifier of a pipeline is registered before the pipeline itself. The source of the pipeline must be set before the pipeline is called, but this allows for more flexible ordering of component setup.
- Parameters:
pipeline (Pipeline)
- class vivarium.engine.framework.values.pipeline.PrivateColumnValueSource(pipeline, source, population_view)[source]
A value source representing a private column source of a value pipeline.
- Parameters:
pipeline (Pipeline)
source (str)
population_view (PopulationView)
- column_name
The name of the private column that is the source of this pipeline.
- class vivarium.engine.framework.values.pipeline.AttributesValueSource(pipeline, source, population_view)[source]
A value source representing the list of attributes source of an attribute pipeline.
- Parameters:
pipeline (Pipeline)
population_view (PopulationView)
- attributes
The name or list of names of the attributes that are the source of this pipeline.
- class vivarium.engine.framework.values.pipeline.ValueModifier(pipeline, modifier, component, required_resources=())[source]
A resource representing a modifier of a value pipeline.
- Parameters:
- RESOURCE_TYPE = 'value_modifier'
The type of the resource. Should be overridden by subclasses.
- class vivarium.engine.framework.values.pipeline.Pipeline(name, component=None)[source]
A tool for building up values across several components.
Pipelines are lazily initialized so that we don’t have to put constraints on the order in which components are created and set up. The values manager will configure a pipeline (set all of its attributes) when the pipeline source is created.
As long as a pipeline is not actually called in a simulation, it does not need a source or to be configured. This might occur when writing generic components that create a set of pipeline modifiers for values that won’t be used in the particular simulation.
Notes
Pipelines are highy generic and can be used to calculate values of any type through a simulation. Most pipelines are intended to calculate simulant attributes; for those, use
AttributePipeline.- RESOURCE_TYPE = 'value'
The type of the resource.
-
source:
ValueSource The callable source of the value represented by the pipeline.
-
mutators:
list[ValueModifier] A list of callables that directly modify the pipeline source or contribute portions of the value.
-
post_processor:
list[PostProcessor] A list of the transformations to perform in order on the combined output of the source and mutators.
- property combiner: ValueCombiner
A strategy for combining the source and mutator values into the final value represented by the pipeline.
- property manager: ValuesManager
A reference to the simulation values manager.
- get_value_modifier(modifier, component, required_resources)[source]
Adds a value modifier to the pipeline and returns it.
- Return type:
- Parameters:
modifier (Callable[[...], Any]) – The value modifier callable for the ValueModifier.
component (Component | Manager) – The component that creates the value modifier.
required_resources (Iterable[str | Resource]) – A list of resources required by the modifier. A string represents a population attribute.
- set_attributes(component, source, combiner, post_processor, required_resources, manager)[source]
Adds a source, combiner, post-processor, and manager to a pipeline.
- Return type:
- Parameters:
component (Component | Manager) – The component that creates the pipeline.
source (ValueSource) – The source for the dynamic attribute pipeline. This can be a callable or a list of column names. If a list of column names is provided, the component that is registering this attribute producer must be the one that creates those columns.
combiner (ValueCombiner) – A strategy for combining the source and mutator values into the final value represented by the pipeline.
post_processor (list[PostProcessor]) – An optional final transformation to perform on the combined output of the source and mutators.
required_resources (Iterable[str | Resource]) – A list of resources required by the pipeline source, combiner, and post-processor. A string represents a population attribute.
manager (ValuesManager) – The simulation values manager.
- Raises:
DynamicValueError – If a second component attempts to set the source for a pipeline that already has a source.
- class vivarium.engine.framework.values.pipeline.AttributePipeline(name, component=None)[source]
A type of value pipeline for calculating simulant attributes.
An attribute pipeline is a specific type of
Pipelinewhere the source and callable must take a pd.Index of integers and return a pd.Series or pd.DataFrame that has that same index.- RESOURCE_TYPE = 'attribute'
The type of the resource.
- property is_simple: bool
Whether or not this
AttributePipelineis simple, i.e. it has a list of columns as its source and no modifiers or postprocessors.
-
post_processor:
list[AttributePostProcessor] A list of the transformations to perform in order on the combined output of the source and mutators.