Skip to content

gds.types

Interface

Bases: BaseModel

The directional-pair boundary of a Block.

Four port slots organized by direction

forward_in — domain inputs (covariant) forward_out — codomain outputs (covariant) backward_in — backward inputs (contravariant) backward_out — backward outputs (contravariant)

Source code in packages/gds-framework/gds/types/interface.py
class Interface(BaseModel, frozen=True):
    """The directional-pair boundary of a Block.

    Four port slots organized by direction:
      forward_in  — domain inputs (covariant)
      forward_out — codomain outputs (covariant)
      backward_in — backward inputs (contravariant)
      backward_out — backward outputs (contravariant)
    """

    forward_in: tuple[Port, ...] = ()
    forward_out: tuple[Port, ...] = ()
    backward_in: tuple[Port, ...] = ()
    backward_out: tuple[Port, ...] = ()

Bases: BaseModel

A named, typed connection point on a block's interface.

Source code in packages/gds-framework/gds/types/interface.py
class Port(BaseModel, frozen=True):
    """A named, typed connection point on a block's interface."""

    name: str
    type_tokens: frozenset[str]

TypeDef

Bases: BaseModel

A named, constrained type used in spaces and state.

Each TypeDef wraps a Python type with an optional constraint predicate. check_value() checks both the Python type and the constraint at runtime.

Source code in packages/gds-framework/gds/types/typedef.py
class TypeDef(BaseModel):
    """A named, constrained type used in spaces and state.

    Each TypeDef wraps a Python type with an optional constraint predicate.
    ``check_value()`` checks both the Python type and the constraint at runtime.
    """

    model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)

    name: str
    python_type: type
    description: str = ""
    constraint: Callable[[Any], bool] | None = None
    units: str | None = None

    def check_value(self, value: Any) -> bool:
        """Check if a value satisfies this type definition."""
        if not isinstance(value, self.python_type):
            return False
        return self.constraint is None or self.constraint(value)

check_value(value)

Check if a value satisfies this type definition.

Source code in packages/gds-framework/gds/types/typedef.py
def check_value(self, value: Any) -> bool:
    """Check if a value satisfies this type definition."""
    if not isinstance(value, self.python_type):
        return False
    return self.constraint is None or self.constraint(value)

Tokens

Tokenize a signature string into a normalized frozen set of tokens.

Splitting rules (applied in order): 1. Split on ' + ' (the compound-type joiner). 2. Split each part on ', ' (comma-space). 3. Strip whitespace and lowercase each token. 4. Discard empty strings.

Source code in packages/gds-framework/gds/types/tokens.py
def tokenize(signature: str) -> frozenset[str]:
    """Tokenize a signature string into a normalized frozen set of tokens.

    Splitting rules (applied in order):
    1. Split on ' + ' (the compound-type joiner).
    2. Split each part on ', ' (comma-space).
    3. Strip whitespace and lowercase each token.
    4. Discard empty strings.
    """
    if not signature:
        return frozenset()
    tokens: set[str] = set()
    for plus_part in signature.split(" + "):
        for comma_part in plus_part.split(", "):
            normalized = comma_part.strip().lower()
            if normalized:
                tokens.add(normalized)
    return frozenset(tokens)

Return True if a and b share at least one token.

Source code in packages/gds-framework/gds/types/tokens.py
def tokens_overlap(a: str, b: str) -> bool:
    """Return True if *a* and *b* share at least one token."""
    a_tokens = tokenize(a)
    b_tokens = tokenize(b)
    if not a_tokens or not b_tokens:
        return False
    return bool(a_tokens & b_tokens)

Return True if every token in child appears in parent.

Returns True if child is empty (vacuous truth).

Source code in packages/gds-framework/gds/types/tokens.py
def tokens_subset(child: str, parent: str) -> bool:
    """Return True if every token in *child* appears in *parent*.

    Returns True if child is empty (vacuous truth).
    """
    child_tokens = tokenize(child)
    if not child_tokens:
        return True
    return child_tokens <= tokenize(parent)