Skip to content

feat(backend): add netlist-driven synthetic circuit generator v2 - #25

Merged
Mani212005 merged 3 commits into
mainfrom
fm/digisim-t2-synth
Nov 17, 2026
Merged

Mani212005 merged 3 commits into
mainfrom
fm/digisim-t2-synth

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 (the class schema, ml/classes.yaml as single source of truth) is already merged on the default branch.

Substance of the referenced report for this task (report section 5, "T2 - Synthetic generator v2", with section 3.3 items 1-2 it points to): build a netlist-driven topology sampler plus a textbook/hand-drawn renderer. The topology sampler generates real, valid circuits (CMOS cells such as inverter, NAND/NOR 2-3 input, AOI/OAI, transmission gate, XOR/XNOR, mux, plus random compositions, and gate-level logic) so topologies can be verified with DigiSim's own switch-level solver (frontend/src/logic/simulation/switchLevel.ts). The renderer randomises symbol style variants (bubble vs arrow PMOS, 3 vs 4 terminal, IEEE vs IEC gates), orientation and mirror, line width, wire routing (orthogonal, jogs, crossovers with and without dots), fonts and net labels, then hand-drawn wobble, paper textures, lighting, perspective, blur, JPEG and phone-photo effects. It emits images, YOLO labels (boxes, using the ml/classes.yaml vocabulary), per-symbol pin points and orientation, and a netlist.json; deterministic seeds; splits by topology hash of the netlist (a circuit appears in only one split) and held-out rendering styles (a font, a symbol variant, a line style, a paper texture) for test. Acceptance from the report: uv run python data_gen/generate_v2.py --count 8000 --seed 1 reproduces byte-identical manifests; pytest validates label bounds, no empty images, a class balance report per domain (no class under 10% of the max), and that 100% of generated netlists pass a truth-table check against the switch-level solver (via a small node script); a contact-sheet overlay of 50 random samples committed under docs/ or reviewed visually; JUNCTION dot size distribution matches real (10-17 px at 1000 px width). Generated images and datasets stay out of git; model weights are never committed.

What Changed

  • Added backend/data_gen/generate_v2.py and the backend/data_gen/synth_v2/ package. It samples netlist-driven circuits (transistor-level CMOS cells and chains, plus gate-level DAGs), lays them out and routes them orthogonally, and renders them in cad, textbook, hand-drawn and phone-photo styles. Each sample gets a JPEG, YOLO labels using the ml/classes.yaml ids, an annotation JSON (pin points, orientation, junctions, wires, crossings) and a netlist JSON with a reference truth table. Output is seeded and deterministic, with splits by topology hash and held-out test styles. The manifest records SHA-256 hashes of every file.
  • Added checks: frontend/scripts/verifySynthNetlists.js, which verifies generated netlists against the switch-level solver by truth table, and backend/test_generate_v2.py, with tests for manifest reproducibility, label bounds, empty images, per-domain class balance, junction dot size, wire-to-netlist consistency, split and held-out styles, orientation, and the truth-table verifier. It also adds a contact-sheet tool (synth_v2/contact_sheet.py).
  • Added docs/synth_v2/README.md and a committed 50-sample contact sheet (docs/synth_v2/contact_sheet.jpg). Updated README.md and agent_docs/ml-pipeline.md to point to the new generator. No generated datasets or model weights are committed.

Risk Assessment

✅ Low: The change adds an isolated, deterministic dataset generator, a node verifier and behavioral tests that satisfy the stated acceptance criteria. It touches no runtime app paths, and generated data and weights stay git-ignored.

Testing

I ran the real generator CLI at 300 samples with seed 1 twice, and the two manifests were byte-identical (sha256 76b044e8...). The node script that checks netlists against DigiSim's switch-level solver passed 300/300. When I corrupted one truth-table row in a copy, it failed 299/300 and exited 1, so the check can catch errors. All 300 label files had boxes inside the image and none were empty. No circuit topology hash appeared in more than one split. Class balance passed in both domains (lowest ratio 0.118 for transistor OUTPUT_PORT and 0.142 for gate NAND). JUNCTION dot diameter stayed within 10.0-17.0 px per 1000 px width. The backend test module passes 12/12 once frontend node_modules are installed; without them, 2 tests skip. I viewed a 50-sample contact sheet and the drawings look valid across the cad, textbook, hand-drawn and phone-photo modes. Not re-run: the full 8000-sample generation, which the README says took about 9 minutes per run.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Run generate_v2.py twice with the same seed and get byte-identical manifests ✅ pass live manifest_hashes.txt; cmp reported IDENTICAL
Every generated netlist matches its truth table in DigiSim's switch-level solver via the node script ✅ pass live truth_table.log: 300/300 pass (225 transistor, 75 gate)
Adversarial: a corrupted truth table is detected by the verifier ✅ pass live truth_table_corrupt.log: 299/300, exit 1, FAIL on the edited netlist
YOLO labels stay in bounds, no label file or image is empty, and no topology hash crosses splits ✅ pass live Script output: 300 label files, 0 out of bounds, 0 empty; 133 hashes, 0 leaking
Class balance per domain stays at or above 10% of the max, and JUNCTION dot sizes are 10-17 px per 1000 px ✅ pass live Generator CLI output: transistor min ratio 0.118, gate 0.142, both pass; dot diameter 10.018-16.992 px
A contact sheet of 50 random samples shows valid, varied circuit renders ✅ pass live contact_sheet.jpg, inspected visually
The acceptance pytest module passes end to end, including the node truth-table tests ✅ pass live pytest.log: 12 passed
The full 8000-sample run reproduces the README manifest hash ⏸️ untested no Skipped as disproportionate to a targeted check: the README reports about 9 minutes per run and 723 MB of output, and a 300-sample run already exercised the same code path with the same determinism an…

Contact sheet of 50 samples from a fresh seed-1 run

Evidence: Manifest hashes from two runs with the same seed
76b044e870e51367be37b2851aef12a70a4fb297d36f3437e043a5fd115e7ea9  /tmp/sv2/a/manifest.json
76b044e870e51367be37b2851aef12a70a4fb297d36f3437e043a5fd115e7ea9  /tmp/sv2/b/manifest.json
Evidence: Truth-table check on the clean dataset
switch-level truth-table check: 300/300 netlists pass {"transistor":{"total":225,"passed":225},"gate":{"total":75,"passed":75}}
Evidence: Truth-table check on a corrupted dataset (must fail)
switch-level truth-table check: 299/300 netlists pass {"transistor":{"total":225,"passed":224},"gate":{"total":75,"passed":75}}
  FAIL netlists/train/000000.netlist.json: in={"A":0,"B":0} OUT: expected 0, got 1
Evidence: pytest result
............                                                             [100%]
12 passed in 38.63s

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Run generate_v2.py twice with the same seed and get byte-identical manifests ✅ pass live manifest_hashes.txt; cmp reported IDENTICAL
Every generated netlist matches its truth table in DigiSim's switch-level solver via the node script ✅ pass live truth_table.log: 300/300 pass (225 transistor, 75 gate)
Adversarial: a corrupted truth table is detected by the verifier ✅ pass live truth_table_corrupt.log: 299/300, exit 1, FAIL on the edited netlist
YOLO labels stay in bounds, no label file or image is empty, and no topology hash crosses splits ✅ pass live Script output: 300 label files, 0 out of bounds, 0 empty; 133 hashes, 0 leaking
Class balance per domain stays at or above 10% of the max, and JUNCTION dot sizes are 10-17 px per 1000 px ✅ pass live Generator CLI output: transistor min ratio 0.118, gate 0.142, both pass; dot diameter 10.018-16.992 px
A contact sheet of 50 random samples shows valid, varied circuit renders ✅ pass live contact_sheet.jpg, inspected visually
The acceptance pytest module passes end to end, including the node truth-table tests ✅ pass live pytest.log: 12 passed
The full 8000-sample run reproduces the README manifest hash ⏸️ untested no Skipped as disproportionate to a targeted check: the README reports about 9 minutes per run and 723 MB of output, and a 300-sample run already exercised the same code path with the same determinism an…
  • uv run pytest test_generate_v2.py -q (12 passed after npm ci in frontend so the node truth-table tests ran)
  • uv run python data_gen/generate_v2.py --count 300 --seed 1 --workers 2 run twice, manifests compared with cmp
  • node frontend/scripts/verifySynthNetlists.js on the generated 300-sample dataset
  • node frontend/scripts/verifySynthNetlists.js on a dataset with one corrupted truth-table row
  • Python script over the 300-sample output: YOLO label bounds, empty label files, and topology-hash split leakage
  • uv run python data_gen/synth_v2/contact_sheet.py --samples 50 and visual inspection of the sheet
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ⚠️ agent_docs/ml-pipeline.md:60 - The evaluation docs say ground-truth netlists are named <image stem>.json and that T2 emits them. The generator writes netlists/<split>/NNNNNN.netlist.json (backend/data_gen/generate_v2.py:205), so ml/eval_netlist.py will not match them to images by stem. One side needs a code change (rename the output, or accept the .netlist suffix in the evaluator). Both are code changes, outside this docs pass.

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

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ns, orientation and netlists

Adds backend/data_gen/generate_v2.py and the synth_v2 package: samples valid
CMOS (series-parallel cells, TG mux, chains) and gate-level circuits, lays them
out like textbook schematics, routes nets on a grid (crossovers vs junction
dots by construction), and renders cad/textbook/hand-drawn/photo styles.
Writes YOLO labels (ml/classes.yaml ids), per-symbol pins and orientation,
netlist.json with reference truth tables, and a byte-reproducible manifest.
Splits by topology hash; held-out styles only in test.

frontend/scripts/verifySynthNetlists.js checks every netlist against the
switch-level solver (8000/8000 pass). Pytest covers determinism, label bounds,
non-empty images, per-domain balance, dot sizes, wire connectivity and splits.
Contact sheet of 50 samples in docs/synth_v2/.
@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 8:26pm UTC

@netlify

netlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for digisim ready!

Name Link
🔨 Latest commit 33bf9bb
🔍 Latest deploy log https://app.netlify.com/projects/digisim/deploys/6afcb82d6d71025bba68f46c
😎 Deploy Preview https://deploy-preview-25--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 f1a95ea into main Nov 17, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
Preview — 33bf9bb5 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