Official Codebase of 3DCodeVerse
Python
bench: coupling_stats counts runs, not three copies of the same URDF
ziyao4cc9527f34cd
diff --git a/harness/bench/coupling_stats.py b/harness/bench/coupling_stats.pyindex 59fd9144..2f5a62c1 100644--- a/harness/bench/coupling_stats.py+++ b/harness/bench/coupling_stats.py@@ -30,7 +30,12 @@ SUBRUN_DIRS = frozenset({"_cand", "_assets"})def _urdfs(root: Path) -> list[Path]:- """Every built ``robot.urdf`` under ``root``, once per file on disk.+ """The BUILT ``robot.urdf`` of each run under ``root``, once per run.++ A run holds the same file three times — ``src/`` (what the agent wrote),+ ``artifacts/`` (what the build produced) and ``deliverable/`` (what finalise copied) —+ so counting files instead of runs multiplies every mechanical number by three. The+ artefact is the one the sweep actually posed.``recurse_symlinks=True`` + resolve-dedupe for the same reason as``bench/session_stats._sessions``: batteries symlink each other's cells, and a walk@@ -38,14 +43,23 @@ def _urdfs(root: Path) -> list[Path]:how the tree happens to be laid out."""seen: dict[Path, Path] = {}for p in sorted(root.rglob("robot.urdf", recurse_symlinks=True)):+ if p.parent.name != "artifacts" or SUBRUN_DIRS & set(p.parts):+ continueseen.setdefault(p.resolve(), p)return sorted(seen.values())def _prompt_of(path: Path) -> str:- """The battery cell a URDF belongs to (``cells/<prompt>/<arm>/run/...``)."""+ """The battery cell a URDF belongs to.++ Two layouts: ``ab_plan``/``compare_backends`` write ``cells/<prompt>/<arm>/run/...``+ and ``bench run`` writes ``runs/<prompt>/...``. Falling back to the parent directory+ named every URDF "artifacts"."""parts = path.parts- return parts[parts.index("cells") + 1] if "cells" in parts else path.parent.name+ for marker in ("cells", "runs"):+ if marker in parts:+ return parts[parts.index(marker) + 1]+ return path.parent.namedef per_prompt(root: Path) -> str:diff --git a/harness/tests/compare_bench/test_session_stats.py b/harness/tests/compare_bench/test_session_stats.pyindex 02f578ea..b305d32d 100644--- a/harness/tests/compare_bench/test_session_stats.py+++ b/harness/tests/compare_bench/test_session_stats.py@@ -138,3 +138,26 @@ def test_the_coupling_survey_also_reads_the_gate_that_judges_the_poses(tmp_path: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])+++def test_the_coupling_survey_counts_runs_not_copies_of_the_same_urdf(tmp_path: Path) -> None:+ """A run holds robot.urdf three times — src/ (written), artifacts/ (built) and+ deliverable/ (finalised) — and `bench run` lays cells out as runs/<id>/, not+ cells/<id>/. Counting files tripled every mechanical number and named every prompt+ "artifacts"."""+ from bench.coupling_stats import _prompt_of, _urdfs++ urdf = """<?xml version="1.0"?>+<robot name="rig"><link name="base"/><link name="a"/>+ <joint name="drive" type="revolute"><parent link="base"/><child link="a"/>+ <axis xyz="0 0 1"/><limit lower="0" upper="1" effort="1" velocity="1"/></joint>+</robot>+"""+ run = tmp_path / "runs" / "cpl_umbrella"+ for where in ("src", "artifacts", "deliverable"):+ (run / where).mkdir(parents=True)+ (run / where / "robot.urdf").write_text(urdf)++ found = _urdfs(tmp_path)+ assert [p.parent.name for p in found] == ["artifacts"], "one URDF per run, the built one"+ assert _prompt_of(found[0]) == "cpl_umbrella"