Official Codebase of 3DCodeVerse
Python
bench: coupling_stats reads the gate that judges the poses, not only which poses
ziyao36074d8e3bc9
diff --git a/harness/bench/coupling_stats.py b/harness/bench/coupling_stats.pyindex 4e9d94de..59fd9144 100644--- a/harness/bench/coupling_stats.py+++ b/harness/bench/coupling_stats.py@@ -16,6 +16,7 @@ a coupling at all — the mechanism claim in docs/PAPER_WRITING.md §5.3.from __future__ import annotationsimport argparse+import jsonimport statisticsimport sysfrom pathlib import Path@@ -24,6 +25,9 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # `python benchfrom codeverse.spatial.joints_model import UrdfError, load_urdf # noqa: E402+#: run-layout directories holding a SUB-workspace, as in bench/session_stats+SUBRUN_DIRS = frozenset({"_cand", "_assets"})+def _urdfs(root: Path) -> list[Path]:"""Every built ``robot.urdf`` under ``root``, once per file on disk.@@ -90,6 +94,32 @@ def survey(root: Path) -> dict:"coupled": coupled}+def gate_stats(root: Path) -> dict:+ """What the ``joint_sweep`` gate said about this battery's rounds.++ The mechanical counts below say which poses were SAMPLED; this says what the gate that+ judges those poses reported, which is the loss event a coupled battery is run for."""+ rounds = ran = failed = errors = 0+ seen: set[Path] = set()+ for rec in root.rglob("record.json"):+ if rec.resolve() in seen or SUBRUN_DIRS & set(rec.parts):+ continue+ seen.add(rec.resolve())+ try:+ data = json.loads(rec.read_text())+ except (OSError, ValueError):+ continue+ for rnd in data.get("rounds") or []:+ rounds += 1+ for g in rnd.get("gates") or []:+ if g.get("gate") != "joint_sweep":+ continue+ ran += 1+ failed += 0 if g.get("passed") else 1+ errors += sum(1 for f in (g.get("findings") or []) if f.get("severity") == "error")+ return {"rounds": rounds, "sweep_ran": ran, "sweep_failed": failed, "sweep_errors": errors}++def report(roots: list[Path]) -> str:lines = ["| battery | URDFs | prompts | prompts with a coupling | coupled URDFs | ""joints, coupled URDFs (median) | driven per pose there (median) | one-input |",@@ -107,6 +137,14 @@ def report(roots: list[Path]) -> str:f"| {root.name} | {s['urdfs']} | {s['prompts']} | {s['coupled_prompts']} | "f"{len(s['coupled'])} | {statistics.median(moves):.0f} | {statistics.median(free):.0f} | "f"{sum(1 for n in free if n == 1)} |")++ lines += ["", "| battery | rounds | joint_sweep ran | failed | ERROR findings | errors/round |",+ "|---|--:|--:|--:|--:|--:|"]+ for root in roots:+ g = gate_stats(root)+ per = g["sweep_errors"] / g["rounds"] if g["rounds"] else float("nan")+ lines.append(f"| {root.name} | {g['rounds']} | {g['sweep_ran']} | {g['sweep_failed']} | "+ f"{g['sweep_errors']} | {per:.2f} |")return "\n".join(lines)diff --git a/harness/tests/compare_bench/test_session_stats.py b/harness/tests/compare_bench/test_session_stats.pyindex 921120c9..02f578ea 100644--- a/harness/tests/compare_bench/test_session_stats.py+++ b/harness/tests/compare_bench/test_session_stats.py@@ -117,3 +117,24 @@ def test_the_coupling_survey_counts_degrees_of_freedom_not_joints(tmp_path: Pathassert s["coupled"] == [(2, 1)] # 2 movable joints, 1 degree of freedomassert "| 2 | 2 | 1 | 1 | 2 | 1 | 1 |" in report([tmp_path])assert "| art_hard_umbrella | 1 | 2 | 1 | 1 |" in per_prompt(tmp_path)+++def test_the_coupling_survey_also_reads_the_gate_that_judges_the_poses(tmp_path: Path) -> None:+ """The mechanical counts say which poses were sampled; a coupled battery is run for+ what the ``joint_sweep`` gate then reports about them, so the survey prints both."""+ from bench.coupling_stats import gate_stats, report++ run = tmp_path / "cells" / "cpl_umbrella" / "arm" / "run"+ run.mkdir(parents=True)+ (run / "record.json").write_text(json.dumps({"rounds": [+ {"index": 0, "gates": [{"gate": "joint_sweep", "passed": False, "findings": [+ {"severity": "error", "message": "links a|b overlap"},+ {"severity": "warn", "message": "shallow rest overlap"}]}]},+ {"index": 1, "gates": [{"gate": "joint_sweep", "passed": True, "findings": []},+ {"gate": "connectivity", "passed": False, "findings": [+ {"severity": "error", "message": "not this gate"}]}]},+ ]}))++ g = gate_stats(tmp_path)+ assert g == {"rounds": 2, "sweep_ran": 2, "sweep_failed": 1, "sweep_errors": 1}+ assert "| 2 | 2 | 1 | 1 | 0.50 |" in report([tmp_path])