Repository navigation
feat(ml): add evaluation harness v2 with per-domain metrics, frozen hash check and netlist metrics - #24
Merged
Conversation
…ozen test hash and end-to-end netlist metrics Extend ml/evaluate.py: per-class and per-domain P/R/F1/accuracy with Wilson CIs, confusion matrix, small-object (junction) recall, one JSON and one Markdown report per run, and a legacy ultralytics block that reproduces the old eval_test.json exactly. Runs refuse to start when the frozen test split hash differs from ml/frozen_sets.json. End-to-end metrics (--gt-netlists/--pred-netlists): net precision/recall/F1 over pin pairs, netlist exact-match rate and truth-table equivalence via DigiSim's own simulate() (ml/sim_bridge). Commits the gate12 baseline (ml/baselines/gate12.json) and the gate12_test frozen-set entry; weights and images stay out of git.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for digisim canceled.
|
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: 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. It split the work into tasks T1-T11; this change is T6, the evaluation harness v2: extend ml/evaluate.py with per-class and per-domain precision/recall/F1/accuracy with Wilson confidence intervals, a confusion matrix, small-object (junction) recall, and a frozen test-set hash check; plus end-to-end metrics - net precision/recall/F1 over pin-pair connectivity, netlist exact-match rate, and truth-table equivalence after circuit reconstruction using DigiSim's simulator. It outputs one JSON and one Markdown table per run. Acceptance: it runs on the old 12-class weights over the gate subset and reproduces the old test numbers within tolerance; a baseline row for the 12-class model is committed as ml/baselines/gate12.json; it refuses to run if the frozen test hash changed. The class vocabulary comes from ml/classes.yaml (T1, already merged); no new weights, datasets or images are committed.
What Changed
ml/evaluate.pyand addedml/eval_metrics.py,ml/eval_report.pyandml/eval_frozen.py. Evaluation now reports per-class and per-domain precision/recall/F1/accuracy with Wilson confidence intervals, a confusion matrix and small-object (junction) recall. Each run writes one JSON and one Markdown table.ml/eval_frozen.pychecks the test set against the hashes inml/frozen_sets.jsonand refuses to run if they changed.ml/eval_netlist.py: net precision/recall/F1 over pin-pair connectivity, netlist exact-match rate, and truth-table equivalence after circuit reconstruction. Equivalence is checked with DigiSim's simulator through the newml/sim_bridge/truth_table.cjs.ml/baselines/gate12.jsonand documented the harness inagent_docs/ml-pipeline.md. Added tests for the new modules underml/tests/plus shared fixtures inconftest.py, and updatedml/pyproject.tomlandml/uv.lock. No weights, datasets or images are added.Risk Assessment
✅ Low: The harness is additive, model-free and offline. The prior fix rounds are correctly applied: the frozen hash now covers the data.yaml-resolved images, labels and netlists directories, the (verified) label only appears when a frozen check ran, the removed flags are gone, the unused split_by_domain helper is deleted, and the domain rules reach evaluate_netlists. Traced inputs gave correct results, and the baseline hash, class list and reproduction match the frozen registry.
Testing
I drove the real
evaluate.pyCLI against a disposable 6-image 12-class split with a random-init YOLOv8n checkpoint, since no weights or gate-era dataset are in the worktree. The full report, the frozen-hash refusal on label, image, yaml-redirect and ground-truth-netlist tampering, the unverified-split labelling and the end-to-end netlist metrics (including truth-table equivalence through the real simulator) all behaved as intended. The acceptance item 'reproduces old test numbers on the real old weights and gate subset' could not be run, because the weights and the 78-image dataset are not committed. I only confirmed the committed baseline's hash matches the registry and that its recorded reproduction deltas are 0. This is a CLI/report change with no UI, so no screenshots apply. Scratch files in /tmp and the frontend node_modules were removed; the worktree is clean.Evidence: Full CLI run transcript (frozen verified)
Evidence: Frozen-set tamper and registry transcript
Evidence: End-to-end netlist run and GT tamper transcript
Evidence: End-to-end Markdown section (net P/R/F1, exact match, truth-table)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed (2) ✅
ml/eval_report.py:210- The Markdown header always prints "(verified)" after the frozen sha256, even when no frozen check ran. For a non-test split with no registered frozen set (e.g.--split val, no--frozen-name, no unique registry match), evaluate.py skips verify_frozen and records frozen_name=None. The report then says "dataset:None... frozen sha256...(verified)", which falsely claims the data was integrity-checked. Render "(verified)" only when run.dataset.frozen_name is set, otherwise "(not frozen - unverified)".ml/evaluate.py:401- Several optional switches go beyond what the T6 intent requires. The intent asks for the metrics, a frozen-hash check, reproduction of the old numbers and a committed baseline. These are not needed for that:--match-mode(three modes;autowould do),--score-bulk,--skip-detection,--threads, and the--freezeworkflow with its registry-writing code. Each adds surface that has to be maintained and tested. The smallest remedy is to remove them and keep the fixed defaults (auto pairing, bulk pins unscored, detection always run). Whether to keep them is a product decision.ml/evaluate.py:62- The frozen hash counts.tifand.tifffiles as images (eval_frozen.IMAGE_SUFFIXES). The scoring code (evaluate.IMAGE_SUFFIXES at evaluate.py:62, used at :224) skips them, and it is a second copy of the same rule. Today the scored set is a subset of the hashed set, so the integrity check stays sound, but the two lists can drift.load_dataset_infoalso derives labels_dir withstr(doc[key]).replace("images", "labels", 1)(evaluate.py:107). That replaces the first occurrence, whereas ultralytics replaces the last/images/component. An entry such asmy_images/images/testwould give different label directories in the detection block and the legacy block. Reuse a single suffix constant, and replace the lastimagespath component instead.🔧 Fix applied.
1 warning still open:
ml/eval_metrics.py:324-split_by_domainis a second grouping helper that nothing calls.evaluate_detectiongroups per-domain inline withdomain_for, andevaluate_netlistsdoes the same. No test references it either. No T6 requirement needs it, since per-domain metrics are already produced throughdomain_for. Smallest remedy: delete it, andIterableif that leaves the import unused.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
cd ml && uv run pytest tests -q(39 passed, including the 2 truth-table tests once frontend deps were installed)evaluate.py --freezeon a disposable 12-class split, then a full CLI run with--skip-legacy-> JSON + Markdown report (per-class/per-domain Wilson CIs, small-object and JUNCTION recall, '(verified)' header)Full CLI run with the ultralytics legacy block and--baseline-> per-class dF1 columns renderedTampered frozen set: edited a label, added an image, pointed data.yaml at images/test_v2 -> exit 3, nothing written; restored data -> exit 0Re-freezing an existing name -> refused (exit 3); non-test split with no registry entry -> '(not frozen - unverified)'; test split with no resolvable frozen name -> argparse error exit 2End-to-end--gt-netlists/--pred-netlistsrun through the real Node/DigiSim simulate() bridge (frontendnpm ciin the worktree, removed afterwards); GT netlist tampering -> exit 3Checkedml/baselines/gate12.jsonagainst theml/frozen_sets.jsongate12_test sha256 and its recorded reproduction deltas✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.