Skip to content

Official Codebase of 3DCodeVerse

Python

graphics: a round keeps its frame metrics, and a replay of round N quotes round N's (B3)

gaoypeng6b38597e7691
diff --git a/eval/bench/judge_calib_graphics.py b/eval/bench/judge_calib_graphics.py
index 69240eae..63e99846 100644
--- a/eval/bench/judge_calib_graphics.py
+++ b/eval/bench/judge_calib_graphics.py
@@ -60,17 +60,12 @@ def judge_one(run: Path, rubric: str, model: str, n: int) -> dict[str, Any]:
return {"run": str(run), "error": "no judged round"}
renders = RenderSet.model_validate(rnd["renders"])
gates = [GateReport.model_validate(g) for g in rnd.get("gates") or []]
- # what the in-run judge also saw: the plan digest and the measured frame metrics (the metrics
- # file is the LAST build's; it is only quoted when the picked round is the last one, else the
- # judge is told so — without it, pro called four moving effects "static" in the first pass)
- ws = Workspace(run)
+ # what the in-run judge also saw: the plan digest and the round's measured frame metrics
+ # (frame_stats_text: its own copy, never a later build's — without them, pro called four
+ # moving effects "static" in the first pass)
plan_path = run / "plan.json"
digest = plan_summary(GraphicsPlan.model_validate_json(plan_path.read_text()), spec.language) if plan_path.is_file() else ""
- last_index = max((int(f.stem[1:]) for f in run.glob("rounds/r*.json")), default=0)
- if int(rnd.get("index", 0)) == last_index:
- extra = "FRAME METRICS (harness-measured):\n" + frame_stats_text(ws)
- else:
- extra = "FRAME METRICS: not available for this round (an earlier round than the last build); judge motion from the frames."
+ extra = "FRAME METRICS (harness-measured):\n" + frame_stats_text(Workspace(run), int(rnd.get("index", 0)))
inp = JudgeInput(spec=spec, renders=renders, gates=gates, round_index=int(rnd.get("index", 0)),
plan_summary=digest, extra_context=extra)
judge = VlmJudge(rubric=rubric, model_id=model, n_samples=n)
diff --git a/harness/codeverse3d/languages/_gl_common.py b/harness/codeverse3d/languages/_gl_common.py
index 78a31f2b..bcdb1e0d 100644
--- a/harness/codeverse3d/languages/_gl_common.py
+++ b/harness/codeverse3d/languages/_gl_common.py
@@ -140,8 +140,9 @@ def finish_build(ws: Workspace, res: GlResult, *, language: str, error_file: str
return result
-def read_metrics(ws: Workspace) -> tuple[SequenceStats, GateReport] | None:
- p = ws.artifacts / METRICS_NAME
+def read_metrics(ws: Workspace, where: Path | None = None) -> tuple[SequenceStats, GateReport] | None:
+ """``metrics.json`` in ``where`` (a round's ``renders/rNN/`` copy), default the canonical one."""
+ p = (where or ws.artifacts) / METRICS_NAME
if not p.is_file():
return None
data = json.loads(p.read_text())
diff --git a/harness/codeverse3d/tracks/graphics.py b/harness/codeverse3d/tracks/graphics.py
index 56d11e43..f80f36f0 100644
--- a/harness/codeverse3d/tracks/graphics.py
+++ b/harness/codeverse3d/tracks/graphics.py
@@ -31,7 +31,7 @@ from codeverse3d.contracts.artifacts import (
from codeverse3d.contracts.common import HARNESS_OWNED_SRC, TRACK_INFO, Language, Track
from codeverse3d.contracts.plan import GraphicsPlan, Plan
from codeverse3d.contracts.run import RoundRecord
-from codeverse3d.languages._gl_common import SHEET_NAME, read_metrics
+from codeverse3d.languages._gl_common import METRICS_NAME, SHEET_NAME, read_metrics
from codeverse3d.languages.glsl_shader import COMMON_GLSL, FUNC_DEF, strip_comments
from codeverse3d.orchestrator import TaskGroup
from codeverse3d.prompts import render
@@ -306,6 +306,8 @@ def frames_render_set(ws: Workspace, build: BuildResult, round_index: int) -> Re
out.mkdir(parents=True, exist_ok=True)
frames_dir = Path(build.extra_paths.get("frames", ws.artifacts / "frames"))
metrics = read_metrics(ws)
+ if metrics is not None: # the round's own copy: what a replay of THIS round quotes (frame_stats_text)
+ shutil.copy2(ws.artifacts / METRICS_NAME, out / METRICS_NAME)
stats = metrics[0] if metrics else None
views: list[RenderView] = []
frames = stats.frames if stats else []
@@ -331,8 +333,16 @@ def frames_render_set(ws: Workspace, build: BuildResult, round_index: int) -> Re
duration_ms=build.duration_ms)
-def frame_stats_text(ws: Workspace) -> str:
- m = read_metrics(ws)
+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."""
+ 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():
+ 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)
if m is None:
return "(no frame metrics)"
stats, gate = m
@@ -357,7 +367,7 @@ class GraphicsPipeline:
def judge_context(self, ws: Workspace, plan: Plan | None, round_index: int, build: BuildResult, gates: list[GateReport]) -> str:
renderer = build.census.get("renderer", "") if isinstance(build.census, dict) else ""
- return f"FRAME METRICS (harness-measured, renderer {renderer or 'moderngl'}):\n{frame_stats_text(ws)}"
+ return f"FRAME METRICS (harness-measured, renderer {renderer or 'moderngl'}):\n{frame_stats_text(ws, round_index)}"
class GraphicsTrack(BaseTrack):
diff --git a/harness/docs/ARCHITECTURE.md b/harness/docs/ARCHITECTURE.md
index fefb4095..0761f7bd 100644
--- a/harness/docs/ARCHITECTURE.md
+++ b/harness/docs/ARCHITECTURE.md
@@ -316,7 +316,8 @@ runs/<slug>/
textures/{<id>.png, texture_plan.json, texturing.json, gate/}
rNN/ the round's own build, copied when it built: object.glb object.stl|step robot.urdf
meshes/*.glb preview.gif frames_sheet.png (only what a hand-over needs)
- renders/rNN/ view_<name>.png sheet.png views.json (judge flags) (+ poses/ articulated; <cam>_t<t>.png metrics.json scenes)
+ renders/rNN/ view_<name>.png sheet.png views.json (judge flags) (+ poses/ articulated; <cam>_t<t>.png metrics.json scenes;
+ frame_t<t>.png metrics.json graphics — the round's own frame metrics, what a replay quotes)
gates/rNN/ lint_<lang>.json connectivity.json contract.json joint_sweep.json motion_direction.json … (+ *_tool.json)
judge/rNN.json (+ rNN_cli.json from `3dcode judge`; rAA_vs_rBB_pairwise.json from `3dcode pick --by pairwise`)
tool_renders/rNN_<hash>/
diff --git a/harness/tests/graphics/test_round_metrics.py b/harness/tests/graphics/test_round_metrics.py
new file mode 100644
index 00000000..7c444bff
--- /dev/null
+++ b/harness/tests/graphics/test_round_metrics.py
@@ -0,0 +1,37 @@
+"""A graphics replay quotes the replayed round's frame metrics, never a later build's (B3)."""
+
+from __future__ import annotations
+
+import json
+
+from codeverse3d.contracts.artifacts import BuildResult, GateReport
+from codeverse3d.spatial.frame_stats import SequenceStats
+from codeverse3d.tracks.graphics import frame_stats_text, frames_render_set
+from codeverse3d.workspace import Workspace
+
+
+def _metrics(ws: Workspace, lum: float) -> None:
+ ws.artifacts.mkdir(parents=True, exist_ok=True)
+ (ws.artifacts / "metrics.json").write_text(json.dumps({
+ "stats": SequenceStats(mean_lum=lum).model_dump(mode="json"),
+ "gate": GateReport(gate="gl_frames", passed=True).model_dump(mode="json")}))
+
+
+def test_each_round_keeps_and_quotes_its_own_frame_metrics(tmp_path):
+ ws = Workspace(tmp_path / "run").create()
+ build = BuildResult(ok=True, language="glsl_shader")
+ for i, lum in enumerate((0.25, 0.75)): # two rounds: the canonical file ends as round 1's
+ _metrics(ws, lum)
+ frames_render_set(ws, build, i)
+ assert "mean_lum=0.250" in frame_stats_text(ws, 0)
+ assert "mean_lum=0.750" in frame_stats_text(ws, 1) and "mean_lum=0.750" in frame_stats_text(ws)
+
+
+def test_a_round_recorded_before_the_copy_is_not_quoted_a_later_builds_metrics(tmp_path):
+ ws = Workspace(tmp_path / "run").create()
+ _metrics(ws, 0.75) # the last build's (round 1)
+ (ws.root / "rounds").mkdir()
+ for i in (0, 1):
+ (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)