sgn.groups
¶
Element grouping and pad selection operations.
This module provides functionality for grouping elements and selecting specific pads for use in pipeline operations. It contains the core abstractions that allow for flexible and intuitive pipeline construction.
ElementGroup
dataclass
¶
Bases: PadIteratorMixin
flowchart TD
sgn.groups.ElementGroup[ElementGroup]
sgn.groups.PadIteratorMixin[PadIteratorMixin]
sgn.groups.PadIteratorMixin --> sgn.groups.ElementGroup
click sgn.groups.ElementGroup href "" "sgn.groups.ElementGroup"
click sgn.groups.PadIteratorMixin href "" "sgn.groups.PadIteratorMixin"
A unified group for elements and pad selections.
This class holds a collection of elements and pad selections without determining upfront whether to extract source or sink pads. The actual pad extraction is deferred until the group is used in pipeline.connect(), where the context (source vs sink position) determines which pads to extract.
Source code in src/sgn/groups.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
elements
property
¶
Get all unique elements referenced by this group.
snks
property
¶
Extract sink pads from all items in the group using names as keys.
srcs
property
¶
Extract source pads from all items in the group using names as keys.
select(*pad_names)
¶
Select pads from items in the group by pad name.
Source code in src/sgn/groups.py
PadIteratorMixin
¶
Mixin class that provides iteration methods for pad selections.
Source code in src/sgn/groups.py
select_by_sink()
¶
Iterate over sink pads, yielding (pad_name, single_pad_selection) tuples.
Each yielded PadSelection contains only a single sink pad. Raises ValueError if there are no sink pads.
Source code in src/sgn/groups.py
select_by_source()
¶
Iterate over source pads, yielding (pad_name, single_pad_selection) tuples.
Each yielded PadSelection contains only a single source pad. Raises ValueError if there are no source pads.
Source code in src/sgn/groups.py
PadProvider
¶
Bases: Protocol
flowchart TD
sgn.groups.PadProvider[PadProvider]
click sgn.groups.PadProvider href "" "sgn.groups.PadProvider"
Protocol defining the interface required by PadIteratorMixin.
Source code in src/sgn/groups.py
PadSelection
dataclass
¶
Bases: PadIteratorMixin
flowchart TD
sgn.groups.PadSelection[PadSelection]
sgn.groups.PadIteratorMixin[PadIteratorMixin]
sgn.groups.PadIteratorMixin --> sgn.groups.PadSelection
click sgn.groups.PadSelection href "" "sgn.groups.PadSelection"
click sgn.groups.PadIteratorMixin href "" "sgn.groups.PadIteratorMixin"
Represents a selection of specific pads from an element.
This allows users to specify exactly which pads from an element should be used in grouping operations.
Source code in src/sgn/groups.py
elements
property
¶
Get the element referenced by this selection.
snks
property
¶
Extract selected sink pads from the element using names as keys.
srcs
property
¶
Extract selected source pads from the element using names as keys.
__post_init__()
¶
Validate that the selected pad names exist on the element.
Source code in src/sgn/groups.py
group(*items)
¶
Create a unified group from elements, pad selections, and existing groups.
This function always returns an ElementGroup that holds elements and/or pad selections. The decision of which pads to extract is deferred until the group is used in pipeline.connect().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*items
|
Element | PadSelection | ElementGroup
|
Elements, pad selections, and/or existing ElementGroups to combine. |
()
|
Returns:
| Type | Description |
|---|---|
ElementGroup
|
A group containing all the provided items. |
Examples:
>>> src1 = IterSource(name="src1", source_pad_names=["H1"])
>>> src2 = IterSource(name="src2", source_pad_names=["L1", "V1"])
>>> snk = Sink(name="snk", sink_pad_names=["H1", "L1"])
>>>
>>> # Group elements
>>> sources = group(src1, src2)
>>>
>>> # Group with pad selection
>>> l1_only = select(src2, "L1")
>>> sources_with_selection = group(src1, l1_only)
>>>
>>> # Connect groups
>>> pipeline.connect(sources_with_selection, snk)
Source code in src/sgn/groups.py
select(target, *pad_names)
¶
Create or refine pad selections from elements, existing selections, or groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Element | PadSelection | ElementGroup
|
The element, pad selection, or element group to select pads from. |
required |
*pad_names
|
str
|
Names of the pads to select. |
()
|
Returns:
| Type | Description |
|---|---|
PadSelection | ElementGroup
|
A PadSelection if target is Element or PadSelection, |
PadSelection | ElementGroup
|
or ElementGroup if target is ElementGroup. |
Examples:
>>> src = IterSource(name="src", source_pad_names=["H1", "L1", "V1"])
>>> h1_only = select(src, "H1")
>>> h1_l1_only = select(src, "H1", "L1")
>>>
>>> # Narrow an existing selection
>>> h1_from_selection = select(h1_l1_only, "H1")
>>>
>>> # Select from a group
>>> sources = group(src1, src2)
>>> h1_from_group = select(sources, "H1")