Repository navigation
feat(ml): single-source detector class schema with generated backend and frontend maps - #23
Merged
Merged
Conversation
…tested, incomplete
…generated backend and frontend maps Adds the transistor-first vocabulary (tier A: NMOS PMOS VDD GND INPUT_PORT OUTPUT_PORT JUNCTION + 7 gates; tier B analog), legacy aliases for old 12-class weights, a generator and check mode, data.yaml rendering, contract tests (pytest + Jest), and updated docs.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for digisim ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
DigiSim is a neglected project. Pull up the latest changes in Linux. It is high time to start training the model for it. I have not been able to provide the data. Figure out, get the data, train a model, make improvements and fix that. Do not come to me until you absolutely need me.
Context: a scout report found that the only trained detector uses 12 gate-era classes and detects nothing on the transistor-first schematics the app now uses, that the transistor-level training data does not exist yet, and that the wire/net tracing assumes left-to-right gates. The work was split into tasks T1-T11; this change is T1, class schema and contracts: create ml/classes.yaml as the single source of truth for detector classes (class name, tier, YOLO id, frontend node type, terminal names, default size); generate backend/pipeline/detector.py CLASS_TO_NODE_TYPE, the frontend YOLO_CLASS_MAP, and data.yaml from it; update agent_docs/ml-pipeline.md (class list, phases, thresholds) to the new transistor-first vocabulary. Acceptance: one source of truth; a Jest test and a pytest test assert the backend and frontend maps equal the YAML; docs updated; legacy gate-era class names kept as aliases so old weights still load.
What Changed
ml/classes.yamlas the single source of truth for detector classes (name, tier, YOLO id, frontend node type, terminals, default size) with a transistor-first vocabulary (NMOS, PMOS, VDD, GND, ports, junction, gates, plus tier B analog parts). Legacy gate-era names (SWITCH,INPUT,OUTPUT,LED) are kept as aliases, and the 12-class legacy weight order is recorded so old weights still decode. Addedml/class_schema.pyto validate the YAML, generatebackend/pipeline/class_map.pyandfrontend/src/logic/vision/yoloClassMap.generated.ts, render the datasetdata.yaml, and check for stale generated files.backend/data_gennow reads class names from this schema.backend/pipeline/detector.pynow takesCLASS_TO_NODE_TYPE(plusCLASS_NAMESandCLASS_ALIASES) from the generated map. Infrontend/src/logic/vision/yoloDetector.ts,YOLO_CLASS_MAPnow comes from the generated file. Output decoding is extracted into an exporteddecodeYoloOutputthat picks the class table by model class count (legacy 12-class order vs canonical). This replaces the old index-modulo lookup over map keys and fixes they2bounding-box bug, which usedcx + h / 2instead ofcy + h / 2.CircuitNodeTypegains the transistor and analog node types.backend/test_class_schema.py) and Jest tests (yoloClassMap.test.ts, updatedyoloDetector.test.ts) asserting the backend and frontend maps equal the YAML. Addedpyyaml(backend) andjs-yaml(frontend dev) dependencies, and updatedagent_docs/ml-pipeline.md,README.md,testing.md, and.claude/agents/model.mdfor the new class list, phases, and regenerate workflow.Risk Assessment
✅ Low: The change is a well-bounded schema and generator refactor. The generated backend and frontend maps are checked against ml/classes.yaml by pytest and Jest contract tests. Legacy gate-era names stay as aliases, and the 12-class legacy decode order is handled. I found no new defects. Declined round 1 and 2 items (netlistGenerator junction handling, metadata-based class table) are not re-raised.
Testing
I ran the schema check and generator CLI, the backend pytest contract file, and the frontend vision Jest suites. I also made a deliberate YAML edit to confirm the check, pytest and Jest all fail on drift, then restored it. A real GraphBuilder run with legacy gate-era and new transistor-first class names mapped every one to the right node type. Those four scenarios passed live. The legacy 12-class ONNX decode scenario was covered only by a Jest unit test, so it is marked untested. No UI changed, so there are no screenshots. The Jest run printed jsdom getContext console noise from the existing ONNX decode tests, but those suites pass.
Evidence: Drift guard transcript
Evidence: Legacy name to node type via real GraphBuilder
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
backend/pipeline/detector.py:54- The change adds a case-insensitive class-name resolver on both sides,resolve_class_name(backend/pipeline/detector.py) andresolveYoloClassName(frontend/src/logic/vision/yoloDetector.ts). Neither has a production caller; only tests call them. Production code does exact-match lookups:graph_builder.pyusesCLASS_TO_NODE_TYPE.get(det.class_name, ...)and the decoder usesYOLO_CLASS_MAP[className]. The intent only requires that legacy gate-era names stay as aliases so old weights still load. That is already met by the alias entries inCLASS_TO_NODE_TYPEandYOLO_CLASS_MAP, plus the legacy-order table. The case-insensitive resolution is unrequired. It also suggests a normalisation that the real call sites never perform, and the lowercase map keys the old frontend map had are gone. The smallest honest remedy is to remove both resolvers and their tests (test_legacy_names_resolve_for_old_weights, the 'resolves legacy gate-era names' Jest case). Keep the alias-map assertions, which already prove legacy names resolve.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
cd ml && uv run python class_schema.py check(rc=0, generated files fresh)cd ml && uv run python class_schema.py data-yaml --path /tmp/ds(tier A data.yaml, nc=14, canonical id order)cd backend && uv run pytest test_class_schema.py -q(5 passed)cd frontend && CI=true npm test -- --watchAll=false src/logic/vision(3 suites, 14 tests passed, including yoloClassMap.test.ts and the legacy 12-class decode test in yoloDetector.test.ts)Adversarial drift: temporarily changed a node_type in ml/classes.yaml;class_schema.py checkexited 1, pytest failed 2 tests, Jest failed the map test; YAML restored with git checkoutLive GraphBuilder run with legacy-named detections (SWITCH, INPUT, LED, AND...) plus new classes (NMOS, VDD, GND): all mapped to the expected node types✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.