Skip to content

gds_business.cld.compile

Compiler: CausalLoopModel → GDSSpec / SystemIR.

Semantic Types

Public Functions

Compile a CausalLoopModel into a GDSSpec.

Registers: types, spaces, blocks, wirings. No entities (stateless).

Source code in packages/gds-business/gds_business/cld/compile.py
def compile_cld(model: CausalLoopModel) -> GDSSpec:
    """Compile a CausalLoopModel into a GDSSpec.

    Registers: types, spaces, blocks, wirings. No entities (stateless).
    """
    spec = GDSSpec(name=model.name, description=model.description)

    # 1. Register types
    spec.collect(SignalType)

    # 2. Register spaces
    spec.collect(SignalSpace)

    # 3. Register blocks (all Policy)
    for var in model.variables:
        spec.register_block(_build_variable_block(var, model))

    # 4. Register spec wirings
    all_block_names = [b.name for b in spec.blocks.values()]
    wires: list[Wire] = []

    for link in model.links:
        wires.append(
            Wire(source=link.source, target=link.target, space="CLD SignalSpace")
        )

    if wires:
        spec.register_wiring(
            SpecWiring(
                name=f"{model.name} Wiring",
                block_names=all_block_names,
                wires=wires,
                description=f"Auto-generated wiring for CLD {model.name!r}",
            )
        )

    return spec

Compile a CausalLoopModel directly to SystemIR.

Builds the composition tree and delegates to GDS compile_system().

Source code in packages/gds-business/gds_business/cld/compile.py
def compile_cld_to_system(model: CausalLoopModel) -> SystemIR:
    """Compile a CausalLoopModel directly to SystemIR.

    Builds the composition tree and delegates to GDS compile_system().
    """
    root = _build_composition_tree(model)
    return compile_system(model.name, root)