Skip to content

feat(ml): real-data ingestion and frozen eval set from CGHD, Roboflow and Sampleimages - #26

Merged
Mani212005 merged 3 commits into
mainfrom
fm/digisim-t4-realdata
Nov 17, 2026
Merged

Mani212005 merged 3 commits into
mainfrom
fm/digisim-t4-realdata

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; this change is one of them, the real-data ingestion and frozen eval set. T1 (the class schema, ml/classes.yaml as single source of truth) is already merged. This task: fetch a small pilot of the CGHD hand-drawn circuit dataset (3-4 drafters, under 1 GB, via the Hugging Face mirror), convert its VOC annotations to YOLO using the class remap onto the classes.yaml vocabulary, relabel CGHD transistor.fet into NMOS/PMOS with our own manual or heuristic-assisted pass and flag uncertain ones, merge the 46 Roboflow images already in the repo (polygon to box) and label the 4 spare Sampleimages, split by drafter (never by image), and write ml/DATA_LICENSES.md (source, licence, attribution; CGHD CC BY 4.0, Roboflow export CC BY 4.0) plus a manifest with hashes. Fetched data stays out of git; commit only scripts, split manifests, hashes and the licences file. Acceptance: per-class real counts reported against the data-plan table with an explicit 'real count too low, synthetic-only claim' flag for any class under 30 test instances; no drafter or source image appears in two splits (script-verified); licence file reviewed. No Roboflow Universe downloads and no Kaggle or Roboflow credentials.

What Changed

  • Added the ml/real_data/ package, run as python -m real_data.build fetch|sheets|convert|verify|report. fetch pulls a 4-drafter CGHD pilot (drafters 16, 19, 20, 25) from the Hugging Face mirror, pinned to a revision. convert turns the CGHD VOC annotations into YOLO labels using the ml/classes.yaml vocabulary. It also merges the 46 Roboflow images (polygons to boxes) and the 4 spare Sampleimages. CGHD transistor.fet is relabelled NMOS/PMOS from our own manual pass in labels/fet_polarity.json. Uncertain transistors, terminals, supply symbols and unmapped classes are kept as ignore regions, not labels. Fetched and converted data go to the gitignored ml/data_real/.
  • Splits are by drafter for CGHD and by source image for the others, never by image. verify re-checks the committed manifest for any drafter, source image or image content (exact and near-duplicate hash) in two splits. ml/data_manifest.json records SHA-256 hashes of every image and label, split membership and a frozen hash per split. ml/REAL_DATA_REPORT.md is generated from it and lists per-class real counts against the data-plan targets. It flags any class with fewer than 30 real test instances as real count too low, synthetic-only claim. In this pilot those are OUTPUT_PORT, NOT, NAND, NOR, XOR, XNOR, INDUCTOR, BJT_NPN, BJT_PNP and CLOCK.
  • Added ml/DATA_LICENSES.md with source, licence and attribution for CGHD (CC BY 4.0) and the Roboflow export (CC BY 4.0). Updated the README data-sources table and agent_docs/ml-pipeline.md. Added pillow, scipy and huggingface_hub to ml/pyproject.toml (and uv.lock), gitignored ml/data_real/, and added ml/tests/test_real_data.py.

Risk Assessment

✅ Low: The three fix-round changes are correct as traced: GND text is tested before the numeric rule, tiny FETs still consume an ordinal, and vss and voltage.dc go through text triage. The new tests and the regenerated manifest and report are consistent with that code. I did not run tests or the leakage verifier, per instructions.

Testing

I ran the real-data CLI against the fetched CGHD pilot, Roboflow and Sampleimages data in the worktree. The 43 targeted tests passed. verify passed, and a fresh convert regenerated the committed manifest and report byte-for-byte with 0 leakage violations. Direct probes confirmed the three review fixes. "0V" and its variants now map to GND, and the tiny-FET case keeps polarity keys aligned (a 2px FET before two normal ones gave NMOS and PMOS to the right boxes). vss and voltage.dc are no longer direct remaps; they resolve by nearby text (VSS gives GND, 5V gives VDD) and are otherwise uncertain_supply ignore regions. Moving images between splits made verify report drafter/group leakage and stale split hashes. The report flags classes with fewer than 30 real test instances as "real count too low, synthetic-only claim". The licence file lists CC BY 4.0 for CGHD and Roboflow and notes the CGHD licence conflict between its sources. There is no UI surface; evidence is CLI and API-level output only.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Rebuild the real-data set from fetched CGHD, Roboflow and Sampleimages data and verify the manifest and report reproduce with no leakage ✅ pass live real_data.build convert -> 'wrote data_manifest.json: 434 images, 0 violations'; git status clean after, so manifest and report match the committed ones; verify OK
A terminal labelled 0V or 0v is classified GND, not VDD ✅ pass live probe.txt: classify_terminal('0V'), ('0v'), ('+0v'), ('0.0v') and ('0') all return GND; '5V' returns VDD
A sub-4px FET before a normal FET does not shift polarity labels ✅ pass live probe.txt: convert_annotation with polarity {#0 PMOS, #1 NMOS, #2 PMOS} gives NMOS for the 2nd and PMOS for the 3rd FET, and the tiny one is dropped
vss and voltage.dc are resolved by nearby text and ignored otherwise (no longer direct remaps) ✅ pass live probe.txt: vss next to 'VSS' gives GND; voltage.dc next to '5V' gives VDD; voltage.dc next to 'R1' becomes an uncertain_supply ignore box; neither name is in CGHD_DIRECT
Adversarial: a drafter or source image that appears in two splits is rejected by the leakage verifier ✅ pass live probe.txt: moving a drafter_20 image to train gives 'group drafter_20 appears in splits train and test'; moving another image gives a drafter_16 test/valid group violation; both also flag stale split…
Per-class real counts reported against the data-plan table, with the synthetic-only flag for classes under 30 test instances ✅ pass live ml/REAL_DATA_REPORT.md regenerated by the convert run; OUTPUT_PORT, NOT, NAND, NOR, XOR, XNOR, INDUCTOR, BJT_NPN, BJT_PNP and CLOCK are flagged
No fetched data or weights are committed, and a licences file exists ✅ pass live git ls-files ml/data_real returns 0 files, the path is gitignored, and ml/DATA_LICENSES.md covers CGHD, Roboflow and Sampleimages
Evidence: Probe output: convert_annotation fixes and leakage rejection
BOXES
  LabelBox(class_name='NMOS', xmin=100, ymin=100, xmax=160, ymax=160)
  LabelBox(class_name='PMOS', xmin=300, ymin=100, xmax=360, ymax=160)
  LabelBox(class_name='GND', xmin=500, ymin=500, xmax=540, ymax=540)
  LabelBox(class_name='VDD', xmin=700, ymin=700, xmax=740, ymax=740)
  LabelBox(class_name='GND', xmin=800, ymin=800, xmax=820, ymax=820)
IGNORED
  IgnoredBox(reason='uncertain_supply', source_class='voltage.dc', xmin=600, ymin=600, xmax=640, ymax=640)
clean: []
drafter leak: ['group drafter_20 appears in splits train and test', 'split test: stored hash does not match its members', 'split train: stored hash does not match its members']
moved image: ['group drafter_16 appears in splits test and valid', 'split test: stored hash does not match its members', 'split valid: stored hash does not match its members']

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ ml/uv.lock - merge conflict rebasing onto origin/main

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

🔧 **Review** - 3 issues found → auto-fixed ✅
  • ⚠️ ml/real_data/class_remap.py:84 - classify_terminal labels a "0V" terminal as VDD. _VOLTAGE_TEXT (\d+(\.\d+)?v) is tested before _GND_TEXT, so "0v", "0V", "+0v" and "0.0v" all match the voltage branch, and 0 <= MAX_RAIL_VOLTS returns VDD. _GND_TEXT lists 0v, which shows GND was intended, but that alternative is unreachable. I ran classify_terminal("0V"), which returned VDD, while "0" returned GND. A "0V" ground reference is common in textbook schematics, so real GND terminals end up in the frozen train/valid/test labels as VDD. That corrupts the GND and VDD real counts and the frozen eval set. Fix: check _GND_TEXT before _VOLTAGE_TEXT, or require a positive value for the VDD branch, add a "0V" test case, and regenerate the manifest and split hashes. No test covers it: tests/test_real_data.py:84-100 has no zero-volt case.
  • ⚠️ ml/real_data/cghd.py:173 - The per-image transistor ordinal is counted two different ways, so a tiny transistor shifts every later polarity label. fet_polarity.fet_objects (fet_polarity.py:64) numbers every transistor.fet object, including ones under MIN_BOX_SIDE. propagate_polarity, load_polarity and the reference decisions key polarity as "<key>#<ordinal>" with that numbering. convert_annotation (cghd.py:172-180) skips boxes smaller than 4px before incrementing fet_seen. If any FET box has a side under 4px, every later FET in that image looks up the previous FET's decision. That gives wrong NMOS/PMOS labels with no error. The propagate_polarity check sorted(decisions) == range(count) cannot catch it because it uses the unfiltered count. Fix: count fet_seen for every transistor.fet object before the size filter, or filter inside fet_objects so both sides agree. Add a test with a tiny FET followed by a real one.
  • ⚠️ ml/real_data/class_remap.py:24 - CGHD vss symbols are remapped to VDD in CGHD_DIRECT, while the text triage in the same module treats the label vss as GND (_GND_TEXT: v_?ss). The same concept therefore gets opposite classes depending on which path sees it. VSS is the negative or ground rail, so labelling the symbol VDD injects wrong labels into a power class that is already scarce. The change's intent does not require mapping vss. The smallest honest remedy is to remove vss from CGHD_DIRECT so it becomes an ignore region, or to map it to GND if that is the intended meaning. Related: voltage.dc -> VDD (class_remap.py:23) maps any DC source symbol, including batteries and bias sources in non-supply positions, to VDD. This needs a human decision on the labelling policy.

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

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Rebuild the real-data set from fetched CGHD, Roboflow and Sampleimages data and verify the manifest and report reproduce with no leakage ✅ pass live real_data.build convert -> 'wrote data_manifest.json: 434 images, 0 violations'; git status clean after, so manifest and report match the committed ones; verify OK
A terminal labelled 0V or 0v is classified GND, not VDD ✅ pass live probe.txt: classify_terminal('0V'), ('0v'), ('+0v'), ('0.0v') and ('0') all return GND; '5V' returns VDD
A sub-4px FET before a normal FET does not shift polarity labels ✅ pass live probe.txt: convert_annotation with polarity {#0 PMOS, #1 NMOS, #2 PMOS} gives NMOS for the 2nd and PMOS for the 3rd FET, and the tiny one is dropped
vss and voltage.dc are resolved by nearby text and ignored otherwise (no longer direct remaps) ✅ pass live probe.txt: vss next to 'VSS' gives GND; voltage.dc next to '5V' gives VDD; voltage.dc next to 'R1' becomes an uncertain_supply ignore box; neither name is in CGHD_DIRECT
Adversarial: a drafter or source image that appears in two splits is rejected by the leakage verifier ✅ pass live probe.txt: moving a drafter_20 image to train gives 'group drafter_20 appears in splits train and test'; moving another image gives a drafter_16 test/valid group violation; both also flag stale split…
Per-class real counts reported against the data-plan table, with the synthetic-only flag for classes under 30 test instances ✅ pass live ml/REAL_DATA_REPORT.md regenerated by the convert run; OUTPUT_PORT, NOT, NAND, NOR, XOR, XNOR, INDUCTOR, BJT_NPN, BJT_PNP and CLOCK are flagged
No fetched data or weights are committed, and a licences file exists ✅ pass live git ls-files ml/data_real returns 0 files, the path is gitignored, and ml/DATA_LICENSES.md covers CGHD, Roboflow and Sampleimages
  • PYTHONPATH=. python -m pytest tests/test_real_data.py -q (43 passed)
  • python -m real_data.build verify against the committed manifest (OK, no leakage)
  • python -m real_data.build convert re-run on the fetched CGHD pilot, Roboflow and Sampleimages data (434 images, 0 violations; ml/data_manifest.json and ml/REAL_DATA_REPORT.md came out byte-identical to the committed ones)
  • Probe of classify_terminal and classify_supply with 0V, 0v, +0v, 0.0v, 0, 5V, +5, VDD, vss, 1000V, R1, Vin and None
  • Probe of convert_annotation with a 2px FET before two normal FETs, vss and voltage.dc symbols next to different labels, and a terminal labelled 0V
  • Tampered manifest copies (a drafter_20 image moved to train; a different image moved to another split) run through build.verify
  • Read ml/REAL_DATA_REPORT.md and ml/DATA_LICENSES.md; confirmed ml/data_real is gitignored with 0 tracked files
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ow, Sampleimages)

Fetch a 4-drafter CGHD pilot (pinned HF revision), convert VOC to YOLO in the
classes.yaml vocabulary, relabel transistor.fet into NMOS/PMOS with our own
reference pass propagated across photos, merge the 46 Roboflow images
(polygon to box) and label the 4 spare Sampleimages. Splits are by drafter or
source image; a script verifies no drafter, source image, image content or
near-duplicate crosses splits. Commits only scripts, label decisions, the
manifest with hashes, the per-class report and DATA_LICENSES.md; fetched data
stays gitignored under ml/data_real/.
@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:32pm UTC

@netlify

netlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for digisim canceled.

Name Link
🔨 Latest commit b5d367f
🔍 Latest deploy log https://app.netlify.com/projects/digisim/deploys/6afcb9acab44808a557ccc13

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

This branch was successfully deployed

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