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
|