ForEach

class laminar.configurations.layers.ForEach(parameters: ~typing.Iterable[~laminar.configurations.layers.Parameter] = <factory>)

Bases: object

Configures a layer to perform a grid-foreach over the configured properties.

Notes

In order to foreach over each element of a layer, the layer’s artifact must be sharded. See Layer.shard().

If Parameter(index=None), ForEach will include artifacts from all Layer splits.

Usage:

@Flow.register(foreach=ForEach(...))

Methods

grid

Generate a grid of all combinations of foreach inputs.

join

Join together multiple artifact splits of a layer into a single Archive.

set

Set a foreach layer's parameters given the inputs from the foreach grid.

splits

Get the splits of the ForEach grid.

Attributes

parameters

Parameters to configure the foreach with.

__init__(parameters: ~typing.Iterable[~laminar.configurations.layers.Parameter] = <factory>)
grid(*, layer: Layer) list[dict[Layer, dict[str, int]]]

Generate a grid of all combinations of foreach inputs.

Parameters
layer : Layer

Layer the ForEach is configured for.

Returns

Index ordered inputs of layers mapped to attributes mapped to Accessor

index.

Return type

List[Dict[Layer, Dict[str, int]]]

join(*, layer: Layer, name: str) Archive

Join together multiple artifact splits of a layer into a single Archive.

Parameters
layer : Layer

Layer to join archives for.

name : str

Name of the attribute to join archives for.

Returns

Archive created from multiple layer archives.

Return type

datastores.Archive

parameters : Iterable[Parameter]

Parameters to configure the foreach with.

set(*, layer: Layer, parameters: tuple[Layer, ...]) tuple[Layer, ...]

Set a foreach layer’s parameters given the inputs from the foreach grid.

Parameters
layer : Layer

Layer the ForEach is configured for.

parameters : Tuple[Layer, ...]

Parameters in the order they will be passed to the layer.

Returns

Parameters with modified values for the foreach evaluation.

Return type

Tuple[Layer, …]

splits(*, layer: Layer) int

Get the splits of the ForEach grid.