Skip to content

Official Codebase of 3DCodeVerse

Python

record: find_run_dirs lists a run reached through several paths once, at its physical path — export, index, pairs and the gallery counted symlinked battery cells twice; only refine de-duplicated (bug B12)

gaoypeng1fc30af17458
diff --git a/harness/codeverse3d/addons/dataset/refine.py b/harness/codeverse3d/addons/dataset/refine.py
index 1e6bcd56..dfcc8a00 100644
--- a/harness/codeverse3d/addons/dataset/refine.py
+++ b/harness/codeverse3d/addons/dataset/refine.py
@@ -158,17 +158,11 @@ def transitions(runs_dir: Path | str, *, threshold: float = MIN_PREFERENCE_DELTA
"""Every exportable refine transition under ``runs_dir``; every one that is not is counted.
A run reachable through more than one path (54 of 239 under ``eval/bench/out``, where the
- batteries symlink each other's cells) is exported once, under the battery it physically
- lives in."""
+ batteries symlink each other's cells) is found once (``find_run_dirs``) and exported under
+ the battery it physically lives in."""
drops = drops if drops is not None else Counter()
root = Path(runs_dir)
- seen: set[Path] = set()
for found in iter_runs(root, on_error=lambda p, e: drops.update([f"unreadable_record: {type(e).__name__}"])):
- physical = found.ws.root.resolve()
- if physical in seen:
- drops["duplicate_run"] += 1
- continue
- seen.add(physical)
rounds = {r.index: r for r in found.record.rounds}
for cur in found.record.rounds:
if cur.kind not in REFINE_KINDS:
diff --git a/harness/codeverse3d/record/record.py b/harness/codeverse3d/record/record.py
index 4fa52064..bc3069d4 100644
--- a/harness/codeverse3d/record/record.py
+++ b/harness/codeverse3d/record/record.py
@@ -315,14 +315,15 @@ def find_run_dirs(root: Path | str, *, predicate: Callable[[Path], bool] = is_ru
ab_plan BATTERY directory work: those hold their runs four and five levels down, so
every exporter used to scan one level, find nothing and report "0 runs" as a success.
A directory that IS a run is never descended into (a run holds candidate workspaces
- of its own).
+ of its own). A run reached through more than one path (``eval/bench/out``'s batteries
+ symlink each other's cells) is listed once, at the path it physically lives at.
"""
root = Path(root)
if not root.is_dir():
return []
- direct = sorted(d for d in root.iterdir() if predicate(d))
+ direct = [d for d in root.iterdir() if predicate(d)]
if direct:
- return direct
+ return _once(root, direct)
found: list[Path] = []
frontier = [d for d in sorted(root.iterdir()) if d.is_dir()] # depth 1
for _ in range(max_depth):
@@ -335,7 +336,18 @@ def find_run_dirs(root: Path | str, *, predicate: Callable[[Path], bool] = is_ru
continue # a run's own subdirectories are not runs
nxt.extend(c for c in sorted(d.iterdir()) if c.is_dir())
frontier = nxt
- return sorted(found)
+ return _once(root, found)
+
+
+def _once(root: Path, dirs: list[Path]) -> list[Path]:
+ """``dirs`` sorted, one path per directory on disk: the physical path beats an alias."""
+ real = root.resolve()
+ best: dict[Path, Path] = {}
+ for d in sorted(dirs):
+ physical = d.resolve()
+ if physical not in best or physical == real / d.relative_to(root):
+ best[physical] = d
+ return sorted(best.values())
def iter_runs(
diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.md
index c5c5e500..92c6ee8c 100644
--- a/harness/docs/INTERFACES.md
+++ b/harness/docs/INTERFACES.md
@@ -633,7 +633,7 @@ from codeverse3d.addons.dataset.refine import build_refine, transitions, RefineT
# drops=None) -> Iterator[RefineTransition]; outcome_of(delta, threshold) -> the label
# one row per round i -> i+1 the harness asked to change; outcome improved|regressed|unchanged|unscored
# (threshold: pairs.MIN_PREFERENCE_DELTA); dropped rows carry the reason (no_predecessor / no_commit /
- # predecessor_build_failed / predecessor_unjudged / git_read_failed / duplicate_run)
+ # predecessor_build_failed / predecessor_unjudged / git_read_failed)
from codeverse3d.record._git import read_tree_at, diff_between, changed_files_between, GitReadError
# read_tree_at(ws, commit, *, paths=None) -> {path: bytes} via ls-tree + cat-file --batch — NEVER
# `git archive`, which renders content through a planted filter.<name>.smudge and has no --no-filters
diff --git a/harness/tests/flywheel_cli/test_flywheel.py b/harness/tests/flywheel_cli/test_flywheel.py
index 175a461c..c3b0aea0 100644
--- a/harness/tests/flywheel_cli/test_flywheel.py
+++ b/harness/tests/flywheel_cli/test_flywheel.py
@@ -445,6 +445,20 @@ def test_battery_layouts_are_discovered_by_flywheel_and_gallery(tmp_path):
assert [e.slug for e in section.entries] == ["control__ctrl_med_chair__harness_api-agent"]
+def test_a_run_reached_twice_is_found_once_at_its_physical_path(tmp_path):
+ """Batteries symlink each other's cells: export, index, pairs and the gallery counted them twice."""
+ from codeverse3d.record.record import find_run_dirs
+
+ real = tmp_path / "zz_home" / "runs" / "chair"
+ real.mkdir(parents=True)
+ (real / "record.json").write_text("{}")
+ (tmp_path / "aa_borrower" / "runs").mkdir(parents=True)
+ (tmp_path / "aa_borrower" / "runs" / "chair").symlink_to(real) # sorts first
+ assert find_run_dirs(tmp_path) == [real], "descending: one hit, the physical one"
+ (real.parent / "alias").symlink_to(real)
+ assert find_run_dirs(real.parent) == [real], "direct children: the alias collapses too"
+
+
def test_empty_run_roots_distinguish_a_failed_battery_from_legitimate_empty_input(tmp_path):
from codeverse3d.record.record import iter_runs
diff --git a/harness/tests/flywheel_cli/test_refine.py b/harness/tests/flywheel_cli/test_refine.py
index 9c39e3a6..46bdc9fd 100644
--- a/harness/tests/flywheel_cli/test_refine.py
+++ b/harness/tests/flywheel_cli/test_refine.py
@@ -71,7 +71,7 @@ def test_a_run_reached_through_a_symlink_is_exported_once_under_its_physical_bat
alias.mkdir(parents=True)
(alias / "chair").symlink_to(tmp_path / "zz_physical" / "runs" / "chair")
rows, drops = _rows(tmp_path)
- assert len(rows) == 1 and drops == {"duplicate_run": 1}
+ assert len(rows) == 1 and not drops, "a run on disk is found once"
assert rows[0].battery == "zz_physical", "labelled by the battery it was reached through first"