Official Codebase of 3DCodeVerse
Python
readers: the last last-build readers read the round they name — skill_targets, gallery links, calibration, the fixed judge
gaoypeng87bada17f8e1
diff --git a/eval/bench/_fixed_eval.py b/eval/bench/_fixed_eval.pyindex d32b605a..a983b52e 100644--- a/eval/bench/_fixed_eval.py+++ b/eval/bench/_fixed_eval.py@@ -3,8 +3,8 @@``FixedEvaluator.evaluate(ws, spec)``: the cell's runtime lint + build → ``measure_glb``→ connectivity gate → 14-view ``render_glb`` (articulated: + joint sweep + pose sheet;graphics: the frame sheet; scene: authored cameras + orbit rig at two times + the-scene_frames gate) → ``judge_for(spec)`` — a ``VlmJudge`` (or ``LikenessJudge``-for graphics with reference photos) on ``rubric_for(spec)``, the track's ``TRACK_INFO``+scene_frames gate) → ``judge_for(spec)`` — the class the loop would use+(``vlm_judge.judge_for``) on ``rubric_for(spec)``, the track's ``TRACK_INFO``rubric, the ONE track→rubric mapping of the compare bench. The judge's acceptance checklist is the brief's``must_have`` list (``acceptance_from_spec``) so harness and one-shot arms arescored against exactly the same checklist — never the harness's plan.@@ -116,8 +116,9 @@ class FixedEvaluator:def judge_for(self, spec: Spec) -> Any:"""The fixed judge for THIS cell: ``rubric_for(spec)`` (the pinned rubric if a caller set- one), through ``LikenessJudge`` for a graphics cell with reference photos, ``VlmJudge``- (cached per rubric) otherwise.+ one), through the class the loop would judge it with (``vlm_judge.judge_for``: reference+ photos → ``LikenessJudge`` on graphics / scene, ``ReferenceJudge`` on an object track;+ a measured rubric → ``ReferenceJudge``), else ``VlmJudge`` (cached per rubric).The evaluator judged every cell with the object rubric on a GLB. A graphics cellhas frames, not a GLB, so ``evaluate`` returned before judging and every graphics@@ -127,12 +128,13 @@ class FixedEvaluator:rubric (``shader_v2``), through ``LikenessJudge`` when the spec carries referencephotos so the arms see the same photos the loop saw."""- rubric = self.rubric if self._pinned else rubric_for(spec)- if spec.track is Track.GRAPHICS and spec.references:- from codeverse3d.judges.vlm_judge import LikenessJudge+ from codeverse3d.judges.vlm_judge import VlmJudge, judge_for- return LikenessJudge(self.judge_model, n_samples=self.n_samples, rubric=rubric)- return self._vlm_judge(rubric)+ rubric = self.rubric if self._pinned else rubric_for(spec)+ cls = judge_for(spec.track, rubric, references=bool(spec.references))+ if cls is VlmJudge:+ return self._vlm_judge(rubric)+ return cls(model_id=self.judge_model, n_samples=self.n_samples, rubric=rubric)def build(self, ws: Workspace, language: Language | str) -> tuple[BuildResult, GateReport]:rt = self.runtime(language)diff --git a/eval/bench/skill_targets.py b/eval/bench/skill_targets.pyindex 811b2dd9..e9c574dd 100644--- a/eval/bench/skill_targets.py+++ b/eval/bench/skill_targets.py@@ -78,6 +78,17 @@ class Run:return Nonereturn gated[0] if which == "first" else gated[-1]+ def round_glb(self, rd: dict) -> Path | None:+ """The round's OWN ``object.glb`` (``select.round_file``) — never ``artifacts/object.glb``,+ which is the LAST build's; None when the round kept none."""+ from codeverse3d.addons import select+ from codeverse3d.contracts.run import RoundRecord+ from codeverse3d.workspace import Workspace++ # round_file locates a round by its index alone; the raw row is not re-validated+ rnd = RoundRecord.model_construct(index=int(rd.get("index", 0)), kind=str(rd.get("kind") or ""))+ return select.round_file(Workspace(self.dir), rnd)+def render_dir(self, rd: dict) -> Path | None:"""The round's render directory, resolved inside THIS tree.@@ -214,8 +225,8 @@ def _measure_heavy(target: Target, run: Run, which: str) -> float | None:if rd is None:return Noneif target.source == SRC_GLB:- glb = run.dir / "artifacts" / "object.glb"- return _feature_density(glb) if glb.is_file() else None+ glb = run.round_glb(rd)+ return _feature_density(glb) if glb is not None else Noneif target.source == SRC_FRAMES:d = run.render_dir(rd)if d is None:diff --git a/eval/tests/test_articulated_compare.py b/eval/tests/test_articulated_compare.pyindex e8979c5e..00a30230 100644--- a/eval/tests/test_articulated_compare.py+++ b/eval/tests/test_articulated_compare.py@@ -41,6 +41,23 @@ def _urdf_spec() -> Spec:constraints=Constraints(must_have=["two revolute joints"], dimensions_m={"height": 0.6}))+def test_the_fixed_judge_is_the_class_the_loop_would_use():+ """_fixed_eval picked LikenessJudge by hand for graphics only: a scene or an object cell with+ reference photos was judged by a plain VlmJudge the loop never uses for it."""+ from codeverse3d.contracts.spec import ReferenceImage+ from codeverse3d.judges.vlm_judge import LikenessJudge, ReferenceJudge, VlmJudge++ ev = FixedEvaluator("gemini:x")+ refs = [ReferenceImage(path="ref.png")]+ lamp = _urdf_spec()+ scene = Spec(id="t/s", track=Track.SCENE, language=Language.SCENE_THREEJS, prompt="a harbour at dusk")+ shader = Spec(id="t/g", track=Track.GRAPHICS, language=Language.GLSL_SHADER, prompt="neon rain")+ assert type(ev.judge_for(lamp)) is VlmJudge+ assert type(ev.judge_for(lamp.model_copy(update={"references": refs}))) is ReferenceJudge+ assert type(ev.judge_for(scene.model_copy(update={"references": refs}))) is LikenessJudge+ assert type(ev.judge_for(shader.model_copy(update={"references": refs}))) is LikenessJudge++def test_urdf_oneshot_prompt_carries_the_frame_recipe_and_the_two_file_envelope():p = oneshot_prompt(_urdf_spec())assert "hand-written URDF" in p and "architect lamp" in p and "MUST HAVE: two revolute joints" in pdiff --git a/eval/tests/test_skill_targets_readout.py b/eval/tests/test_skill_targets_readout.pyindex 3f363b4a..5dc2525b 100644--- a/eval/tests/test_skill_targets_readout.py+++ b/eval/tests/test_skill_targets_readout.py@@ -163,3 +163,22 @@ def test_the_shader_preflight_row_reads_the_gate_not_the_raw_driver_json(tmp_patrows = {r["skill"]: r for r in battery_rows(load_runs(root), list(TARGETS), which="last", cache=None)}assert rows["c3d-threejs-shader-traps"]["n"] == 2assert rows["c3d-threejs-shader-traps"]["mean"] == 1.5 # 2 in the round, 1 in the gate file+++def test_a_glb_row_measures_the_measured_rounds_own_glb(tmp_path, monkeypatch):+ """`--round first` read artifacts/object.glb — the LAST build's — for a GLB-derived metric."""+ import bench.skill_targets as st+ from codeverse3d.addons.skill_targets import SRC_GLB, Target++ gates = [{"gate": "connectivity", "findings": CONNECTIVITY}]+ root = _battery(tmp_path, {"chair": {"spec": {"language": "blender"}, "rounds": [+ {"index": i, "gates": gates, "build": {"ok": True}} for i in (0, 1)]}})+ run_dir = root / "runs" / "chair"+ for name, byte in (("r00/object.glb", 10), ("r01/object.glb", 11), ("object.glb", 99)):+ (run_dir / "artifacts" / name).parent.mkdir(parents=True, exist_ok=True)+ (run_dir / "artifacts" / name).write_bytes(bytes([byte]))+ monkeypatch.setattr(st, "_feature_density", lambda glb: float(glb.read_bytes()[0]))+ target = Target(skill="x", metric="feature_density", direction="up", unit="", source=SRC_GLB, why="")+ run = st.load_runs(root)[0]+ assert st.measure(target, run, which="first") == 10.0+ assert st.measure(target, run, which="last") == 11.0diff --git a/harness/codeverse3d/addons/calibration.py b/harness/codeverse3d/addons/calibration.pyindex 268de1a6..18003dfd 100644--- a/harness/codeverse3d/addons/calibration.py+++ b/harness/codeverse3d/addons/calibration.py@@ -10,7 +10,7 @@ per-criterion std, defects and caps. Across rounds it reports the Pearson andSpearman correlation between gate error counts and the new scores (expectednegative), and between stored and new overalls. Optionally renders a clay /normals geometry set for the picked round (``addons/select``) when it stored none — from-its own ``artifacts/rNN/object.glb`` — so the geometry montage is exercised. Output goes to ``out_dir`` (never into the run).+its own GLB (``select.round_file``; none when it kept none) — so the geometry montage is exercised. Output goes to ``out_dir`` (never into the run).CLI: ``python -m codeverse3d.addons.calibration runs/a runs/b --model gemini:gemini-3.7-flash --n 3 --out scratch/``"""@@ -181,14 +181,18 @@ def load_run_cases(run_dir: Path, *, rounds: list[int] | None = None) -> list[Rostored=rec.judgment, is_picked=picked == rec.index,glb=str(glb) if (glb := select.round_file(ws, rec)) is not None else None,))- if picked is None and cases: # no record / nothing judged: the tree's GLB is its last round's- cases[-1].is_picked = True+ if picked is None and cases: # no record / nothing judged: the last round that kept its own GLB stands in+ next((c for c in reversed(cases) if c.glb), cases[-1]).is_picked = Truereturn casesdef render_geometry_views(case: RoundCase, out_dir: Path, mode: str) -> RenderSet | None:- """Clay/normals renders of the picked round's GLB (object tracks only)."""- if not case.glb or case.inp.spec.track.value == "scene":+ """Clay/normals renders of the picked round's own GLB (object tracks only; None when that+ round kept none — never the last build's ``artifacts/object.glb`` in its place)."""+ if case.inp.spec.track.value == "scene":+ return None+ if not case.glb:+ log.warning("no geometry views for %s r%02d: the round kept no GLB of its own", case.run, case.round_index)return Nonefrom codeverse3d.conventions import OBJECT_CLAY_VIEWSfrom codeverse3d.spatial.render import render_glbdiff --git a/harness/codeverse3d/addons/gallery/index.py b/harness/codeverse3d/addons/gallery/index.pyindex 9ccfcf79..97062a56 100644--- a/harness/codeverse3d/addons/gallery/index.py+++ b/harness/codeverse3d/addons/gallery/index.py@@ -28,6 +28,7 @@ from codeverse3d.addons.gallery.model import ()from codeverse3d.contracts.run import RunId, RunRecordfrom codeverse3d.proc import read_json_or_none+from codeverse3d.record.deliverable import round_outputs, texture_shipped_forfrom codeverse3d.record.record import (RecordError,battery_label,@@ -135,13 +136,24 @@ def _articulation_sheet(ws: Workspace, picked: int | None) -> str:def entry_links(ws: Workspace, rec: RunRecord | None, picked: int | None) -> list[RunLink]:"""The working links of a card: workspace, record, code, sheet, GLB, track extras — theartifact files of the handed-over round (``deliverable/``), else of the picked round- (``artifacts/rNN/``), else whatever ``artifacts/`` holds (a run recorded before rounds- kept their own)."""+ (``select.round_file``: ``artifacts/rNN/``, or ``artifacts/`` of a run recorded before rounds+ kept their own, for the round it rebuilt there) — never another round's. A run with no+ picked round (no record yet, none judged) links whatever ``artifacts/`` holds."""run = ws.root- kept = [f"artifacts/r{picked:02d}"] if picked is not None else []+ rnd = next((r for r in rec.rounds if r.index == picked), None) if rec is not None else None+ out = round_outputs(ws, rnd)def artifact(name: str, *extra: str) -> str:- return _first_file(run, f"deliverable/{name}", *(f"{k}/{name}" for k in kept), f"artifacts/{name}", *extra)+ if rnd is None:+ own = [f"artifacts/{name}"]+ else:+ own = [_rel(ws, out / name)] if out is not None else []+ return _first_file(run, f"deliverable/{name}", *own, *extra)++ # the texture pack is a link only when a pass SHIPPED from this round's GLB — a stray file+ # from a rejected pass (or an older harness that leaked one), or another round's pack, is not+ tex = (rec.extra.get("texturing") or {}) if rec is not None else {}+ shipped = texture_shipped_for(ws, rec, out) if rnd is not None and rec is not None else bool(tex.get("shipped"))links = [RunLink(label="workspace", rel="", kind="dir"),RunLink(label="record.json", rel="record.json")]@@ -156,10 +168,7 @@ def entry_links(ws: Workspace, rec: RunRecord | None, picked: int | None) -> lisglb = artifact("object.glb")if glb:links.append(RunLink(label="glb", rel=glb, kind="viewer"))- # the textured GLB is a link only when the texture pass SHIPPED — a stray file- # from a rejected pass (or an older harness that leaked one) is not a deliverable- tex = (rec.extra.get("texturing") or {}) if rec is not None else {}- if tex.get("shipped"):+ if shipped:textured = _first_file(run, "deliverable/object_textured.glb", "artifacts/object_textured.glb")if textured:links.append(RunLink(label="textured glb", rel=textured, kind="viewer"))@@ -172,11 +181,15 @@ def entry_links(ws: Workspace, rec: RunRecord | None, picked: int | None) -> lisgif = artifact("preview.gif")if gif:links.append(RunLink(label="preview.gif", rel=gif))- if (run / "artifacts" / "frames").is_dir():- links.append(RunLink(label="frames/", rel="artifacts/frames", kind="dir"))- for tex in ("deliverable/textures", "artifacts/textures", "public/textures"):- if (run / tex).is_dir():- links.append(RunLink(label="textures/", rel=tex, kind="dir"))+ frames = ("deliverable/frames", f"artifacts/renders/r{picked:02d}") if rnd is not None else ("artifacts/frames",)+ if rnd is not None and out == ws.artifacts:+ frames += ("artifacts/frames",) # the one round an old run rebuilt there+ frames_rel = next((f for f in frames if any((run / f).glob("f*_t*.png")) or any((run / f).glob("frame_t*.png"))), "")+ if frames_rel:+ links.append(RunLink(label="frames/", rel=frames_rel, kind="dir"))+ for tex_rel in ("deliverable/textures", "artifacts/textures" if shipped else "", "public/textures"):+ if tex_rel and (run / tex_rel).is_dir():+ links.append(RunLink(label="textures/", rel=tex_rel, kind="dir"))breakif (run / "public" / "assets").is_dir():links.append(RunLink(label="assets/", rel="public/assets", kind="dir"))diff --git a/harness/codeverse3d/addons/skill_targets.py b/harness/codeverse3d/addons/skill_targets.pyindex 4904483a..a52cee39 100644--- a/harness/codeverse3d/addons/skill_targets.py+++ b/harness/codeverse3d/addons/skill_targets.py@@ -42,7 +42,7 @@ DIRECTIONS = (DOWN, UP)#: where the readout gets the numberSRC_GATE = "gate_kinds" #: count findings of `kinds` in the last gated roundSRC_BUILD = "build" #: the round's BuildResult-SRC_GLB = "glb" #: recomputed from the exported object.glb+SRC_GLB = "glb" #: recomputed from the measured round's own object.glb (artifacts/rNN/)SRC_FRAMES = "frames" #: recomputed from the round's sampled framesSRC_ARTIFACT = "artifact" #: a gate report written beside the run, not into the recordSOURCES = (SRC_GATE, SRC_BUILD, SRC_GLB, SRC_FRAMES, SRC_ARTIFACT)diff --git a/harness/tests/flywheel_cli/test_run_layout_cli.py b/harness/tests/flywheel_cli/test_run_layout_cli.pyindex c86aa6ef..de7ebb98 100644--- a/harness/tests/flywheel_cli/test_run_layout_cli.py+++ b/harness/tests/flywheel_cli/test_run_layout_cli.py@@ -181,6 +181,21 @@ def test_rejected_texture_pass_is_not_delivered_or_linked(fake_run):assert "textured glb" in {ln.label for ln in entry.links}+def test_a_cards_links_are_the_picked_rounds_never_the_last_builds(tmp_path):+ """The gallery linked artifacts/object.glb and artifacts/frames/ — the LAST build's — when the+ picked round had no copy of its own (and frames/ always)."""+ from .conftest import tiny_png++ ws, rec = make_fake_run(tmp_path / "runs", scores=(0.90, 0.50)) # r00 is picked, r01 built last+ tiny_png(ws.artifacts / "frames" / "f00_t0.png") # the last build's frames+ tiny_png(ws.renders_dir(0) / "frame_t00.00.png") # r00's own+ links = {ln.label: ln.rel for ln in entry_from_record("runs", ws, rec).links}+ assert links["glb"] == "artifacts/r00/object.glb" and links["frames/"] == "artifacts/renders/r00"+ shutil.rmtree(ws.round_artifacts(0)) # r00 kept no build outputs+ links = {ln.label: ln.rel for ln in entry_from_record("runs", ws, rec).links}+ assert "glb" not in links++# --------------------------------------------------------------------------- showdef _show(slug: str, runs_dir: Path, *args: str):return runner.invoke(app, ["show", slug, "--runs-dir", str(runs_dir), *args])diff --git a/harness/tests/judges/test_calibration.py b/harness/tests/judges/test_calibration.pyindex 14a02966..3ba38f5f 100644--- a/harness/tests/judges/test_calibration.py+++ b/harness/tests/judges/test_calibration.py@@ -52,6 +52,20 @@ def test_load_cases_reads_the_plan_the_in_run_judge_read(tmp_path):assert load_run_cases(run, rounds=[1])[0].round_index == 1+def test_with_nothing_picked_the_stand_in_is_the_last_round_that_kept_a_glb(tmp_path, caplog):+ """No picked round: the geometry montage used the last round even when IT kept no GLB (and+ the render was skipped in silence) while an earlier round kept one."""+ from codeverse3d.addons.calibration import render_geometry_views++ run = _fake_run(tmp_path, "runB")+ (run / "artifacts" / "r00").mkdir(parents=True)+ (run / "artifacts" / "r00" / "object.glb").write_bytes(b"glTF")+ cases = load_run_cases(run)+ assert cases[0].is_picked and not cases[1].is_picked and cases[0].glb.endswith("r00/object.glb")+ assert render_geometry_views(cases[1], tmp_path / "out", "clay") is None+ assert "kept no GLB" in caplog.text++def test_correlations():assert pearson([0, 1, 2], [2, 1, 0]) == -1.0 and spearman([0, 1, 5], [5, 3, 1]) == -1.0assert pearson([1, 1], [0, 1]) is None and spearman([], []) is None