traversals
traversals ¶
Contains helper methods centered around traversing collections or pipelines in ways specific to CoSy-Luigi.
flatten(*heterogeneous_task_collection: type[CoSyLuigiTask] | Iterable[type[CoSyLuigiTask]]) -> Iterable[type[CoSyLuigiTask]] ¶
Takes an arbitrarily nested Sequence where the leaves of the nested structure are CoSyLuigiTasks' types and flattens it. During flattening, if an abstract Task type is encountered, it is instead expanded into the set of its implementing subclasses and becomes part of the flattening procedure, i.e. also multiple levels of abstraction are correctly handled. See the corresponding test_abstract_variant_expansion.py for an example.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*heterogeneous_task_collection | type[CoSyLuigiTask] | Sequence[type[CoSyLuigiTask]] | An arbitrarily nested Sequence where leaves are CoSyLuigiTasks' types. | () |
Returns:
| Type | Description |
|---|---|
Iterable[type[CoSyLuigiTask]] | Iterable[type[CoSyLuigiTask]]: The flattened representation of *heterogeneous_task_collection. |
Source code in src/cosy_luigi/utils/traversals.py
traverse_pipeline(to_traverse: CoSyLuigiTask | Sequence[CoSyLuigiTask] | Iterable[CoSyLuigiTask]) -> Sequence[CoSyLuigiTask] ¶
Recursively traverses a pipeline's structure and collect all encountered tasks. Wraps _traverse_pipeline to allow direct root task of a Pipeline to be passed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_traverse | CoSyLuigiTask | Sequence[CoSyLuigiTask] | Iterable[CoSyLuigiTask] | The pipeline to be traversed. | required |
Returns:
| Type | Description |
|---|---|
Sequence[CoSyLuigiTask] | Sequence[CoSyLuigiTask]: All tasks contained in the pipeline. |