Skip to content

Official Codebase of 3DCodeVerse

Python

readers: a round's GLB, GIF, meshes and complexity are its own, never the last build's (B4, B6)

gaoypeng8345d22b6afd
diff --git a/harness/codeverse3d/addons/calibration.py b/harness/codeverse3d/addons/calibration.py
index fcd8e155..268de1a6 100644
--- a/harness/codeverse3d/addons/calibration.py
+++ b/harness/codeverse3d/addons/calibration.py
@@ -165,7 +165,6 @@ def load_run_cases(run_dir: Path, *, rounds: list[int] | None = None) -> list[Ro
except RecordError: # an interrupted run: rounds/ + spec.json
run = RunRecord(spec=Spec.model_validate_json(ws.spec_path.read_text()), workspace=str(run_dir))
picked = None
- canonical = run_dir / "artifacts" / "object.glb" # where a round's GLB was before rounds kept their own
cases: list[RoundCase] = []
for path in sorted((run_dir / "rounds").glob("r*.json")):
rec = RoundRecord.model_validate_json(path.read_text())
@@ -180,7 +179,7 @@ def load_run_cases(run_dir: Path, *, rounds: list[int] | None = None) -> list[Ro
gate_errors=sum(len(g.errors) for g in rec.gates),
gate_warnings=sum(1 for g in rec.gates for f in g.findings if f.severity.value == "warn"),
stored=rec.judgment, is_picked=picked == rec.index,
- glb=next((str(p) for p in (ws.round_artifacts(rec.index) / "object.glb", canonical) if p.is_file()), None),
+ 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
diff --git a/harness/codeverse3d/addons/dataset/export.py b/harness/codeverse3d/addons/dataset/export.py
index c59d9fd1..37e2ccb6 100644
--- a/harness/codeverse3d/addons/dataset/export.py
+++ b/harness/codeverse3d/addons/dataset/export.py
@@ -129,7 +129,7 @@ def export_one(
if entry not in written:
raise S.SampleError(f"entry file {ENTRY_FILE[record.spec.language]} missing at {code_source}")
renders = S.copy_renders(ws, rnd, dest)
- meshes = S.copy_link_meshes(ws, dest) if record.spec.language is Language.URDF_BLENDER else []
+ meshes = S.copy_link_meshes(ws, rnd, dest) if record.spec.language is Language.URDF_BLENDER else []
textured = S.copy_textured(ws, record, dest)
captions = load_captions(ws, record, captions_dir, slug=key)
(dest / "captions.json").write_text(json.dumps(_caption_texts(captions), indent=2, ensure_ascii=False))
diff --git a/harness/codeverse3d/addons/dataset/sample.py b/harness/codeverse3d/addons/dataset/sample.py
index 7c9a4f8f..1e74d816 100644
--- a/harness/codeverse3d/addons/dataset/sample.py
+++ b/harness/codeverse3d/addons/dataset/sample.py
@@ -38,10 +38,9 @@ from codeverse3d.contracts.common import (
)
from codeverse3d.contracts.run import RoundRecord, RunRecord
from codeverse3d.record import _git
-from codeverse3d.record.deliverable import deliverable_path
+from codeverse3d.record.deliverable import deliverable_path, round_outputs
from codeverse3d.record.record import (
effective_judgment,
- round_complexity,
round_summary,
)
from codeverse3d.workspace import Workspace
@@ -225,12 +224,10 @@ def copy_renders(ws: Workspace, rnd: RoundRecord | None, dest: Path) -> list[str
if not any(o.startswith("renders/sheet") for o in out):
packaged = ws.deliverable / "sheet.png" # the handed-over round's sheet
_cp(packaged if packaged.is_file() else None, "sheet.png")
- glb = deliverable_path(ws, "object.glb")
- if glb is not None and glb.stat().st_size < MAX_GLB_BYTES:
- _cp(glb, "object.glb")
- gif = deliverable_path(ws, "preview.gif") # graphics runs: animated loop preview
- if gif is not None and gif.stat().st_size < MAX_GLB_BYTES:
- _cp(gif, "preview.gif")
+ for name in ("object.glb", "preview.gif"): # the round's OWN build (graphics: its animated loop preview)
+ src = select.round_file(ws, rnd, name)
+ if src is not None and src.stat().st_size < MAX_GLB_BYTES:
+ _cp(src, name)
return out
@@ -259,11 +256,11 @@ def copy_textured(ws: Workspace, record: RunRecord, dest: Path) -> list[str]:
return out
-def copy_link_meshes(ws: Workspace, dest: Path) -> list[str]:
- """(urdf_blender) copy the per-link meshes so the sample's robot.urdf resolves
- (``deliverable/meshes/`` on the new layout, ``artifacts/meshes/`` on the old)."""
- src = next((d for d in (ws.deliverable / "meshes", ws.artifacts / "meshes") if d.is_dir()), None)
- if src is None:
+def copy_link_meshes(ws: Workspace, rnd: RoundRecord | None, dest: Path) -> list[str]:
+ """(urdf_blender) copy the round's own per-link meshes so the sample's robot.urdf resolves."""
+ out_dir = round_outputs(ws, rnd)
+ src = out_dir / "meshes" if out_dir is not None else None
+ if src is None or not src.is_dir():
return []
out: list[str] = []
total = 0
@@ -305,7 +302,7 @@ def build_meta(
n_gate_errors = sum(gates.values())
# difficulty next to quality: a tier-A five-box stool and a tier-A machine are
# not the same training sample (eval/docs/COMPLEXITY.md)
- cx = (round_complexity(rnd) if rnd is not None else None) or record.extra.get("complexity")
+ cx = select.round_complexity_block(ws, rnd)
name = ""
if record.plan is not None:
name = getattr(record.plan, "object_name", "") or getattr(record.plan, "title", "")
diff --git a/harness/codeverse3d/addons/gallery/index.py b/harness/codeverse3d/addons/gallery/index.py
index d4dc3817..9ccfcf79 100644
--- a/harness/codeverse3d/addons/gallery/index.py
+++ b/harness/codeverse3d/addons/gallery/index.py
@@ -197,28 +197,15 @@ _CX_AXES = ("part_count", "assembly_depth", "tri_count", "materials",
"silhouette", "feature_density", "symmetry_groups", "hollowness")
-def _measurement_complexity(ws: Workspace) -> dict | None:
- """The complexity block sitting in ``artifacts/measurement.json`` — how a run
- finished before the record carried its own block (and after any re-measure)."""
- data = read_json_or_none(ws.root / "artifacts" / "measurement.json") or {}
- block = (data.get("extra") or {}).get("complexity")
- return block if isinstance(block, dict) else None
-
-
def _complexity(ws: Workspace, rec: RunRecord, picked: int | None) -> tuple[float | None, str, dict[str, float]]:
- """``(index, band, axes)`` of the picked round's artifact: its own measurement,
- else the record's complexity block, else the measurement file on disk. A run built
- before the complexity vector existed has none (``eval/bench/complexity_report.py``
+ """``(index, band, axes)`` of the picked round's artifact (``select.round_complexity_block``).
+ A run built before the complexity vector existed has none (``eval/bench/complexity_report.py``
recomputes those from the GLB)."""
- from codeverse3d.record.record import round_complexity
-
- rnd = next((r for r in rec.rounds if r.index == picked), None)
try:
- block = ((round_complexity(rnd) if rnd is not None else None) or rec.extra.get("complexity")
- or _measurement_complexity(ws))
+ block = select.round_complexity_block(ws, next((r for r in rec.rounds if r.index == picked), None))
except Exception: # noqa: BLE001 - a card is never worth an exception
block = None
- if not isinstance(block, dict) or block.get("index") is None:
+ if block is None or block.get("index") is None:
return None, "", {}
axes = {a: float(block[a]) for a in _CX_AXES if isinstance(block.get(a), (int, float))}
return float(block["index"]), str(block.get("band") or ""), axes
diff --git a/harness/codeverse3d/addons/select.py b/harness/codeverse3d/addons/select.py
index 63a515f0..556ec077 100644
--- a/harness/codeverse3d/addons/select.py
+++ b/harness/codeverse3d/addons/select.py
@@ -15,6 +15,8 @@ other reader asks (gallery, dataset, cost report, calibration, the CLI, eval/ben
* :func:`summarise` baseline score, the picked round and its score, the delta, rounds run
and the stop reason — the round ``selection.json`` names when the run
was packaged, else :func:`pick`'s;
+* :func:`round_file` a round's OWN build output (its GLB, GIF), never the last build's —
+ and :func:`round_complexity_block` its complexity vector;
* :func:`package` ``deliverable/`` for one round, the texture pass on it when asked, and
``selection.json`` (round, method, scores) beside ``record.json``.
@@ -32,13 +34,13 @@ from typing import Any, Literal
from pydantic import BaseModel, Field
from codeverse3d.contracts.common import TRACK_INFO, Usage
-from codeverse3d.contracts.run import RunRecord
+from codeverse3d.contracts.run import RoundRecord, RunRecord
from codeverse3d.cost.context import call_context
from codeverse3d.cost.types import Role, Stage
from codeverse3d.judges.base import judged_subset, resolve_paths
from codeverse3d.proc import EventLog, read_json_or_none
from codeverse3d.record.deliverable import build_deliverable, round_outputs, texture_report_for
-from codeverse3d.record.record import effective_judgment, load_record, package_run
+from codeverse3d.record.record import effective_judgment, load_record, package_run, round_complexity
from codeverse3d.workspace import Workspace
log = logging.getLogger(__name__)
@@ -127,6 +129,25 @@ def _ranked(rows: list[RoundRow]) -> list[RoundRow]:
return sorted((r for r in rows if r.score is not None), key=lambda r: (-(r.score or 0.0), r.gate_errors, r.index))
+# --------------------------------------------------------------------------- a round's own outputs
+def round_file(ws: Workspace, rnd: RoundRecord | None, name: str = "object.glb") -> Path | None:
+ """Round ``rnd``'s own build output ``name`` (``record.deliverable.round_outputs``), else
+ None — never the canonical ``artifacts/<name>`` on its own: that is the LAST build's."""
+ out = round_outputs(ws, rnd)
+ p = out / name if out is not None else None
+ return p if p is not None and p.is_file() else None
+
+
+def round_complexity_block(ws: Workspace, rnd: RoundRecord | None) -> dict | None:
+ """Round ``rnd``'s complexity vector: its own measurement's block, else — a run recorded
+ before rounds carried one — ``artifacts/measurement.json``'s when that canonical build is
+ this round's. Never another round's (``record.extra["complexity"]`` is the LAST one's)."""
+ block = round_complexity(rnd) if rnd is not None else None
+ if block is None and rnd is not None and round_outputs(ws, rnd) == ws.artifacts:
+ block = ((read_json_or_none(ws.artifacts / "measurement.json") or {}).get("extra") or {}).get("complexity")
+ return block if isinstance(block, dict) else None
+
+
# --------------------------------------------------------------------------- pick
def pick(run_dir: Path | str, *, by: PickBy = "score", pairwise_model: str | None = None,
record: RunRecord | None = None, judge: Any | None = None) -> int | None:
@@ -249,9 +270,8 @@ def _texture(ws: Workspace, rec: RunRecord, index: int, *, image_model: Any | No
if not texture_supported(rec.spec.track):
raise ValueError(f"the texture pass is for object tracks; {rec.spec.track.value} runs have no GLB to texture")
rnd = next(r for r in rec.rounds if r.index == index)
- out = round_outputs(ws, rnd)
- glb = out / "object.glb" if out is not None else None
- if glb is None or not glb.is_file():
+ glb = round_file(ws, rnd)
+ if glb is None:
raise ValueError(f"round {index} kept no object.glb to texture (artifacts/r{index:02d}/)")
if texture_report_for(ws, glb) is not None:
EventLog(ws.events_path).emit("texture.skipped", reason="already_textured_this_artifact", round=index)
diff --git a/harness/codeverse3d/cli/_judge.py b/harness/codeverse3d/cli/_judge.py
index 4ccf741c..72f0b8d2 100644
--- a/harness/codeverse3d/cli/_judge.py
+++ b/harness/codeverse3d/cli/_judge.py
@@ -107,13 +107,12 @@ def build_judge_input(ws: Workspace, rec: RunRecord, rnd: RoundRecord) -> Any:
def stored_glb_path(ws: Workspace, rnd: RoundRecord) -> str | None:
- """The round's canonical GLB, rebased to THIS workspace — what lets ``3dcode judge``
- reproduce the D48 conditional slice payload from the stored gates."""
- if rnd.build is None or not rnd.build.glb_path:
- return None
- kept = ws.round_artifacts(rnd.index) / "object.glb" # the round's own GLB; the stored path is
- p = kept if kept.is_file() else ws.rebase(rnd.build.glb_path) # the canonical one, rebuilt since
- return str(p) if p.is_file() else None
+ """The round's own GLB (``select.round_file``; never the canonical one, the last build's)
+ — what lets ``3dcode judge`` reproduce the D48 conditional slice payload from the stored gates."""
+ from codeverse3d.addons.select import round_file
+
+ glb = round_file(ws, rnd)
+ return str(glb) if glb is not None else None
def make_judge(spec: Spec, rubric_name: str, model_id: str, n: int, **options: Any) -> Any:
diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.md
index de38107f..af45b191 100644
--- a/harness/docs/INTERFACES.md
+++ b/harness/docs/INTERFACES.md
@@ -623,6 +623,10 @@ select.summarise(run_dir, *, record=None) -> RunSummary{rounds, stop_reason, bas
select.package(run_dir, round_index, *, texture=False, method="round", image_model=None) -> Path (deliverable/)
# + selection.json {round, method, scores, textured, selected_at}; texture=True runs the pass on that round's
# kept GLB unless a report already covers those bytes; a failed pass never fails the hand-over
+select.round_file(ws, rnd, name="object.glb") -> Path | None # the round's OWN output (round_outputs), never the
+ # canonical artifacts/<name> (the last build's): calibration, `3dcode judge`, `texture pass`, export, eval/bench
+select.round_complexity_block(ws, rnd) -> dict | None # its own measurement's vector (legacy: measurement.json only
+ # when the canonical build is this round's); gallery cards and dataset meta. Never record.extra["complexity"]
from codeverse3d.addons.gallery.index import hero_view # (ws, rec, picked) -> (rel, label, n_views): the card image
from codeverse3d.record.record import complexity_block, round_complexity # objective complexity of what was built
# finalize_record fills record.extra["complexity"] = the LAST measured round's vector + plan_parts /
diff --git a/harness/docs/RUN_LAYOUT.md b/harness/docs/RUN_LAYOUT.md
index 5ce2f6a3..9bb27afe 100644
--- a/harness/docs/RUN_LAYOUT.md
+++ b/harness/docs/RUN_LAYOUT.md
@@ -181,7 +181,8 @@ package's own command, `3dcode cost show <runs-dir>`.
`deliverable/` or `telemetry/` present.
* Consumers resolve artifacts through
`record.deliverable.deliverable_path(ws, name)`: `deliverable/<name>` first,
- `artifacts/<name>` second.
+ `artifacts/<name>` second. A reader that wants a given ROUND's file asks
+ `addons.select.round_file(ws, rnd, name)` (`round_outputs`), never `artifacts/<name>`.
* `flywheel export` reads the packaged code snapshot only when git cannot answer
(`meta.code_source == "deliverable"`), and adds a compact `meta.telemetry`
digest when the run has one (`{}` otherwise).
diff --git a/harness/tests/flywheel_cli/test_flywheel.py b/harness/tests/flywheel_cli/test_flywheel.py
index c3b0aea0..85e230ad 100644
--- a/harness/tests/flywheel_cli/test_flywheel.py
+++ b/harness/tests/flywheel_cli/test_flywheel.py
@@ -377,7 +377,9 @@ def test_export_graphics_sample(tmp_path: Path):
from tests.flywheel_cli.conftest import make_fake_run, tiny_png
ws, rec = make_fake_run(tmp_path / "runs", "rain_glsl", prompt="neon rain", language=Language.GLSL_SHADER)
- tiny_png(ws.artifacts / "preview.gif") # gif magic irrelevant here — copied by name
+ for r in rec.rounds: # each round keeps its own preview (gif magic irrelevant here — copied by name)
+ tiny_png(ws.round_artifacts(r.index) / "preview.gif")
+ tiny_png(ws.artifacts / "preview.gif") # the canonical one is the LAST build's: never exported for another round
out = tmp_path / "ds"
rep = export_samples(ws.root.parent, out)
assert rep.n_exported == 1, rep.skipped
diff --git a/harness/tests/flywheel_cli/test_quality_gallery.py b/harness/tests/flywheel_cli/test_quality_gallery.py
index beaa11aa..c1bc866b 100644
--- a/harness/tests/flywheel_cli/test_quality_gallery.py
+++ b/harness/tests/flywheel_cli/test_quality_gallery.py
@@ -75,9 +75,10 @@ def test_whitespace_inside_a_string_is_a_near_duplicate_not_a_duplicate(runs_dir
def test_export_meta_tiers_duplicates_and_captions_sidecar(runs_dir: Path, tmp_path: Path):
# a fourth run = exact duplicate (same code + prompt) of the first, and a urdf run with link meshes
make_fake_run(runs_dir, "wooden_chair_again")
- ws_u, _ = make_fake_run(runs_dir, "cabinet_urdf", prompt="a cabinet", language=Language.URDF_BLENDER)
- (ws_u.artifacts / "meshes").mkdir()
- (ws_u.artifacts / "meshes" / "Body.glb").write_bytes(b"glTF" + b"\0" * 8)
+ ws_u, rec_u = make_fake_run(runs_dir, "cabinet_urdf", prompt="a cabinet", language=Language.URDF_BLENDER)
+ for r in rec_u.rounds: # each round keeps its own link meshes (artifacts/rNN/meshes/)
+ (ws_u.round_artifacts(r.index) / "meshes").mkdir()
+ (ws_u.round_artifacts(r.index) / "meshes" / "Body.glb").write_bytes(b"glTF" + b"\0" * 8)
side = tmp_path / "caps"
side.mkdir()
(side / "lamp_three.json").write_text(json.dumps({**GOOD, "provenance": {"captioner": "gemini:x"}}))
diff --git a/harness/tests/flywheel_cli/test_select.py b/harness/tests/flywheel_cli/test_select.py
index 6ce737e0..c42db0e5 100644
--- a/harness/tests/flywheel_cli/test_select.py
+++ b/harness/tests/flywheel_cli/test_select.py
@@ -279,3 +279,25 @@ def test_make_hands_over_the_picked_round_unless_no_pick(tmp_path, monkeypatch):
"--no-pick"])
assert r.exit_code == 0, r.output
assert not (runs / "kept" / "selection.json").exists() and not (runs / "kept" / "deliverable" / "manifest.json").exists()
+
+
+# --------------------------------------------------------------------------- a round's own outputs
+def test_round_outputs_are_the_rounds_own_never_the_last_builds(tmp_path: Path):
+ """artifacts/object.glb and measurement.json are the LAST build's: a reader asking for round N's
+ GLB or complexity got the last round's (calibration, `3dcode judge`, the export, gallery, dataset)."""
+ ws = _run(tmp_path / "r", [(0.8, 0), (0.6, 0)])
+ rec = RunRecord.model_validate_json(ws.record_path.read_text())
+ (ws.artifacts / "object.glb").write_bytes(b"last")
+ ws.write_json(ws.artifacts / "measurement.json", {"extra": {"complexity": {"index": 0.9}}})
+ assert select.round_file(ws, rec.rounds[0]) == ws.round_artifacts(0) / "object.glb"
+ assert select.round_file(ws, rec.rounds[0], "preview.gif") is None
+ assert select.round_complexity_block(ws, rec.rounds[0]) is None # never the canonical file's
+ # a run recorded before rounds kept their own: the canonical build is its best_round's only
+ for i in (0, 1):
+ (ws.round_artifacts(i) / "object.glb").unlink()
+ ws.round_artifacts(i).rmdir()
+ data = json.loads(ws.record_path.read_text())
+ ws.write_json(ws.record_path, {**data, "best_round": 1})
+ assert select.round_file(ws, rec.rounds[0]) is None
+ assert select.round_file(ws, rec.rounds[1]) == ws.artifacts / "object.glb"
+ assert select.round_complexity_block(ws, rec.rounds[1]) == {"index": 0.9}
diff --git a/harness/tests/judges/test_judge_slices.py b/harness/tests/judges/test_judge_slices.py
index 3901b397..1ae1e56e 100644
--- a/harness/tests/judges/test_judge_slices.py
+++ b/harness/tests/judges/test_judge_slices.py
@@ -190,7 +190,8 @@ def test_a_dirty_round_with_a_floating_only_error_still_elicits(tmp_path, cache_
def test_replay_reproduces_the_conditional_payload_from_stored_gates_and_glb(tmp_ws: Workspace, tmp_path, cache_dir):
from codeverse3d.cli._judge import build_judge_input
- glb = two_box_glb(tmp_path / "object.glb")
+ tmp_ws.round_artifacts(0).mkdir(parents=True)
+ glb = two_box_glb(tmp_ws.round_artifacts(0) / "object.glb") # the round's own GLB (artifacts/r00/)
renders = make_renders(tmp_path / "renders")
rec = RunRecord(spec=make_spec(), workspace=str(tmp_ws.root))
rnd = RoundRecord(index=0, kind="baseline", gates=dirty_gates(), renders=renders,
@@ -206,7 +207,8 @@ def test_replay_reproduces_the_conditional_payload_from_stored_gates_and_glb(tmp
scene_rec = RunRecord(spec=make_spec(track="scene", language="scene_threejs"), workspace=str(tmp_ws.root))
assert build_judge_input(tmp_ws, scene_rec, rnd).glb_path is None
- # a moved/deleted glb disables the channel instead of crashing the replay
- rnd_gone = rnd.model_copy(update={"build": BuildResult(ok=True, language="blender",
- glb_path=str(tmp_path / "gone.glb"))})
- assert build_judge_input(tmp_ws, rec, rnd_gone).glb_path is None
+ # the canonical GLB is the LAST build's, never another round's; a deleted one disables the
+ # channel instead of crashing the replay
+ assert build_judge_input(tmp_ws, rec, rnd.model_copy(update={"index": 1})).glb_path is None
+ glb.unlink()
+ assert build_judge_input(tmp_ws, rec, rnd).glb_path is None