Skip to content

Official Codebase of 3DCodeVerse

Python

graphics: an old run's canonical metrics.json is quoted for the round its finalise rebuilt (best_round), not the highest (B3)

gaoypeng1549b1bbae42
diff --git a/harness/codeverse3d/tracks/graphics.py b/harness/codeverse3d/tracks/graphics.py
index 698bcc73..ae1c4fcc 100644
--- a/harness/codeverse3d/tracks/graphics.py
+++ b/harness/codeverse3d/tracks/graphics.py
@@ -41,6 +41,7 @@ from codeverse3d.languages.glsl_shader import (
from codeverse3d.orchestrator import TaskGroup
from codeverse3d.prompts import render
from codeverse3d.prompts.sections import Section, split_sections
+from codeverse3d.record.deliverable import legacy_canonical_round
from codeverse3d.tracks.common import RunContext
from codeverse3d.tracks.generation import GenerationTask
from codeverse3d.tracks.lifecycle import MATERIALIZE, SKELETON, BaseTrack, StageNode
@@ -339,11 +340,14 @@ def frames_render_set(ws: Workspace, build: BuildResult, round_index: int) -> Re
def frame_stats_text(ws: Workspace, round_index: int | None = None) -> str:
"""The frame metrics as judge / refine text: round ``round_index``'s own copy
- (``renders/rNN/metrics.json``), else the canonical file — the LAST build's, so for a round
- rendered before rounds kept a copy it is quoted only when no later round exists."""
+ (``renders/rNN/metrics.json``), else the canonical file, quoted only for the round it belongs
+ to — the round an old run's finalise rebuilt (``legacy_canonical_round``: its best), else
+ the LAST build's (no later round in the journal)."""
where = ws.renders_dir(round_index) if round_index is not None else None
- if where is not None and not (where / METRICS_NAME).is_file():
- if (ws.root / "rounds" / f"r{round_index + 1:02d}.json").is_file():
+ if round_index is not None and where is not None and not (where / METRICS_NAME).is_file():
+ owner = legacy_canonical_round(ws)
+ later = any(int(p.stem[1:]) > round_index for p in (ws.root / "rounds").glob("r[0-9][0-9].json"))
+ if (owner != round_index) if owner is not None else later:
return "(not kept for this round: the metrics on disk are a later build's; judge motion from the frames)"
where = None
m = read_metrics(ws, where)
diff --git a/harness/tests/graphics/test_round_metrics.py b/harness/tests/graphics/test_round_metrics.py
index 7c444bff..8f7bfb56 100644
--- a/harness/tests/graphics/test_round_metrics.py
+++ b/harness/tests/graphics/test_round_metrics.py
@@ -35,3 +35,18 @@ def test_a_round_recorded_before_the_copy_is_not_quoted_a_later_builds_metrics(t
(ws.root / "rounds" / f"r{i:02d}.json").write_text("{}")
assert "later build" in frame_stats_text(ws, 0) and "mean_lum" not in frame_stats_text(ws, 0)
assert "mean_lum=0.750" in frame_stats_text(ws, 1)
+
+
+def test_an_old_graphics_run_quotes_the_canonical_metrics_for_the_round_its_finalise_rebuilt(tmp_path):
+ """smoke_glsl-like: three rounds recorded before rounds kept a copy; the old finalise rebuilt
+ the best (``best_round`` 1), so artifacts/metrics.json is round 1's — not round 2's (the
+ highest), and not "a later build's" for round 1."""
+ ws = Workspace(tmp_path / "run").create()
+ _metrics(ws, 0.5) # round 1's, rebuilt by the old finalise
+ (ws.root / "rounds").mkdir()
+ for i in (0, 1, 2):
+ (ws.root / "rounds" / f"r{i:02d}.json").write_text("{}")
+ ws.write_json(ws.record_path, {"best_round": 1})
+ assert "mean_lum=0.500" in frame_stats_text(ws, 1)
+ for i in (0, 2):
+ assert "mean_lum" not in frame_stats_text(ws, i)