Skip to content

feat(ml): single-source detector class schema with generated backend and frontend maps - #23

Merged
Mani212005 merged 6 commits into
mainfrom
fm/digisim-t1-classes
Nov 17, 2026
Merged

Mani212005 merged 6 commits into
mainfrom
fm/digisim-t1-classes

Conversation

@Mani212005

Copy link
Copy Markdown
Owner

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

  • Added ml/classes.yaml as 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. Added ml/class_schema.py to validate the YAML, generate backend/pipeline/class_map.py and frontend/src/logic/vision/yoloClassMap.generated.ts, render the dataset data.yaml, and check for stale generated files. backend/data_gen now reads class names from this schema.
  • backend/pipeline/detector.py now takes CLASS_TO_NODE_TYPE (plus CLASS_NAMES and CLASS_ALIASES) from the generated map. In frontend/src/logic/vision/yoloDetector.ts, YOLO_CLASS_MAP now comes from the generated file. Output decoding is extracted into an exported decodeYoloOutput that 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 the y2 bounding-box bug, which used cx + h / 2 instead of cy + h / 2. CircuitNodeType gains the transistor and analog node types.
  • Added a pytest test (backend/test_class_schema.py) and Jest tests (yoloClassMap.test.ts, updated yoloDetector.test.ts) asserting the backend and frontend maps equal the YAML. Added pyyaml (backend) and js-yaml (frontend dev) dependencies, and updated agent_docs/ml-pipeline.md, README.md, testing.md, and .claude/agents/model.md for 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.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Generated backend/frontend maps and data.yaml are in sync with ml/classes.yaml (schema check CLI) ✅ pass live class_schema.py check rc=0; data-yaml output lists 14 tier A classes in id order
Backend pytest and frontend Jest contract tests assert the maps equal the YAML ✅ pass live pytest 5 passed; Jest vision suites 14 passed
Adversarial: editing the YAML without regenerating is caught by the check CLI, pytest and Jest ✅ pass live drift.txt: check rc=1, 2 pytest failures, 1 Jest failure
Legacy gate-era names from old weights (SWITCH, INPUT, LED, AND...) still resolve in the real backend graph builder ✅ pass live backend_legacy_graph.txt
Frontend decodes a legacy 12-class ONNX output with the gate-era index order ⏸️ untested no The prior payload recorded this only as a Jest unit test (yoloDetector.test.ts), not a run against the live product in a browser, so it did not establish a live result. No trained legacy ONNX model is…
Evidence: Drift guard transcript
stale: backend/pipeline/class_map.py (run: cd ml && uv run python class_schema.py generate)
stale: frontend/src/logic/vision/yoloClassMap.generated.ts (run: cd ml && uv run python class_schema.py generate)
check rc=1
E         Left contains 2 more items, first extra item: PosixPath('~/.no-mistakes/worktrees/d6f1543da1b7/01M7NEMS62EE70Y0R1QXZK4CNM/backend/pipeline/class_map.py')
E         Use -v to get more diff

test_class_schema.py:66: AssertionError
=========================== short test summary info ============================
FAILED test_class_schema.py::test_backend_map_equals_yaml - AssertionError: a...
FAILED test_class_schema.py::test_generated_files_are_fresh - AssertionError:...
2 failed, 3 passed in 2.66s
FAIL src/logic/vision/yoloClassMap.test.ts
    ✕ maps every canonical class and every legacy alias to the YAML node type (3 ms)
Tests:       1 failed, 5 passed, 6 total
Evidence: Legacy name to node type via real GraphBuilder
AND -> andGate
OR -> orGate
NOT -> notGate
NAND -> nandGate
NOR -> norGate
XOR -> xorGate
XNOR -> xnorGate
SWITCH -> input
INPUT -> input
OUTPUT -> output
LED -> output
NMOS -> nmos
VDD -> vsource
GND -> ground

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) and resolveYoloClassName (frontend/src/logic/vision/yoloDetector.ts). Neither has a production caller; only tests call them. Production code does exact-match lookups: graph_builder.py uses CLASS_TO_NODE_TYPE.get(det.class_name, ...) and the decoder uses YOLO_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 in CLASS_TO_NODE_TYPE and YOLO_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.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Generated backend/frontend maps and data.yaml are in sync with ml/classes.yaml (schema check CLI) ✅ pass live class_schema.py check rc=0; data-yaml output lists 14 tier A classes in id order
Backend pytest and frontend Jest contract tests assert the maps equal the YAML ✅ pass live pytest 5 passed; Jest vision suites 14 passed
Adversarial: editing the YAML without regenerating is caught by the check CLI, pytest and Jest ✅ pass live drift.txt: check rc=1, 2 pytest failures, 1 Jest failure
Legacy gate-era names from old weights (SWITCH, INPUT, LED, AND...) still resolve in the real backend graph builder ✅ pass live backend_legacy_graph.txt
Frontend decodes a legacy 12-class ONNX output with the gate-era index order ⏸️ untested no The prior payload recorded this only as a Jest unit test (yoloDetector.test.ts), not a run against the live product in a browser, so it did not establish a live result. No trained legacy ONNX model is…
  • 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 check exited 1, pytest failed 2 tests, Jest failed the map test; YAML restored with git checkout
  • Live 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.

…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.
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
digisim Ready Ready Preview Nov 17, 2026 7:20pm UTC

@netlify

netlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for digisim ready!

Name Link
🔨 Latest commit cd2e23e
🔍 Latest deploy log https://app.netlify.com/projects/digisim/deploys/6afca865947f246e9699070b
😎 Deploy Preview https://deploy-preview-23--digisim.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Mani212005
Mani212005 merged commit b8951ae into main Nov 17, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
Preview — cd2e23ed Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant