Skip to content

ogs.ir

Models

Bases: BaseModel

A single open game component in the flat IR representation.

Source code in packages/gds-games/ogs/ir/models.py
class OpenGameIR(BaseModel):
    """A single open game component in the flat IR representation."""

    name: str
    game_type: GameType
    signature: tuple[str, str, str, str]  # (X, Y, R, S)
    logic: str = ""
    gds_function: str | None = None
    constraints: list[str] = Field(default_factory=list)
    parent_pattern: str | None = None
    color_code: int
    contained_nodes: list[str] = Field(default_factory=list)
    tags: dict[str, str] = Field(default_factory=dict)

Bases: BaseModel

A directed information flow (edge) between components in the IR.

Source code in packages/gds-games/ogs/ir/models.py
class FlowIR(BaseModel):
    """A directed information flow (edge) between components in the IR."""

    source: str
    target: str
    label: str
    flow_type: FlowType
    direction: FlowDirection
    is_feedback: bool = False
    is_corecursive: bool = False

Bases: BaseModel

A complete composite pattern — the top-level unit of specification.

Source code in packages/gds-games/ogs/ir/models.py
class PatternIR(BaseModel):
    """A complete composite pattern — the top-level unit of specification."""

    name: str
    games: list[OpenGameIR] = Field(default_factory=list)
    flows: list[FlowIR] = Field(default_factory=list)
    inputs: list[InputIR] = Field(default_factory=list)
    composition_type: CompositionType
    terminal_conditions: list[TerminalCondition] | None = None
    action_spaces: list[ActionSpace] | None = None
    initialization: list[StateInitialization] | None = None
    hierarchy: HierarchyNodeIR | None = None
    source_canvas: str
    source_spec_notes: str | None = None

    def to_system_ir(self) -> SystemIR:
        """Project this OGS PatternIR to a GDS SystemIR.

        Enables interop with any GDS tool that accepts SystemIR, including
        GDS generic verification checks (G-001 through G-006).

        Mapping:
        - OpenGameIR → BlockIR (game_type → block_type, constraints/tags → metadata)
        - FlowIR → WiringIR (flow_type → wiring_type, is_corecursive → is_temporal)
        - OGS CORECURSIVE → GDS TEMPORAL
        """
        from gds.ir.models import BlockIR, SystemIR, WiringIR
        from gds.ir.models import CompositionType as GDSCompositionType
        from gds.ir.models import InputIR as GDSInputIR

        blocks = [
            BlockIR(
                name=g.name,
                block_type=g.game_type.value,
                signature=g.signature,
                logic=g.logic,
                color_code=g.color_code,
                metadata={"constraints": g.constraints, "tags": g.tags},
            )
            for g in self.games
        ]

        wirings = [
            WiringIR(
                source=f.source,
                target=f.target,
                label=f.label,
                wiring_type=f.flow_type.value,
                direction=f.direction,
                is_feedback=f.is_feedback,
                is_temporal=f.is_corecursive,
            )
            for f in self.flows
        ]

        # Map OGS composition types to GDS (CORECURSIVE → TEMPORAL)
        comp_map = {
            "sequential": "SEQUENTIAL",
            "parallel": "PARALLEL",
            "feedback": "FEEDBACK",
            "corecursive": "TEMPORAL",
        }
        gds_comp = GDSCompositionType[comp_map[self.composition_type.value]]

        inputs = [
            GDSInputIR(
                name=i.name,
                metadata={
                    "input_type": i.input_type.value,
                    "schema_hint": i.schema_hint,
                    "shape": i.shape,
                },
            )
            for i in self.inputs
        ]

        return SystemIR(
            name=self.name,
            blocks=blocks,
            wirings=wirings,
            inputs=inputs,
            composition_type=gds_comp,
            source=self.source_canvas,
        )

to_system_ir()

Project this OGS PatternIR to a GDS SystemIR.

Enables interop with any GDS tool that accepts SystemIR, including GDS generic verification checks (G-001 through G-006).

Mapping: - OpenGameIR → BlockIR (game_type → block_type, constraints/tags → metadata) - FlowIR → WiringIR (flow_type → wiring_type, is_corecursive → is_temporal) - OGS CORECURSIVE → GDS TEMPORAL

Source code in packages/gds-games/ogs/ir/models.py
def to_system_ir(self) -> SystemIR:
    """Project this OGS PatternIR to a GDS SystemIR.

    Enables interop with any GDS tool that accepts SystemIR, including
    GDS generic verification checks (G-001 through G-006).

    Mapping:
    - OpenGameIR → BlockIR (game_type → block_type, constraints/tags → metadata)
    - FlowIR → WiringIR (flow_type → wiring_type, is_corecursive → is_temporal)
    - OGS CORECURSIVE → GDS TEMPORAL
    """
    from gds.ir.models import BlockIR, SystemIR, WiringIR
    from gds.ir.models import CompositionType as GDSCompositionType
    from gds.ir.models import InputIR as GDSInputIR

    blocks = [
        BlockIR(
            name=g.name,
            block_type=g.game_type.value,
            signature=g.signature,
            logic=g.logic,
            color_code=g.color_code,
            metadata={"constraints": g.constraints, "tags": g.tags},
        )
        for g in self.games
    ]

    wirings = [
        WiringIR(
            source=f.source,
            target=f.target,
            label=f.label,
            wiring_type=f.flow_type.value,
            direction=f.direction,
            is_feedback=f.is_feedback,
            is_temporal=f.is_corecursive,
        )
        for f in self.flows
    ]

    # Map OGS composition types to GDS (CORECURSIVE → TEMPORAL)
    comp_map = {
        "sequential": "SEQUENTIAL",
        "parallel": "PARALLEL",
        "feedback": "FEEDBACK",
        "corecursive": "TEMPORAL",
    }
    gds_comp = GDSCompositionType[comp_map[self.composition_type.value]]

    inputs = [
        GDSInputIR(
            name=i.name,
            metadata={
                "input_type": i.input_type.value,
                "schema_hint": i.schema_hint,
                "shape": i.shape,
            },
        )
        for i in self.inputs
    ]

    return SystemIR(
        name=self.name,
        blocks=blocks,
        wirings=wirings,
        inputs=inputs,
        composition_type=gds_comp,
        source=self.source_canvas,
    )

Bases: HierarchyNodeIR

OGS hierarchy node — extends GDS with CORECURSIVE composition type.

Inherits id, name, block_name, exit_condition, and children from GDS. Overrides composition_type to use the OGS enum which includes CORECURSIVE (mapped to GDS TEMPORAL).

The game_name property is a backwards-compatible alias for block_name (inherited from GDS).

Source code in packages/gds-games/ogs/ir/models.py
class HierarchyNodeIR(_GDSHierarchyNodeIR):
    """OGS hierarchy node — extends GDS with CORECURSIVE composition type.

    Inherits ``id``, ``name``, ``block_name``, ``exit_condition``, and
    ``children`` from GDS. Overrides ``composition_type`` to use the OGS
    enum which includes CORECURSIVE (mapped to GDS TEMPORAL).

    The ``game_name`` property is a backwards-compatible alias for
    ``block_name`` (inherited from GDS).
    """

    composition_type: CompositionType | None = None  # type: ignore[assignment]  # OGS enum (has CORECURSIVE)
    children: list[HierarchyNodeIR] = Field(default_factory=list)  # type: ignore[assignment]

    @property
    def game_name(self) -> str | None:
        """Backwards-compatible alias for ``block_name``."""
        return self.block_name

game_name property

Backwards-compatible alias for block_name.

Serialization

Bases: BaseModel

Top-level IR document containing one or more patterns.

Source code in packages/gds-games/ogs/ir/serialization.py
class IRDocument(BaseModel):
    """Top-level IR document containing one or more patterns."""

    version: str = "1.0"
    patterns: list[PatternIR]
    metadata: IRMetadata

Serialize an IR document to JSON.

Source code in packages/gds-games/ogs/ir/serialization.py
def save_ir(doc: IRDocument, path: Path) -> None:
    """Serialize an IR document to JSON."""
    path.write_text(doc.model_dump_json(indent=2))

Deserialize an IR document from JSON.

Source code in packages/gds-games/ogs/ir/serialization.py
def load_ir(path: Path) -> IRDocument:
    """Deserialize an IR document from JSON."""
    return IRDocument.model_validate_json(path.read_text())