Skip to content

feat(backend): net tracing v2 with pin assignment and schema 2 exporter - #27

Merged
Mani212005 merged 4 commits into
mainfrom
fm/digisim-t8-nettrace
Nov 17, 2026
Merged

Mani212005 merged 4 commits into
mainfrom
fm/digisim-t8-nettrace

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: the scout report at ~/linux-fleet-home/data/digisim-ml-scout/report.md 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. It split the work into tasks T1-T11 (section 5); this task is one of them. T1 (class schema ml/classes.yaml), T2 (synthetic generator v2 with netlist ground truth) and T6 (evaluation harness v2 with end-to-end net and truth-table metrics) are already merged on the default branch.

This task is the report's T8 - Net tracing v2 and exporter. Its substance: the wire/net step (backend/pipeline/graph_builder.py, wire_extractor.py) assumes left-to-right gates with an output on the right and inputs on the left, but transistors have D/G/S/B terminals and no direction, so the graph builder and exporter must be rewritten as a net-based classical CV stage (still no neural net): binarise and mask out detected symbol bodies while keeping lead ends attached; skeletonise and build a pixel graph whose connected components are candidate nets; at a degree-4 skeleton node, connect only if a JUNCTION detection sits on it, otherwise split it into two straight-through wires (crossover); pin assignment where each symbol's lead endpoints at its box boundary become pins, with an orientation head (or keypoints) deciding which MOSFET pin is D, G, S (B optional) and a single pin for VDD/GND/ports; emit nets (sets of pins) rather than directed gate edges, with an exporter that turns nets into connections between pins using the app's t:/s: handles, supply symbols becoming vsource/ground nodes, and types nmos pmos vsource ground input output plus library cells for gate symbols; attach OCR text labels to the nearest port/net for naming; make the pixel-absolute thresholds (min_line_length, max_line_gap, min_component_diag, NET_JOIN_DISTANCE) scale with image and symbol size; remove the gate-direction heuristics (graph_builder.py right-half-is-output / left-half-is-input and top/bottom-half port choice). Acceptance in the report: on 300 T2 samples with ground-truth nets, net F1 >= 0.90 and netlist exact-match >= 70% on clean renders and >= 50% on hand-drawn-style renders; on the T3 round-trip set the reconstructed circuit gives the same truth table as the source in >= 80% of cases; tests cover crossover with/without dot, branching supply rail, rotated/mirrored transistor, 3 vs 4 terminal symbols; runtime < 2 s per image on this CPU. The frontend import integration (updating importCircuit for transistor handles) is the separate T9 task.

What Changed

  • Replaced the left-to-right gate wire stage (wire_extractor.py, directional graph_builder.py) with a classical-CV net tracer in backend/pipeline/ (ink.py, skeleton_graph.py, net_tracer.py, pin_assignment.py, label_attach.py, trace_types.py). It binarises ink, erases symbol bodies, skeletonises wires into a pixel graph, and treats a degree-4 node as a connection only when a JUNCTION detection sits on it (otherwise a crossover). Thresholds scale with stroke width and median symbol size. Pins come from detector keypoints or a geometry fallback with orientation estimation and MOSFET D/G/S resolution. OCR text is attached to ports and nets. GraphBuilder now builds an undirected component/net graph, and /detect_circuit in app.py uses the new NetTracer.
  • CircuitExporter now emits schema_version 2 (per-component pins, orientation, library cell, nets and ReactFlow edges with t:/s: handles) alongside the legacy connections list. class_map.py and ml/class_schema.py gain a generated CLASS_TERMINALS map. frontend/src/types/api.ts adds the matching optional types, and scikit-image is added to the backend dependencies.
  • Added backend/test_net_tracer.py and backend/bench_tracing.py (scores traced nets against T2 synthetic ground truth). ml/eval_netlist.py now also accepts the T2 pin-map netlist shape and object-form nets, with test updates. Docs (README.md, agent_docs/ml-pipeline.md, .claude/agents/model.md, testing.md) are updated.

Risk Assessment

✅ Low: The two round-2 fixes (downscaled paper-background estimate in ink_mask, and skipping pass-through repair when a symbol has partial keypoints) match the recorded instructions and behave correctly. A timing probe of the full tracer on scenes up to 2560 px wide stayed at 0.23 s, so no performance concern remains.

Testing

I generated 300 synthetic circuits (seed 1) and ran the bench with truth-table checking in keypoint and geometry modes. Keypoint mode gave net F1 0.9995 clean and 0.9989 hand-drawn, with exact match 99.3% and 98.7% and p95 runtime about 0.16 s. Geometry fallback gave exact match 88.7% clean and 87.2% hand-drawn, with truth-table match about 92%. The bench scores come from perturbed ground-truth detections, so they bound the tracer rather than the end-to-end photo pipeline. I then ran the real Flask app over HTTP with a stand-in detector. Three transistor circuits returned schema 2 output whose net sizes and component types matched ground truth, in 0.07 to 0.18 s. A 4000x3000 upload traced correctly in about 0.8 s, which covers the large-image fix. Dropping keypoints did not merge drain and source nets. Missing image gave 400, undecodable image gave 400, and no auth cookie gave 401. The targeted unit tests for crossover with and without a dot, branching rails, rotated and mirrored transistors, and 3 versus 4 terminal symbols passed, but they ran the tracer directly on rendered images and were not driven through the running service, so that scenario is recorded as untested. The T3 round-trip criterion is deferred, as the recorded decision says. The new class set has no trained detector yet, so nothing here exercised real detections or the frontend. No UI changed, so there are no screenshots. The frontend/node_modules install and all temp data were cleaned or are gitignored, and the working tree is clean.

  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
On 300 T2 samples, the bench meets net F1 >= 0.90 and exact match >= 70% clean and >= 50% hand-drawn, in keypoint and geometry modes ✅ pass live bench_truth_table.txt
Runtime stays under 2 s per image (bench p95 about 0.16 s, max 0.34 s) ✅ pass live bench_truth_table.txt
POST a transistor schematic to /detect_circuit and get schema 2 nets, pins and t:/s: edges that match ground truth ✅ pass live endpoint_runs.txt, endpoint_000000.json
A 4000x3000 camera-size upload traces correctly in under 2 s (about 0.8 s) ✅ pass live endpoint_runs.txt
Adversarial: with only the g keypoint kept, or d/s keypoints dropped, drain and source nets are not merged by the pass-through repair ✅ pass live endpoint_partial_keypoints.txt, unit_scenarios.txt
Error handling: missing image gives 400, undecodable image gives 400, no auth cookie gives 401 ✅ pass live endpoint_partial_keypoints.txt
Crossover with or without a dot, branching supply rail, rotated or mirrored transistor, and 3 vs 4 terminal symbols behave correctly ⏸️ untested no The prior payload recorded this only as 50 passing unit tests in test_net_tracer.py that run the tracer on rendered images, with live=false. It did not establish a live result through the running serv…
On the T3 round-trip set, the reconstructed circuit gives the same truth table as the source in >= 80% of cases ⏸️ untested no The T3 screenshot round-trip set does not exist yet. The recorded user decision defers this criterion. It is not a failure of this change.
Evidence: Bench with truth tables (300 T2 samples, both pin modes)
# Net tracing v2 bench

Perturbation: Perturbation(box_sigma=0.03, keypoint_sigma=0.03, junction_miss=0.02, junction_sigma=0.1)

| pin mode | domain | circuits | net P | net R | net F1 | exact match | truth-table equiv. | gate |
|---|---|---|---|---|---|---|---|---|
| keypoints | clean | 151 | 1.0000 | 0.9990 | 0.9995 | 0.993 | 0.993 | pass |
| keypoints | hand_drawn | 149 | 1.0000 | 0.9977 | 0.9989 | 0.987 | 0.987 | pass |
| geometry | clean | 151 | 0.9939 | 0.9856 | 0.9897 | 0.887 | 0.927 | pass |
| geometry | hand_drawn | 149 | 0.9872 | 0.9759 | 0.9816 | 0.872 | 0.919 | pass |

| pin mode | render mode | circuits | net F1 | exact match |
|---|---|---|---|---|
| keypoints | cad | 83 | 1.0000 | 1.000 |
| keypoints | hand | 77 | 1.0000 | 1.000 |
| keypoints | photo | 72 | 0.9976 | 0.972 |
| keypoints | textbook | 68 | 0.9988 | 0.985 |
| geometry | cad | 83 | 0.9946 | 0.928 |
| geometry | hand | 77 | 0.9774 | 0.844 |
| geometry | photo | 72 | 0.9862 | 0.903 |
| geometry | textbook | 68 | 0.9837 | 0.838 |

| pin mode | runtime mean / p95 / max (s) | orientation acc | MOSFET d/s acc | port label acc |
|---|---|---|---|---|
| keypoints | 0.0876 / 0.1596 / 0.3415 | 1.0 | 0.9994 | 1.0 |
| geometry | 0.0782 / 0.1319 / 0.1542 | 0.9848 | 0.9872 | 1.0 |
Evidence: Bench without truth tables
# Net tracing v2 bench

Perturbation: Perturbation(box_sigma=0.03, keypoint_sigma=0.03, junction_miss=0.02, junction_sigma=0.1)

| pin mode | domain | circuits | net P | net R | net F1 | exact match | truth-table equiv. | gate |
|---|---|---|---|---|---|---|---|---|
| keypoints | clean | 151 | 1.0000 | 0.9990 | 0.9995 | 0.993 | n/a | pass |
| keypoints | hand_drawn | 149 | 1.0000 | 0.9977 | 0.9989 | 0.987 | n/a | pass |
| geometry | clean | 151 | 0.9939 | 0.9856 | 0.9897 | 0.887 | n/a | pass |
| geometry | hand_drawn | 149 | 0.9872 | 0.9759 | 0.9816 | 0.872 | n/a | pass |

| pin mode | render mode | circuits | net F1 | exact match |
|---|---|---|---|---|
| keypoints | cad | 83 | 1.0000 | 1.000 |
| keypoints | hand | 77 | 1.0000 | 1.000 |
| keypoints | photo | 72 | 0.9976 | 0.972 |
| keypoints | textbook | 68 | 0.9988 | 0.985 |
| geometry | cad | 83 | 0.9946 | 0.928 |
| geometry | hand | 77 | 0.9774 | 0.844 |
| geometry | photo | 72 | 0.9862 | 0.903 |
| geometry | textbook | 68 | 0.9837 | 0.838 |

| pin mode | runtime mean / p95 / max (s) | orientation acc | MOSFET d/s acc | port label acc |
|---|---|---|---|---|
| keypoints | 0.0766 / 0.1298 / 0.1737 | 1.0 | 0.9994 | 1.0 |
| geometry | 0.0737 / 0.1227 / 0.1412 | 0.9848 | 0.9872 | 1.0 |
Evidence: /detect_circuit runs vs ground truth, including 4000x3000 timing
000000 200 0.18 pred nets [2, 2, 4, 4, 4, 5, 5, 5, 5, 5] gt nets [2, 2, 4, 4, 4, 5, 5, 5, 5, 5]
  types match: True
000010 200 0.07 pred nets [2, 2, 2, 2, 2] gt nets [2, 2, 2, 2, 2]
  types match: True
000011 200 0.16 pred nets [2, 3, 3, 3, 4, 5, 6] gt nets [2, 3, 3, 3, 4, 5, 6]
  types match: True
src 1018 824
big (3000, 4000, 3)
big 200 0.78 comps 17 nets [2, 2, 4, 4, 4, 5, 5, 5, 5, 5]
big 200 0.77 comps 17 nets [2, 2, 4, 4, 4, 5, 5, 5, 5, 5]
big 200 0.82 comps 17 nets [2, 2, 4, 4, 4, 5, 5, 5, 5, 5]
Evidence: /detect_circuit with partial or no keypoints and error cases
000000 all keypoints dropped for d,s (geometry fallback per terminal) 200 0.16 nets [1, 1, 1, 2, 2, 5, 5] gt [2, 2, 4, 4, 4, 5, 5, 5, 5, 5] ok warnings []
   pin_source {'keypoints'}
000000 no keypoints at all 200 0.15 nets [2, 2, 4, 4, 4, 5, 5, 5, 5, 5] gt [2, 2, 4, 4, 4, 5, 5, 5, 5, 5] ok warnings []
   pin_source {'geometry'}
000000 only g keypoint kept 200 0.16 nets [1, 1, 1, 2, 2, 5, 5] gt [2, 2, 4, 4, 4, 5, 5, 5, 5, 5] ok warnings []
   pin_source {'keypoints'}
000011 all keypoints dropped for d,s (geometry fallback per terminal) 200 0.16 nets [1, 2, 2, 3, 3, 3] gt [2, 3, 3, 3, 4, 5, 6] ok warnings []
   pin_source {'keypoints'}
000011 no keypoints at all 200 0.15 nets [1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 6] gt [2, 3, 3, 3, 4, 5, 6] ok warnings []
   pin_source {'geometry'}
000011 only g keypoint kept 200 0.16 nets [1, 2, 2, 3, 3, 3] gt [2, 3, 3, 3, 4, 5, 6] ok warnings []
   pin_source {'keypoints'}
no image: 400 {'error': 'No image provided'}
garbage: 400 {'error': 'Could not decode the uploaded image'}
no auth: 401
Evidence: Full /detect_circuit JSON response for sample 000000
{
 "components": [
  {
   "bbox": [
    249.3,
    185.0,
    285.1,
    249.3
   ],
   "class": "PMOS",
   "confidence": 0.894,
   "height": 64.3,
   "id": "MP2",
   "label": "PMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n3",
     "x": 251.4,
     "y": 250.9
    },
    "g": {
     "net": "n1",
     "x": 282.2,
     "y": 218.8
    },
    "s": {
     "net": "n8",
     "x": 250.8,
     "y": 186.1
    }
   },
   "type": "pmos",
   "width": 35.8,
   "x": 249.3,
   "y": 185.0
  },
  {
   "bbox": [
    249.5,
    345.6,
    283.5,
    412.6
   ],
   "class": "NMOS",
   "confidence": 0.709,
   "height": 67.0,
   "id": "MN1",
   "label": "NMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n3",
     "x": 251.1,
     "y": 347.4
    },
    "g": {
     "net": "n1",
     "x": 282.5,
     "y": 378.9
    },
    "s": {
     "net": "n0",
     "x": 250.2,
     "y": 412.0
    }
   },
   "type": "nmos",
   "width": 34.0,
   "x": 249.5,
   "y": 345.6
  },
  {
   "bbox": [
    428.1,
    178.8,
    463.1,
    248.1
   ],
   "class": "PMOS",
   "confidence": 0.903,
   "height": 69.3,
   "id": "MP1",
   "label": "PMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n4",
     "x": 428.0,
     "y": 250.0
    },
    "g": {
     "net": "n2",
     "x": 460.7,
     "y": 218.4
    },
    "s": {
     "net": "n8",
     "x": 430.4,
     "y": 184.6
    }
   },
   "type": "pmos",
   "width": 35.0,
   "x": 428.1,
   "y": 178.8
  },
  {
   "bbox": [
    428.9,
    347.2,
    462.7,
    412.5
   ],
   "class": "NMOS",
   "confidence": 0.928,
   "height": 65.2,
   "id": "MN2",
   "label": "NMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n4",
     "x": 426.4,
     "y": 347.6
    },
    "g": {
     "net": "n2",
     "x": 460.6,
     "y": 378.4
    },
    "s": {
     "net": "n0",
     "x": 427.5,
     "y": 411.9
    }
   },
   "type": "nmos",
   "width": 33.8,
   "x": 428.9,
   "y": 347.2
  },
  {
   "bbox": [
    604.3,
    184.4,
    639.8,
    250.9
   ],
   "class": "PMOS",
   "confidence": 0.632,
   "height": 66.5,
   "id": "MP3",
   "label": "PMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n9",
     "x": 606.6,
     "y": 251.4
    },
    "g": {
     "net": "n1",
     "x": 638.6,
     "y": 217.3
    },
    "s": {
     "net": "n8",
     "x": 606.7,
     "y": 185.3
    }
   },
   "type": "pmos",
   "width": 35.5,
   "x": 604.3,
   "y": 184.4
  },
  {
   "bbox": [
    732.5,
    184.3,
    770.0,
    249.4
   ],
   "class": "PMOS",
   "confidence": 0.684,
   "height": 65.1,
   "id": "MP4",
   "label": "PMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n9",
     "x": 734.9,
     "y": 250.5
    },
    "g": {
     "net": "n4",
     "x": 767.8,
     "y": 217.1
    },
    "s": {
     "net": "n8",
     "x": 734.0,
     "y": 186.0
    }
   },
   "type": "pmos",
   "width": 37.4,
   "x": 732.5,
   "y": 184.3
  },
  {
   "bbox": [
    604.7,
    310.2,
    640.5,
    381.7
   ],
   "class": "PMOS",
   "confidence": 0.958,
   "height": 71.5,
   "id": "MP5",
   "label": "PMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n5",
     "x": 607.2,
     "y": 379.4
    },
    "g": {
     "net": "n3",
     "x": 637.4,
     "y": 348.2
    },
    "s": {
     "net": "n9",
     "x": 606.2,
     "y": 316.0
    }
   },
   "type": "pmos",
   "width": 35.9,
   "x": 604.7,
   "y": 310.2
  },
  {
   "bbox": [
    732.1,
    312.7,
    768.9,
    382.8
   ],
   "class": "PMOS",
   "confidence": 0.746,
   "height": 70.1,
   "id": "MP6",
   "label": "PMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n5",
     "x": 735.4,
     "y": 378.0
    },
    "g": {
     "net": "n2",
     "x": 766.2,
     "y": 348.3
    },
    "s": {
     "net": "n9",
     "x": 735.9,
     "y": 314.4
    }
   },
   "type": "pmos",
   "width": 36.8,
   "x": 732.1,
   "y": 312.7
  },
  {
   "bbox": [
    604.9,
    476.9,
    640.2,
    543.3
   ],
   "class": "NMOS",
   "confidence": 0.883,
   "height": 66.4,
   "id": "MN4",
   "label": "NMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n5",
     "x": 605.8,
     "y": 476.4
    },
    "g": {
     "net": "n1",
     "x": 639.4,
     "y": 506.6
    },
    "s": {
     "net": "n7",
     "x": 605.8,
     "y": 541.3
    }
   },
   "type": "nmos",
   "width": 35.3,
   "x": 604.9,
   "y": 476.9
  },
  {
   "bbox": [
    604.8,
    573.9,
    639.0,
    639.5
   ],
   "class": "NMOS",
   "confidence": 0.7,
   "height": 65.6,
   "id": "MN5",
   "label": "NMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n7",
     "x": 606.6,
     "y": 574.9
    },
    "g": {
     "net": "n4",
     "x": 638.6,
     "y": 605.0
    },
    "s": {
     "net": "n0",
     "x": 604.3,
     "y": 640.1
    }
   },
   "type": "nmos",
   "width": 34.3,
   "x": 604.8,
   "y": 573.9
  },
  {
   "bbox": [
    733.0,
    474.8,
    769.2,
    544.5
   ],
   "class": "NMOS",
   "confidence": 0.927,
   "height": 69.8,
   "id": "MN3",
   "label": "NMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n5",
     "x": 735.2,
     "y": 476.7
    },
    "g": {
     "net": "n3",
     "x": 766.8,
     "y": 509.5
    },
    "s": {
     "net": "n6",
     "x": 734.1,
     "y": 542.0
    }
   },
   "type": "nmos",
   "width": 36.2,
   "x": 733.0,
   "y": 474.8
  },
  {
   "bbox": [
    732.1,
    573.4,
    766.4,
    644.9
   ],
   "class": "NMOS",
   "confidence": 0.979,
   "height": 71.5,
   "id": "MN6",
   "label": "NMOS",
   "library_cell": null,
   "orientation": {
    "mirror": true,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "d": {
     "net": "n6",
     "x": 734.1,
     "y": 572.3
    },
    "g": {
     "net": "n2",
     "x": 768.1,
     "y": 605.0
    },
    "s": {
     "net": "n0",
     "x": 734.6,
     "y": 637.9
    }
   },
   "type": "nmos",
   "width": 34.3,
   "x": 732.1,
   "y": 573.4
  },
  {
   "bbox": [
    96.5,
    208.5,
    139.2,
    227.2
   ],
   "class": "INPUT_PORT",
   "confidence": 0.795,
   "height": 18.8,
   "id": "IN1",
   "label": "A",
   "library_cell": null,
   "orientation": {
    "mirror": false,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "out": {
     "net": "n1",
     "x": 137.2,
     "y": 217.6
    }
   },
   "type": "input",
   "width": 42.6,
   "x": 96.5,
   "y": 208.5
  },
  {
   "bbox": [
    95.7,
    597.2,
    137.5,
    615.5
   ],
   "class": "INPUT_PORT",
   "confidence": 0.715,
   "height": 18.3,
   "id": "IN2",
   "label": "B",
   "library_cell": null,
   "orientation": {
    "mirror": false,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "out": {
     "net": "n2",
     "x": 137.3,
     "y": 606.2
    }
   },
   "type": "input",
   "width": 41.8,
   "x": 95.7,
   "y": 597.2
  },
  {
   "bbox": [
    878.8,
    418.8,
    921.4,
    437.1
   ],
   "class": "OUTPUT_PORT",
   "confidence": 0.93,
   "height": 18.3,
   "id": "OUT1",
   "label": "OUT",
   "library_cell": null,
   "orientation": {
    "mirror": false,
    "rotation": 0
   },
   "pin_source": "keypoints",
   "pins": {
    "a": {
     "

... [2106 bytes truncated] ...

: 622.6,
   "y": 510.1
  },
  {
   "class": "NMOS",
   "confidence": 0.7,
   "height": 65.6,
   "width": 34.3,
   "x": 621.9,
   "y": 606.7
  },
  {
   "class": "NMOS",
   "confidence": 0.927,
   "height": 69.8,
   "width": 36.2,
   "x": 751.1,
   "y": 509.7
  },
  {
   "class": "NMOS",
   "confidence": 0.979,
   "height": 71.5,
   "width": 34.3,
   "x": 749.2,
   "y": 609.1
  },
  {
   "class": "INPUT_PORT",
   "confidence": 0.795,
   "height": 18.8,
   "width": 42.6,
   "x": 117.9,
   "y": 217.8
  },
  {
   "class": "INPUT_PORT",
   "confidence": 0.715,
   "height": 18.3,
   "width": 41.8,
   "x": 116.6,
   "y": 606.3
  },
  {
   "class": "OUTPUT_PORT",
   "confidence": 0.93,
   "height": 18.3,
   "width": 42.6,
   "x": 900.1,
   "y": 427.9
  },
  {
   "class": "VDD",
   "confidence": 0.844,
   "height": 21.2,
   "width": 17.8,
   "x": 250.1,
   "y": 111.2
  },
  {
   "class": "GND",
   "confidence": 0.985,
   "height": 29.6,
   "width": 21.6,
   "x": 250.7,
   "y": 715.6
  },
  {
   "class": "JUNCTION",
   "confidence": 0.796,
   "height": 13.5,
   "width": 13.9,
   "x": 250.0,
   "y": 153.5
  },
  {
   "class": "JUNCTION",
   "confidence": 0.682,
   "height": 15.4,
   "width": 11.7,
   "x": 606.1,
   "y": 153.2
  },
  {
   "class": "JUNCTION",
   "confidence": 0.836,
   "height": 11.1,
   "width": 12.1,
   "x": 250.0,
   "y": 446.5
  },
  {
   "class": "JUNCTION",
   "confidence": 0.774,
   "height": 12.6,
   "width": 11.5,
   "x": 249.6,
   "y": 670.4
  },
  {
   "class": "JUNCTION",
   "confidence": 0.751,
   "height": 16.4,
   "width": 16.5,
   "x": 604.4,
   "y": 670.3
  },
  {
   "class": "JUNCTION",
   "confidence": 0.712,
   "height": 9.8,
   "width": 16.6,
   "x": 250.9,
   "y": 315.6
  },
  {
   "class": "JUNCTION",
   "confidence": 0.902,
   "height": 10.1,
   "width": 11.9,
   "x": 669.8,
   "y": 428.7
  },
  {
   "class": "JUNCTION",
   "confidence": 0.823,
   "height": 13.8,
   "width": 13.8,
   "x": 314.6,
   "y": 217.7
  },
  {
   "class": "JUNCTION",
   "confidence": 0.88,
   "height": 12.9,
   "width": 13.2,
   "x": 670.3,
   "y": 218.0
  },
  {
   "class": "JUNCTION",
   "confidence": 0.809,
   "height": 12.5,
   "width": 12.7,
   "x": 314.6,
   "y": 281.7
  },
  {
   "class": "JUNCTION",
   "confidence": 0.93,
   "height": 12.4,
   "width": 14.6,
   "x": 428.0,
   "y": 282.8
  },
  {
   "class": "JUNCTION",
   "confidence": 0.834,
   "height": 11.7,
   "width": 11.4,
   "x": 492.2,
   "y": 282.8
  },
  {
   "class": "JUNCTION",
   "confidence": 0.854,
   "height": 17.2,
   "width": 13.8,
   "x": 492.8,
   "y": 379.8
  },
  {
   "class": "JUNCTION",
   "confidence": 0.75,
   "height": 12.6,
   "width": 12.2,
   "x": 493.0,
   "y": 605.9
  },
  {
   "class": "JUNCTION",
   "confidence": 0.723,
   "height": 14.4,
   "width": 12.0,
   "x": 606.0,
   "y": 282.3
  },
  {
   "class": "JUNCTION",
   "confidence": 0.894,
   "height": 14.2,
   "width": 15.0,
   "x": 735.1,
   "y": 281.2
  },
  {
   "class": "JUNCTION",
   "confidence": 0.632,
   "height": 11.3,
   "width": 13.2,
   "x": 605.9,
   "y": 412.0
  },
  {
   "class": "JUNCTION",
   "confidence": 0.636,
   "height": 13.3,
   "width": 19.6,
   "x": 735.6,
   "y": 411.2
  },
  {
   "class": "JUNCTION",
   "confidence": 0.957,
   "height": 11.9,
   "width": 16.1,
   "x": 734.5,
   "y": 428.4
  }
 ],
 "edges": [
  {
   "id": "e0",
   "source": "GND1",
   "sourceHandle": "s:gnd",
   "target": "MN1",
   "targetHandle": "t:s"
  },
  {
   "id": "e1",
   "source": "GND1",
   "sourceHandle": "s:gnd",
   "target": "MN2",
   "targetHandle": "t:s"
  },
  {
   "id": "e2",
   "source": "GND1",
   "sourceHandle": "s:gnd",
   "target": "MN5",
   "targetHandle": "t:s"
  },
  {
   "id": "e3",
   "source": "GND1",
   "sourceHandle": "s:gnd",
   "target": "MN6",
   "targetHandle": "t:s"
  },
  {
   "id": "e4",
   "source": "IN1",
   "sourceHandle": null,
   "target": "MN1",
   "targetHandle": "t:g"
  },
  {
   "id": "e5",
   "source": "IN1",
   "sourceHandle": null,
   "target": "MN4",
   "targetHandle": "t:g"
  },
  {
   "id": "e6",
   "source": "IN1",
   "sourceHandle": null,
   "target": "MP2",
   "targetHandle": "t:g"
  },
  {
   "id": "e7",
   "source": "IN1",
   "sourceHandle": null,
   "target": "MP3",
   "targetHandle": "t:g"
  },
  {
   "id": "e8",
   "source": "IN2",
   "sourceHandle": null,
   "target": "MN2",
   "targetHandle": "t:g"
  },
  {
   "id": "e9",
   "source": "IN2",
   "sourceHandle": null,
   "target": "MN6",
   "targetHandle": "t:g"
  },
  {
   "id": "e10",
   "source": "IN2",
   "sourceHandle": null,
   "target": "MP1",
   "targetHandle": "t:g"
  },
  {
   "id": "e11",
   "source": "IN2",
   "sourceHandle": null,
   "target": "MP6",
   "targetHandle": "t:g"
  },
  {
   "id": "e12",
   "source": "MN1",
   "sourceHandle": "s:d",
   "target": "MN3",
   "targetHandle": "t:g"
  },
  {
   "id": "e13",
   "source": "MN1",
   "sourceHandle": "s:d",
   "target": "MP2",
   "targetHandle": "t:d"
  },
  {
   "id": "e14",
   "source": "MN1",
   "sourceHandle": "s:d",
   "target": "MP5",
   "targetHandle": "t:g"
  },
  {
   "id": "e15",
   "source": "MN2",
   "sourceHandle": "s:d",
   "target": "MN5",
   "targetHandle": "t:g"
  },
  {
   "id": "e16",
   "source": "MN2",
   "sourceHandle": "s:d",
   "target": "MP1",
   "targetHandle": "t:d"
  },
  {
   "id": "e17",
   "source": "MN2",
   "sourceHandle": "s:d",
   "target": "MP4",
   "targetHandle": "t:g"
  },
  {
   "id": "e18",
   "source": "MN3",
   "sourceHandle": "s:d",
   "target": "MN4",
   "targetHandle": "t:d"
  },
  {
   "id": "e19",
   "source": "MN3",
   "sourceHandle": "s:d",
   "target": "MP5",
   "targetHandle": "t:d"
  },
  {
   "id": "e20",
   "source": "MN3",
   "sourceHandle": "s:d",
   "target": "MP6",
   "targetHandle": "t:d"
  },
  {
   "id": "e21",
   "source": "MN3",
   "sourceHandle": "s:d",
   "target": "OUT1",
   "targetHandle": null
  },
  {
   "id": "e22",
   "source": "MN3",
   "sourceHandle": "s:s",
   "target": "MN6",
   "targetHandle": "t:d"
  },
  {
   "id": "e23",
   "source": "MN4",
   "sourceHandle": "s:s",
   "target": "MN5",
   "targetHandle": "t:d"
  },
  {
   "id": "e24",
   "source": "MP1",
   "sourceHandle": "s:s",
   "target": "MP2",
   "targetHandle": "t:s"
  },
  {
   "id": "e25",
   "source": "MP1",
   "sourceHandle": "s:s",
   "target": "MP3",
   "targetHandle": "t:s"
  },
  {
   "id": "e26",
   "source": "MP1",
   "sourceHandle": "s:s",
   "target": "MP4",
   "targetHandle": "t:s"
  },
  {
   "id": "e27",
   "source": "MP1",
   "sourceHandle": "s:s",
   "target": "VDD1",
   "targetHandle": "t:pos"
  },
  {
   "id": "e28",
   "source": "MP3",
   "sourceHandle": "s:d",
   "target": "MP4",
   "targetHandle": "t:d"
  },
  {
   "id": "e29",
   "source": "MP3",
   "sourceHandle": "s:d",
   "target": "MP5",
   "targetHandle": "t:s"
  },
  {
   "id": "e30",
   "source": "MP3",
   "sourceHandle": "s:d",
   "target": "MP6",
   "targetHandle": "t:s"
  }
 ],
 "image": {
  "height": 824,
  "width": 1018
 },
 "nets": [
  {
   "id": "n0",
   "label": "GND",
   "pins": [
    "GND1:gnd",
    "MN1:s",
    "MN2:s",
    "MN5:s",
    "MN6:s"
   ]
  },
  {
   "id": "n1",
   "label": "A",
   "pins": [
    "IN1:out",
    "MN1:g",
    "MN4:g",
    "MP2:g",
    "MP3:g"
   ]
  },
  {
   "id": "n2",
   "label": "B",
   "pins": [
    "IN2:out",
    "MN2:g",
    "MN6:g",
    "MP1:g",
    "MP6:g"
   ]
  },
  {
   "id": "n3",
   "label": null,
   "pins": [
    "MN1:d",
    "MN3:g",
    "MP2:d",
    "MP5:g"
   ]
  },
  {
   "id": "n4",
   "label": null,
   "pins": [
    "MN2:d",
    "MN5:g",
    "MP1:d",
    "MP4:g"
   ]
  },
  {
   "id": "n5",
   "label": "OUT",
   "pins": [
    "MN3:d",
    "MN4:d",
    "MP5:d",
    "MP6:d",
    "OUT1:a"
   ]
  },
  {
   "id": "n6",
   "label": null,
   "pins": [
    "MN3:s",
    "MN6:d"
   ]
  },
  {
   "id": "n7",
   "label": null,
   "pins": [
    "MN4:s",
    "MN5:d"
   ]
  },
  {
   "id": "n8",
   "label": "VDD",
   "pins": [
    "MP1:s",
    "MP2:s",
    "MP3:s",
    "MP4:s",
    "VDD1:pos"
   ]
  },
  {
   "id": "n9",
   "label": null,
   "pins": [
    "MP3:d",
    "MP4:d",
    "MP5:s",
    "MP6:s"
   ]
  }
 ],
 "schema_version": 2,
 "status": "ok",
 "warnings": []
}
Evidence: test_net_tracer.py verbose results
test_net_tracer.py::test_crossover_without_dot_keeps_nets_separate[True] PASSED
test_net_tracer.py::test_crossover_without_dot_keeps_nets_separate[False] PASSED
test_net_tracer.py::test_crossing_with_dot_is_one_net[True] PASSED
test_net_tracer.py::test_crossing_with_dot_is_one_net[False] PASSED
test_net_tracer.py::test_crossing_with_undetected_dot_falls_back_to_crossover PASSED
test_net_tracer.py::test_crossover_beside_a_dot_stays_a_crossover PASSED
test_net_tracer.py::test_branching_supply_rail[True] PASSED
test_net_tracer.py::test_branching_supply_rail[False] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r0] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r90] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r180] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r270] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r0m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r90m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r180m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[True-r270m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r0] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r90] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r180] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r270] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r0m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r90m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r180m] PASSED
test_net_tracer.py::test_rotated_mirrored_transistor[False-r270m] PASSED
test_net_tracer.py::test_partial_keypoints_do_not_merge_drain_and_source_nets PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-NMOS-plain3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-NMOS-arrow3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-NMOS-dashed3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-NMOS-body4-True] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-PMOS-bubble3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-PMOS-arrow3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-PMOS-bubble4-True] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[True-PMOS-body4-True] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-NMOS-plain3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-NMOS-arrow3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-NMOS-dashed3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-NMOS-body4-True] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-PMOS-bubble3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-PMOS-arrow3-False] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-PMOS-bubble4-True] PASSED
test_net_tracer.py::test_three_vs_four_terminal_symbols[False-PMOS-body4-True] PASSED
test_net_tracer.py::test_separate_supply_symbols_share_one_net PASSED
test_net_tracer.py::test_stacked_transistors_with_tiny_link PASSED
test_net_tracer.py::test_ink_ignores_ruled_paper_lines PASSED
test_net_tracer.py::test_ink_mask_on_a_large_photo_is_fast_and_keeps_strokes PASSED
test_net_tracer.py::test_reads_port_labels_beside_symbols PASSED
test_net_tracer.py::test_export_schema_v2_for_cmos_inverter PASSED
test_net_tracer.py::test_export_gate_circuit_keeps_legacy_connections PASSED
test_net_tracer.py::test_legacy_alias_classes_are_traced PASSED
test_net_tracer.py::test_unknown_class_is_reported_not_traced PASSED
============================== 50 passed in 1.61s ==============================
- Outcome: ⚠️ 2 infos across 1 run (5m11s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed (2) ✅
  • ⚠️ agent_docs/ml-pipeline.md:30 - The intent's acceptance list requires that on the T3 round-trip set the reconstructed circuit gives the same truth table as the source in >= 80% of cases. The change does not implement or measure this. agent_docs/ml-pipeline.md says "Not yet: the T3 screenshot round-trip check", and bench_tracing.py only scores the T2 synthetic samples (net F1, exact match, and an optional --truth-table on T2 ground truth). No bench results for net F1 >= 0.90, exact match >= 70% clean / >= 50% hand-drawn, or runtime < 2 s are recorded in the diff either. Whether this criterion is deferred (for example because the T3 set is not merged yet) is the author's call.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ backend/pipeline/ink.py:63 - ink_mask() estimates the paper background with a morphological CLOSE using an elliptical kernel that is 3% of the longer image side, on the full-resolution float32 image. A 4000x3000 camera photo took 10.6 s in ink_mask alone (measured: 1024x768 takes 0.06 s). /detect_circuit passes the uploaded image at native size, and the frontend comment at App.tsx:~840 notes camera photos can be 4k wide, so the stated acceptance of < 2 s per image is lost on the real endpoint. The bench only covers T2 render sizes, so this goes unmeasured. Skeletonisation and the symbol-scaled closing kernel add more cost at that size. Siblings that scale with resolution in the same way: net_tracer.py:211-212 (closing kernel grows with symbol size, full-res), net_tracer.py:220 and skeleton_graph.py:107 (skeletonize on the full mask), app.py:154-156 (no downscale before NetTracer). Smallest fix: compute the background at a reduced resolution (or cap the working long side) and upsample it, and bound the tracer's working size.
  • ⚠️ backend/pipeline/net_tracer.py:252 - _repair_pass_through unions any two collinear, opposite leftover contacts of a symbol, assuming a wire runs past the symbol. In keypoint mode, terminals whose keypoints were dropped (visibility < KEYPOINT_MIN_VISIBILITY, detector.py) also leave their contacts unused. Trace: a vertical NMOS with only the 'g' keypoint kept has its drain and source wires as unused contacts, collinear and opposite. They are unioned, so the drain net and source net merge. Every other component's pins on those two nets then land on one wrong net, with no error or warning. The same gate applies to any symbol with a partial keypoint set. Fix: skip the repair for symbols whose class has declared terminals that went unassigned, or first fall back to assign_by_geometry for those terminals.

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Test** - 2 infos
  • ℹ️ With no keypoints (geometry fallback), sample 000011 produced six extra singleton nets compared with ground truth. This fits the documented geometry-mode exact match of about 87-89%, which is above the 70% and 50% gates. In keypoint mode with only some terminals kept, the unassigned terminals' pins are simply absent from the nets rather than falling back to geometry, which is the behavior the recorded decision chose.
  • ℹ️ agent_docs/ml-pipeline.md:40 - The geometry-mode hand-drawn bench numbers in agent_docs/ml-pipeline.md (net F1 0.9799, exact match 86.6%) differ slightly from this run (0.9816, 87.2%). Every other figure matches. The small drift is probably from the later ink-background downscale.
  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
On 300 T2 samples, the bench meets net F1 >= 0.90 and exact match >= 70% clean and >= 50% hand-drawn, in keypoint and geometry modes ✅ pass live bench_truth_table.txt
Runtime stays under 2 s per image (bench p95 about 0.16 s, max 0.34 s) ✅ pass live bench_truth_table.txt
POST a transistor schematic to /detect_circuit and get schema 2 nets, pins and t:/s: edges that match ground truth ✅ pass live endpoint_runs.txt, endpoint_000000.json
A 4000x3000 camera-size upload traces correctly in under 2 s (about 0.8 s) ✅ pass live endpoint_runs.txt
Adversarial: with only the g keypoint kept, or d/s keypoints dropped, drain and source nets are not merged by the pass-through repair ✅ pass live endpoint_partial_keypoints.txt, unit_scenarios.txt
Error handling: missing image gives 400, undecodable image gives 400, no auth cookie gives 401 ✅ pass live endpoint_partial_keypoints.txt
Crossover with or without a dot, branching supply rail, rotated or mirrored transistor, and 3 vs 4 terminal symbols behave correctly ⏸️ untested no The prior payload recorded this only as 50 passing unit tests in test_net_tracer.py that run the tracer on rendered images, with live=false. It did not establish a live result through the running serv…
On the T3 round-trip set, the reconstructed circuit gives the same truth table as the source in >= 80% of cases ⏸️ untested no The T3 screenshot round-trip set does not exist yet. The recorded user decision defers this criterion. It is not a failure of this change.
  • uv run pytest test_net_tracer.py test_class_schema.py in backend (56 passed)
  • uv run pytest tests/test_eval_netlist.py in ml (11 passed, 2 skipped)
  • uv run python data_gen/generate_v2.py --count 300 --seed 1, then uv run python bench_tracing.py --count 300 --mode both --truth-table
  • Real Flask /detect_circuit over HTTP with an auth cookie: 3 transistor circuits, a 4000x3000 upload, partial or no keypoints, and 400/401 error cases
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…er, pin assignment and schema 2 exporter

Replace the Hough segment extractor and the left/right-of-box gate heuristics with a
classical net tracer: background-normalised ink, symbol erasure with size-relative
margins, skeleton graph with junction-dot vs crossover rules, pin assignment from
detector keypoints or a geometry fallback with an orientation estimate, global supply
nets, and OCR of port and supply labels. The graph is now an undirected component/net
multigraph and the exporter emits schema 2 (pins, nets, ReactFlow edges, library cells)
while keeping the legacy gate-level connections for the current importer.

bench_tracing.py drives the tracer from perturbed T2 ground truth and scores it with the
T6 evaluator, which now also reads T2 pin-map netlists and net objects.

Scores: on 300 held-out T2 samples (seed 1) the tracer reaches net F1 0.9995 and exact
match 99.3% on clean renders, net F1 0.9989 and exact match 98.7% on hand-drawn-style
renders, truth-table equivalence 99.0%, p95 runtime 0.29 s per image. These scores come
from perturbed ground-truth detections (box and keypoint jitter, dropped junction dots):
no trained detector for the new classes exists yet, so the numbers bound the tracer, not
the end-to-end photo pipeline. The T3 round-trip truth-table criterion waits for T3.
@netlify

netlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for digisim ready!

Name Link
🔨 Latest commit 328d2e4
🔍 Latest deploy log https://app.netlify.com/projects/digisim/deploys/6afcc7fecfd8290b0b195583
😎 Deploy Preview https://deploy-preview-27--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.

@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 9:33pm UTC

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

This branch was successfully deployed

1 active deployment
Preview — 328d2e48 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