feat(spatial): 第一个真实 provider——KiCad 网表到 Observation,零依赖

This commit is contained in:
liuhuajie committed 2026-12-04 00:45:33 +08:00
1 parent 29491cae82
commit f907d57b6a
5 files changed
+352 -2

No files matched your search

+36 -2
View File
@@ -13,7 +13,7 @@ import os
import sys
from . import checker, generator
from .schema import FullState
from .schema import FullState, Query
def _load_config(path: str) -> dict:
@@ -223,12 +223,46 @@ def check_scope_agrees(n: int = 24) -> bool:
return True
def check_netlist_provider() -> bool:
"""The netlist provider must reproduce membership, and must not over-claim.
Built from the same membership it is checked against, so "the edges are
right" is a construction. What this pins is the mapping's *shape*: one
entity per (ref, pin), pairwise conduct inside a net, nothing invented
across nets, and a single-node net that stays isolated instead of being
silently promoted to "connected to something".
"""
from .providers import kicad_netlist
path = os.path.join(os.path.dirname(__file__), "providers", "fixtures", "tiny.net")
nl = kicad_netlist.load(path)
obs = kicad_netlist.to_observation(nl)
want = {"comp": 3, "node": 6, "net": 3, "edge": 4}
got = {"comp": len(nl.comps), "node": len(nl.nodes()), "net": len(nl.nets),
"edge": len(obs.edges)}
if got != want:
return _fail(f"netlist mapping changed: {got} != {want}")
if checker.withheld_flag(obs):
return _fail("a complete netlist reported itself as incomplete")
pairs = [("R1.2", "U1.1", True), # same net
("R1.1", "R1.2", False), # same part, different nets
("U1.7", "R1.2", False)] # single-node net: connected to nothing
for a, b, want_ans in pairs:
got_ans = checker.evaluate(obs.entities, obs.edges,
Query(kind="connection", a=a, b=b))
if got_ans is not want_ans:
return _fail(f"netlist says {a}-{b} is {got_ans}, expected {want_ans}")
print("ok netlist provider: 3 comps / 6 pads / 4 conduct edges, "
"no cross-net edge, isolated pin stays isolated")
return True
def cmd_smoke(args) -> int:
cfg = _load_config(args.config)
print(f"config {args.config} out {cfg['out_dir']}")
results = [check_splits(cfg), check_determinism(), check_labels(),
check_insufficient(), check_invariances(), check_cross_family_digest(),
check_extract_contacts(), check_scope_agrees()]
check_extract_contacts(), check_scope_agrees(),
check_netlist_provider()]
# one update, then interrupt and resume: the step counter must advance
from . import train as trainer