Repository navigation
feat(backend): add netlist-driven synthetic circuit generator v2 - #25
Merged
Merged
Conversation
…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/.
|
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: 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 1reproduces 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
backend/data_gen/generate_v2.pyand thebackend/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 theml/classes.yamlids, 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.frontend/scripts/verifySynthNetlists.js, which verifies generated netlists against the switch-level solver by truth table, andbackend/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).docs/synth_v2/README.mdand a committed 50-sample contact sheet (docs/synth_v2/contact_sheet.jpg). UpdatedREADME.mdandagent_docs/ml-pipeline.mdto 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.
Evidence: Manifest hashes from two runs with the same seed
Evidence: Truth-table check on the clean dataset
Evidence: Truth-table check on a corrupted dataset (must fail)
Evidence: pytest result
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.
uv run pytest test_generate_v2.py -q(12 passed afternpm ciin frontend so the node truth-table tests ran)uv run python data_gen/generate_v2.py --count 300 --seed 1 --workers 2run twice, manifests compared with cmpnode frontend/scripts/verifySynthNetlists.json the generated 300-sample datasetnode frontend/scripts/verifySynthNetlists.json a dataset with one corrupted truth-table rowPython script over the 300-sample output: YOLO label bounds, empty label files, and topology-hash split leakageuv run python data_gen/synth_v2/contact_sheet.py --samples 50and 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>.jsonand that T2 emits them. The generator writesnetlists/<split>/NNNNNN.netlist.json(backend/data_gen/generate_v2.py:205), soml/eval_netlist.pywill not match them to images by stem. One side needs a code change (rename the output, or accept the.netlistsuffix 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.