Download tasks/t20-blender-donut-40/tests/test_outputs.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 27 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t20-blender-donut-40/tests/test_outputs.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t20-blender-donut-40/tests/test_outputs.py
-
curl -L -o test_outputs.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t20-blender-donut-40/tests/test_outputs.py
27 kB
| """ | |
| Verifier for t20 (Beginner Blender 4.0 donut tutorial, 14 parts, GUI only), | |
| graded against a real learner's reference saves. | |
| The reference is thecrazymage/Blender-Donut-Tutorial: `Donut_1..13.blend`, one | |
| save per part, made in Blender 4.0 while following the same videos. Their | |
| inventories (tests/reference/inv*.json, made by tools/inventory.py) define what | |
| each part leaves behind; `Donut_13.blend` is the hidden end-state reference | |
| and doubles as the oracle. Because the tutorial uses randomisers (sprinkle | |
| scatter, sculpting, painted textures) and the learner's own choices (which | |
| icing colours, how many donuts), nothing is compared exactly: every structural | |
| item is a TOLERANCE BAND around the reference value, and the final image is | |
| compared as a RENDER PAIR (both scenes rendered inside the verifier with | |
| identical Cycles settings, similarity mapped through a threshold band) — the | |
| same two-layer approach refresh-platform's Blender verifiers use. | |
| Score = 0.90 structural milestones (parts 1-13, weights roughly per part) + | |
| 0.10 render-pair similarity. | |
| No-op floor 0.0 (no .blend). Oracle (the reference itself) ~1.0. Negative | |
| controls: Donut_6 / Donut_9 grade partway (see RUBRIC.md). | |
| """ | |
| from __future__ import annotations | |
| import glob | |
| import json | |
| import math | |
| import os | |
| import shutil | |
| import statistics | |
| import subprocess | |
| from pathlib import Path | |
| try: | |
| import pytest | |
| except ImportError: | |
| class _NoPytest: | |
| def fixture(*a, **k): | |
| return lambda f: f | |
| pytest = _NoPytest() # type: ignore | |
| REWARD_PATH = os.environ.get("REWARD_PATH", "/logs/verifier/reward.txt") | |
| BLENDER = os.environ.get("BLENDER_BIN", "/opt/blender/blender") | |
| HERE = Path(__file__).resolve().parent | |
| INSPECT = str(HERE / "inspect_blend.py") | |
| RENDER_VIEW = str(HERE / "render_view.py") | |
| REFERENCE = HERE / "reference" | |
| GRADE_DIR = Path(os.environ.get("T20_GRADE_DIR", "/tmp/t20-grade")) | |
| SEARCH_ROOTS = [p for p in os.environ.get("T20_ROOTS", "/root").split(":") if p] | |
| PREFERRED = "/root/donut/donut.blend" | |
| RENDER_PATH = os.environ.get("T20_RENDER", "/root/donut/render.png") | |
| ASSETS_DIR = os.environ.get("T20_ASSETS", "/root/Downloads") | |
| DO_RENDER_PAIR = os.environ.get("T20_RENDER_PAIR", "1") == "1" | |
| WEIGHTS = { | |
| "p01_started": 0.03, | |
| "p02_donut": 0.06, | |
| "p03_icing": 0.07, | |
| "p04_sculpt": 0.06, | |
| "p05_shading": 0.08, | |
| "p06_geometry_nodes": 0.08, | |
| "p07_long_sprinkles": 0.07, | |
| "p08_render_setup": 0.06, | |
| "p09_layout": 0.10, | |
| "p10_lighting": 0.08, | |
| "p11_compositing": 0.07, | |
| "p12_animation": 0.07, | |
| "p13_final_render": 0.07, | |
| "render_pair": 0.10, | |
| } | |
| assert abs(sum(WEIGHTS.values()) - 1.0) < 1e-9 | |
| # --------------------------------------------------------------------------- | |
| # discovery / dump / render | |
| # --------------------------------------------------------------------------- | |
| def find_blends(): | |
| found = [] | |
| for root in SEARCH_ROOTS: | |
| for depth in ("*.blend", "*/*.blend", "*/*/*.blend", "*/*/*/*.blend"): | |
| for f in glob.glob(os.path.join(root, depth)): | |
| if any(x in f for x in ("/.config/", "/.local/", "/.cache/", "/Downloads/")): | |
| continue | |
| # the Poliigon model files the agent may copy/append from (never a deliverable) | |
| if f.endswith("_Blender_Cycles.blend") or any(a in f for a in ("GlasswareWhiskeySet", "PlantAgave", "QuartziteDenali")): | |
| continue | |
| if f.endswith(".blend1") or os.path.basename(f) == "quit.blend": | |
| continue | |
| found.append(f) | |
| return sorted(set(found), key=lambda f: (f != PREFERRED, -os.path.getmtime(f))) | |
| def run_blender(args, timeout, log_name): | |
| GRADE_DIR.mkdir(parents=True, exist_ok=True) | |
| try: | |
| r = subprocess.run([BLENDER, *args], capture_output=True, text=True, timeout=timeout, | |
| env={**os.environ, "HOME": "/tmp/t20-verifier-home", "DISPLAY": ""}) | |
| except subprocess.TimeoutExpired: | |
| (GRADE_DIR / log_name).write_text("TIMEOUT") | |
| return None | |
| (GRADE_DIR / log_name).write_text(r.stdout[-30000:] + "\n---stderr---\n" + r.stderr[-10000:]) | |
| return r | |
| def dump(blend): | |
| out = GRADE_DIR / (Path(blend).stem + ".json") | |
| r = run_blender(["-b", blend, "-Y", "--python", INSPECT, "--", str(out)], 600, Path(blend).stem + ".inspect.log") | |
| if r is None or not out.exists(): | |
| print(f"[verifier] inspect failed on {blend}") | |
| return None | |
| return json.loads(out.read_text()) | |
| def render_pair(blend): | |
| """Render candidate and reference the same way; return similarity dict or None.""" | |
| a_png = GRADE_DIR / "candidate.png" | |
| b_png = GRADE_DIR / "reference.png" | |
| cmp_json = GRADE_DIR / "render_pair.json" | |
| ra = run_blender(["-b", blend, "-Y", "--python", RENDER_VIEW, "--", "render", str(a_png), ASSETS_DIR], 900, "render_candidate.log") | |
| if ra is None or not a_png.exists(): | |
| print("[verifier] candidate render failed (no camera / crash / timeout)") | |
| return None | |
| ref_blend = str(REFERENCE / "Donut_13.blend") | |
| cached = REFERENCE / "reference_render.png" | |
| if cached.exists(): | |
| shutil.copy(cached, b_png) | |
| else: | |
| rb = run_blender(["-b", ref_blend, "-Y", "--python", RENDER_VIEW, "--", "render", str(b_png), ASSETS_DIR], 900, "render_reference.log") | |
| if rb is None or not b_png.exists(): | |
| print("[verifier] reference render failed — infrastructure; render_pair skipped") | |
| return None | |
| rc = run_blender(["-b", "-Y", "--python", RENDER_VIEW, "--", "compare", str(a_png), str(b_png), str(cmp_json)], 300, "render_compare.log") | |
| if rc is None or not cmp_json.exists(): | |
| return None | |
| return json.loads(cmp_json.read_text()) | |
| # --------------------------------------------------------------------------- | |
| # helpers | |
| # --------------------------------------------------------------------------- | |
| def meshes(d): | |
| return [o for o in d.get("objects", []) if o.get("type") == "MESH" and o.get("topology")] | |
| def mods(o): | |
| return (o or {}).get("modifiers") or [] | |
| def has_mod(o, t): | |
| return any(m["type"] == t for m in mods(o)) | |
| def mats(o): | |
| return (o or {}).get("materials") or [] | |
| def nodes(o, t=None): | |
| return [n for m in mats(o) for n in m.get("nodes", []) if t is None or n["type"] == t] | |
| def dims(o): | |
| return (o or {}).get("dimensions") or [0, 0, 0] | |
| def band(value, lo, hi, soft=0.5): | |
| """1 inside [lo, hi]; linear to 0 at soft*lo / hi/soft outside.""" | |
| if value is None: | |
| return 0.0 | |
| if lo <= value <= hi: | |
| return 1.0 | |
| if value < lo: | |
| floor = lo * soft | |
| return max(0.0, (value - floor) / max(lo - floor, 1e-9)) | |
| ceil = hi / soft | |
| return max(0.0, (ceil - value) / max(ceil - hi, 1e-9)) | |
| def identify(d): | |
| ms = meshes(d) | |
| tf = d.get("torus_fit") | |
| donuts = [] | |
| for o in ms: | |
| if o["name"].lower().startswith("icing"): | |
| continue | |
| t = o["topology"] | |
| # a donut: closed genus-1 mostly-quad mesh, roughly torus proportions, not a plate | |
| if t["boundary_edges"] == 0 and t["euler"] == 0 and t["quad_fraction"] > 0.9 and t["components"] == 1: | |
| dm = dims(o) | |
| if dm[2] > 0 and 0.2 < dm[2] / max(dm[0], 1e-6) < 0.7 and abs(dm[0] - dm[1]) < 0.15 * max(dm[0], 1e-6): | |
| donuts.append(o) | |
| named_donut = [o for o in ms if o["name"].lower().startswith(("donut", "torus"))] | |
| for o in named_donut: | |
| if o not in donuts and o["topology"]["euler"] == 0: | |
| donuts.append(o) | |
| donut = None | |
| if tf and tf.get("object"): | |
| donut = next((o for o in ms if o["name"] == tf["object"]), None) | |
| if donut is None and donuts: | |
| donut = donuts[0] | |
| icings = [o for o in ms if o["name"].lower().startswith("icing")] | |
| if not icings and donut: | |
| for o in ms: | |
| if o is donut or o in donuts: | |
| continue | |
| bb, db = o.get("bbox_base"), donut.get("bbox_base") | |
| if bb and db and abs(bb["center"][0] - db["center"][0]) < 0.6 * db["dim"][0] and abs(bb["center"][1] - db["center"][1]) < 0.6 * db["dim"][1] \ | |
| and o.get("mean_z_base", db["center"][2]) > db["center"][2] and 0.7 < bb["dim"][0] / max(db["dim"][0], 1e-6) < 1.4: | |
| icings.append(o) | |
| # an unnamed icing sits on a donut's top half; never count it as a donut | |
| donuts = [o for o in donuts if o not in icings] | |
| icing = None | |
| if icings: | |
| # the icing that belongs to the fitted donut, else the first | |
| icing = next((o for o in icings if donut and o.get("parent") == donut["name"]), icings[0]) | |
| rest = [o for o in ms if o not in donuts and o not in icings and o is not donut] | |
| def named(keys): | |
| return [o for o in rest if any(k in o["name"].lower() for k in keys)] | |
| plate = (named(("plate",)) or [None])[0] | |
| if plate is None and donut: | |
| dw = max(dims(donut)[:2]) | |
| c = [o for o in rest if 1.5 * dw <= max(dims(o)[:2]) <= 5 * dw and dims(o)[2] < 0.5 * dw and o["topology"]["verts"] >= 200] | |
| plate = max(c, key=lambda o: o["topology"]["verts"]) if c else None | |
| counter = (named(("counter", "plane", "table", "floor")) or [None])[0] | |
| if counter is None: | |
| c = [o for o in rest if o is not plate and o["topology"]["verts"] <= 8 and max(dims(o)[:2]) >= 0.5 and dims(o)[2] < 0.05] | |
| counter = max(c, key=lambda o: max(dims(o)[:2])) if c else None | |
| backsplash = (named(("backsplash", "wall")) or [None])[0] | |
| if backsplash is None: | |
| c = [o for o in rest if o is not counter and o["topology"]["verts"] <= 8 and dims(o)[2] >= 0.3 and min(dims(o)[:2]) < 0.05] | |
| backsplash = c[0] if c else None | |
| room = (named(("cube", "room", "kitchen", "enclosure")) or [None])[0] | |
| if room is None: | |
| c = [o for o in rest if 8 <= o["topology"]["verts"] <= 40 and min(dims(o)) > 0.5 and len(mats(o)) >= 1] | |
| room = c[0] if c else None | |
| tiny = [o for o in rest if 0 < max(dims(o)) < 0.03] | |
| spheres = [o for o in tiny if abs(dims(o)[0] - dims(o)[2]) < 0.3 * max(dims(o)) and abs(dims(o)[1] - dims(o)[2]) < 0.3 * max(dims(o))] | |
| cylinders = [o for o in tiny if o not in spheres] | |
| appended = [o for o in rest if any(k in o["name"].lower() for k in ("glassware", "whiskey", "decanter", "agave", "plant", "utensil", "jar"))] | |
| return {"donut": donut, "donuts": donuts, "icing": icing, "icings": icings, "plate": plate, "counter": counter, | |
| "backsplash": backsplash, "room": room, "spheres": spheres, "cylinders": cylinders, "appended": appended, "torus": tf} | |
| # --------------------------------------------------------------------------- | |
| # checks: (fraction, note). Reference values from inv*.json are quoted inline. | |
| # --------------------------------------------------------------------------- | |
| def check_p01_started(d, ids, blend): | |
| s, notes = 0.0, [] | |
| if blend == PREFERRED: | |
| s += 0.5; notes.append("saved at /root/donut/donut.blend") | |
| else: | |
| s += 0.25; notes.append(f"saved at {blend}") | |
| if d.get("cameras") and meshes(d): | |
| s += 0.5; notes.append("camera + mesh in scene") | |
| return s, ", ".join(notes) | |
| def check_p02_donut(d, ids, blend): | |
| dn, tf = ids["donut"], ids["torus"] | |
| if not dn: | |
| return 0.0, "no torus-like donut mesh" | |
| s, notes = 0.3, [f"donut {dn['name']}"] | |
| if has_mod(dn, "SUBSURF"): | |
| s += 0.2; notes.append("Subdivision") | |
| if dn["topology"]["smooth_fraction"] >= 0.9: | |
| s += 0.2; notes.append("shade smooth") | |
| if tf and tf["r"] > 0 and tf["resid_mean"] / tf["r"] >= 0.03: | |
| s += 0.15; notes.append(f"deformed ({tf['resid_mean'] / tf['r']:.3f} r)") | |
| else: | |
| notes.append("still a perfect torus") | |
| v = dn["topology"]["verts"] | |
| b = band(v, 250, 1200) # ref 384 (Torus 32x12); default 48x12 = 576 | |
| s += 0.15 * b; notes.append(f"verts={v}") | |
| return min(1.0, s), ", ".join(notes) | |
| def check_p03_icing(d, ids, blend): | |
| ic, tf, dn = ids["icing"], ids["torus"], ids["donut"] | |
| if not ic: | |
| return 0.0, "no icing mesh over the donut" | |
| s, notes = 0.3, [f"icing {ic['name']}"] | |
| if ic["name"].lower().startswith("icing"): | |
| s += 0.1; notes.append("named") | |
| t = ic["topology"] | |
| if has_mod(ic, "SOLIDIFY") or (dn and t["verts"] >= 4 * dn["topology"]["verts"]): | |
| s += 0.2; notes.append(f"thickness/applied (verts={t['verts']})") | |
| ang = ic.get("angular_base") or (ic.get("evaluated") or {}).get("angular") | |
| if ang and tf: | |
| mz = [z for z in ang["min_z"] if z is not None] | |
| if mz: | |
| cz, r = tf["center"][2], tf["r"] | |
| sd = statistics.pstdev(mz) / max(r, 1e-6) | |
| if sd >= 0.03: | |
| s += 0.1; notes.append(f"wavy rim ({sd:.2f} r)") | |
| if min(mz) <= cz - 0.1 * r: | |
| s += 0.2; notes.append("drips below the centre line") | |
| if t["smooth_fraction"] >= 0.9: | |
| s += 0.1; notes.append("smooth") | |
| return min(1.0, s), ", ".join(notes) | |
| def check_p04_sculpt(d, ids, blend): | |
| ic = ids["icing"] | |
| if not ic: | |
| return 0.0, "no icing" | |
| t = ic["topology"] | |
| s, notes = 0.0, [] | |
| if t["boundary_edges"] == 0 and t["verts"] >= 6000: # ref 27776 after solidify+subsurf applied | |
| s += 0.5; notes.append(f"solid, dense icing (verts={t['verts']})") | |
| elif t["verts"] >= 2000: | |
| s += 0.25; notes.append(f"dense icing (verts={t['verts']})") | |
| td = ic.get("torus_dist_base") | |
| if has_mod(ic, "SHRINKWRAP") or (td and td["frac_within_6mm"] >= 0.25): | |
| s += 0.25; notes.append("hugs the donut (shrinkwrap)") | |
| if ic.get("mode") == "SCULPT" or (td and td["p95"] > 1.5 * max(td["p75"], 1e-4)): | |
| s += 0.25; notes.append("sculpted variation") | |
| return min(1.0, s), ", ".join(notes) or "no sculpt-stage evidence" | |
| def _pbr(o): | |
| imgs = [n for n in nodes(o, "TEX_IMAGE") if n.get("image")] | |
| return imgs, bool(nodes(o, "NORMAL_MAP")), any((n.get("colorspace") or "").lower().startswith("non") for n in imgs) | |
| def check_p05_shading(d, ids, blend): | |
| ic, dn, ct = ids["icing"], ids["donut"], ids["counter"] | |
| s, notes = 0.0, [] | |
| if ic and nodes(ic, "BSDF_PRINCIPLED"): | |
| s += 0.15; notes.append("icing material") | |
| if dn and any(n.get("image") for n in nodes(dn, "TEX_IMAGE")): | |
| s += 0.2; notes.append("painted donut texture") | |
| elif dn and nodes(dn, "BSDF_PRINCIPLED"): | |
| s += 0.08; notes.append("donut material (untextured)") | |
| if ct: | |
| s += 0.15; notes.append(f"counter {ct['name']}") | |
| imgs, nmap, noncol = _pbr(ct) | |
| if len(imgs) >= 2: | |
| s += 0.15; notes.append(f"{len(imgs)} PBR maps") | |
| if nmap: | |
| s += 0.1; notes.append("normal map") | |
| if noncol or len(imgs) >= 3: | |
| s += 0.05; notes.append("roughness/non-color") | |
| if ic and dn and ic.get("parent") == dn["name"]: | |
| s += 0.1; notes.append("icing parented") | |
| saved = [i for i in d.get("images", []) if i.get("filepath") and "Downloads" not in i["filepath"] and i["name"] not in ("Render Result", "Viewer Node")] | |
| if saved: | |
| s += 0.1; notes.append(f"saved image {saved[0]['name']}") | |
| return min(1.0, s), ", ".join(notes) or "no shading" | |
| def _gn_types(d, o): | |
| types = set() | |
| for m in mods(o): | |
| if m["type"] == "NODES" and m.get("node_group"): | |
| g = (d.get("node_groups") or {}).get(m["node_group"]) | |
| if g: | |
| types |= set(g["node_types"]) | |
| return types | |
| def check_p06_geometry_nodes(d, ids, blend): | |
| ic, dn = ids["icing"], ids["donut"] | |
| s, notes = 0.0, [] | |
| if dn: | |
| mx = max(dims(dn)[:2]) | |
| b = band(mx, 0.08, 0.2) # ref 0.12 m after "accurate real-world size" | |
| s += 0.2 * b; notes.append(f"donut {mx * 100:.0f} cm") | |
| if ids["spheres"]: | |
| s += 0.15; notes.append("round sprinkle mesh") | |
| gn_any = [o for o in ids["icings"] if has_mod(o, "NODES")] | |
| if gn_any: | |
| s += 0.2; notes.append("Geometry Nodes on icing") | |
| types = set() | |
| for o in gn_any: | |
| types |= _gn_types(d, o) | |
| if "DISTRIBUTE_POINTS_ON_FACES" in types and "INSTANCE_ON_POINTS" in types: | |
| s += 0.2; notes.append("distribute + instance") | |
| if "INPUT_ATTRIBUTE" in types or "INPUT_NAMED_ATTRIBUTE" in types: | |
| s += 0.1; notes.append("density attribute") | |
| if ic and (ic.get("mesh_extras") or {}).get("vertex_groups"): | |
| s += 0.15; notes.append("weight-paint group") | |
| return min(1.0, s), ", ".join(notes) or "no geometry nodes" | |
| def check_p07_long_sprinkles(d, ids, blend): | |
| s, notes = 0.0, [] | |
| cyl = ids["cylinders"] | |
| if len(cyl) >= 3: | |
| s += 0.25; notes.append(f"{len(cyl)} long sprinkles") | |
| elif cyl: | |
| s += 0.1; notes.append("one long sprinkle") | |
| colls = [c.lower() for c in (d.get("scene") or {}).get("collections", [])] | |
| hit = [k for k in ("long", "round", "sprinkles") if any(k in c for c in colls)] | |
| if len(hit) >= 2: | |
| s += 0.2; notes.append("collections " + "/".join(hit)) | |
| types = set() | |
| for o in ids["icings"]: | |
| types |= _gn_types(d, o) | |
| if "COLLECTION_INFO" in types: | |
| s += 0.2; notes.append("Collection Info scatter") | |
| if "RANDOM_VALUE" in types or "ROTATE_EULER" in types or "ROTATE_ROTATION" in types: | |
| s += 0.15; notes.append("random rotation") | |
| if len(ids["donuts"]) >= 2: | |
| s += 0.2; notes.append(f"{len(ids['donuts'])} donuts") | |
| return min(1.0, s), ", ".join(notes) or "no long sprinkles" | |
| def check_p08_render_setup(d, ids, blend): | |
| s, notes = 0.0, [] | |
| all_objs = ids["spheres"] + ids["cylinders"] + ids["icings"] | |
| if any(nodes(o, "OBJECT_INFO") for o in all_objs): | |
| s += 0.4; notes.append("Object Info random") | |
| ramps = [n for o in all_objs for n in nodes(o, "VALTORGB")] | |
| if ramps: | |
| s += 0.0 if any(nodes(o, "OBJECT_INFO") for o in all_objs) else 0.2 | |
| if any(r.get("interpolation") == "CONSTANT" for r in ramps): | |
| s += 0.15; notes.append("constant ramp") | |
| if len(ramps) >= 2 or any((n.get("metallic") or 0) > 0 or "Metallic" in (n.get("linked_inputs") or []) for o in all_objs for n in nodes(o, "BSDF_PRINCIPLED")): | |
| s += 0.15; notes.append("metallic sprinkles") | |
| sc = d.get("scene") or {} | |
| if sc.get("render_engine") == "CYCLES": | |
| s += 0.2; notes.append("Cycles") | |
| if sc.get("cycles_denoise"): | |
| s += 0.1; notes.append("denoise") | |
| return min(1.0, s), ", ".join(notes) or "no render setup" | |
| def check_p09_layout(d, ids, blend): | |
| s, notes = 0.0, [] | |
| pl = ids["plate"] | |
| if pl: | |
| s += 0.2 if pl["topology"]["verts"] >= 200 else 0.1; notes.append(f"plate {pl['name']} ({pl['topology']['verts']} verts)") | |
| if mats(pl): | |
| s += 0.1; notes.append("plate material") | |
| n = len(ids["donuts"]) | |
| s += 0.25 * band(n, 5, 12) # ref 9 donuts | |
| notes.append(f"{n} donuts") | |
| with_icing = sum(1 for o in ids["icings"] if o.get("parent")) | |
| if with_icing >= min(n, 5) and n > 1: | |
| s += 0.1; notes.append("icings parented") | |
| icing_mats = {m["name"] for o in ids["icings"] for m in mats(o)} | |
| s += 0.15 * band(len(icing_mats), 4, 12) # ref 7 icing colours | |
| notes.append(f"{len(icing_mats)} icing materials") | |
| cams = d.get("cameras") or [] | |
| if cams and cams[0].get("lens", 50) >= 60: # ref 110 mm in Part 9, 65 mm by Part 12 | |
| s += 0.1; notes.append(f"lens {cams[0]['lens']:.0f} mm") | |
| if ids["backsplash"]: | |
| s += 0.1; notes.append("backsplash") | |
| return min(1.0, s), ", ".join(notes) | |
| def check_p10_lighting(d, ids, blend): | |
| sc = d.get("scene") or {} | |
| s, notes = 0.0, [] | |
| if "TEX_SKY" in (sc.get("world_nodes") or []): | |
| s += 0.3; notes.append("Sky Texture world") | |
| room = ids["room"] | |
| if room: | |
| s += 0.15; notes.append(f"room {room['name']}") | |
| if len(mats(room)) >= 2: | |
| s += 0.1; notes.append("two wall materials") | |
| if ids["appended"]: | |
| s += 0.2; notes.append("appended models: " + ", ".join(o["name"] for o in ids["appended"][:3])) | |
| lights = d.get("lights") or [] | |
| if lights and not any(l["light_type"] == "POINT" and l["energy"] >= 500 for l in lights): | |
| s += 0.1; notes.append("default point lamp gone") | |
| elif not lights: | |
| s += 0.1; notes.append("no lamps (sun texture only)") | |
| colls = [c.lower() for c in sc.get("collections", [])] | |
| if any(k in c for c in colls for k in ("whiskey", "plant", "props", "models")): | |
| s += 0.15; notes.append("prop collections") | |
| return min(1.0, s), ", ".join(notes) or "no lighting stage" | |
| def check_p11_compositing(d, ids, blend): | |
| sc = d.get("scene") or {} | |
| s, notes = 0.0, [] | |
| comp = sc.get("compositor_nodes") or [] | |
| if sc.get("use_nodes"): | |
| s += 0.2; notes.append("compositor on") | |
| if "GLARE" in comp: | |
| s += 0.25; notes.append("Glare") | |
| if "LENSDIST" in comp: | |
| s += 0.2; notes.append("Lens Distortion") | |
| if "contrast" in (sc.get("look") or "").lower(): | |
| s += 0.15; notes.append(sc["look"]) | |
| warm = [l for l in d.get("lights") or [] if l["light_type"] == "AREA" and l["color"][0] > l["color"][2] + 0.2] | |
| if warm: | |
| s += 0.2; notes.append("warm area light") | |
| return min(1.0, s), ", ".join(notes) or "no compositing" | |
| def check_p12_animation(d, ids, blend): | |
| sc = d.get("scene") or {} | |
| s, notes = 0.0, [] | |
| anim = d.get("animated_objects") or [] | |
| empties = [a for a in anim if a["type"] == "EMPTY"] | |
| if empties: | |
| s += 0.3; notes.append(f"animated pivot {empties[0]['name']}") | |
| elif anim: | |
| s += 0.15; notes.append(f"animated {anim[0]['name']}") | |
| cams = d.get("cameras") or [] | |
| cam_obj = next((o for o in d.get("objects", []) if o["type"] == "CAMERA"), None) | |
| if cam_obj and cam_obj.get("parent"): | |
| s += 0.25; notes.append(f"camera parented to {cam_obj['parent']}") | |
| fr = sc.get("frame_range") or [1, 250] | |
| if fr[1] != 250 or sc.get("fps") == 30: | |
| s += 0.2; notes.append(f"frames {fr}, fps {sc.get('fps')}") | |
| if any("rotation" in p for a in anim for p in a["paths"]): | |
| s += 0.25; notes.append("rotation keyframes") | |
| return min(1.0, s), ", ".join(notes) or "no animation" | |
| def check_p13_final_render(d, ids, blend): | |
| sc = d.get("scene") or {} | |
| s, notes = 0.0, [] | |
| if sc.get("fps") == 30: | |
| s += 0.2; notes.append("30 fps") | |
| cams = d.get("cameras") or [] | |
| if cams and cams[0].get("use_dof") and cams[0].get("focus_object"): | |
| s += 0.25; notes.append(f"DoF on {cams[0]['focus_object']}") | |
| smp = sc.get("cycles_samples") | |
| if smp is not None and smp != 4096 and 32 <= smp <= 4096: | |
| s += 0.15; notes.append(f"samples {smp}") | |
| if len(d.get("lights") or []) >= 2: | |
| s += 0.15; notes.append("two lights") | |
| p = Path(RENDER_PATH) | |
| # only the requested render.png or a PNG whose name says render/frame — the painted | |
| # texture the agent saves in Part 5 also lands in /root/donut and must not count | |
| cands = [p] + ([c for c in sorted(Path("/root/donut").glob("*.png")) if any(k in c.name.lower() for k in ("render", "frame", "final"))] if Path("/root/donut").exists() else []) | |
| for c in cands: | |
| if c.exists() and c.stat().st_size > 20_000: | |
| s += 0.25 if c == p else 0.15; notes.append(f"render {c.name} ({c.stat().st_size // 1024} KB)") | |
| break | |
| return min(1.0, s), ", ".join(notes) or "no final-render stage" | |
| def check_render_pair(d, ids, blend, rp=None): | |
| if not rp: | |
| return 0.0, "render pair unavailable" | |
| sim = rp["similarity"] | |
| # threshold band (calibrated 2026-09-09 on the learner's saves): reference vs its | |
| # own 1080p frame 0.79; Donut_9 (same content, different camera) vs Donut_13 0.23; | |
| # identical renders 1.00. 0.20 -> 0, 0.75 -> 1. | |
| frac = max(0.0, min(1.0, (sim - 0.20) / 0.55)) | |
| return frac, f"similarity {sim:.3f} (colour {rp['pixel_color']:.2f}, edges {rp['edge_corr']:.2f}, histogram {rp['hist_intersection']:.2f})" | |
| CHECKS = {k: globals()["check_" + k] for k in WEIGHTS if k != "render_pair"} | |
| def grade(d, blend, rp=None): | |
| ids = identify(d) | |
| res = {} | |
| for name, fn in CHECKS.items(): | |
| try: | |
| frac, note = fn(d, ids, blend) | |
| except Exception as e: # noqa: BLE001 | |
| frac, note = 0.0, f"check error: {e!r}" | |
| res[name] = {"frac": max(0.0, min(1.0, float(frac))), "weight": WEIGHTS[name], "note": note} | |
| frac, note = check_render_pair(d, ids, blend, rp) | |
| res["render_pair"] = {"frac": frac, "weight": WEIGHTS["render_pair"], "note": note} | |
| res["_total"] = sum(v["frac"] * v["weight"] for k, v in res.items() if not k.startswith("_")) | |
| res["_ids"] = {k: (v["name"] if isinstance(v, dict) else ([o["name"] for o in v] if isinstance(v, list) else None)) | |
| for k, v in ids.items() if k != "torus"} | |
| return res | |
| def scored(): | |
| blends = find_blends() | |
| print(f"[verifier] .blend files: {blends or 'none'}") | |
| best, best_blend = None, None | |
| for b in blends[:4]: | |
| d = dump(b) | |
| if not d: | |
| continue | |
| r = grade(d, b) # structural first (cheap) | |
| print(f"[verifier] {b}: structural {r['_total']:.4f}") | |
| if best is None or r["_total"] > best["_total"]: | |
| best, best_blend = r, b | |
| if best is None: | |
| best = {k: {"frac": 0.0, "weight": w, "note": "no .blend graded"} for k, w in WEIGHTS.items()} | |
| best["_total"], best["_ids"] = 0.0, {} | |
| elif DO_RENDER_PAIR: | |
| rp = render_pair(best_blend) | |
| d = json.loads((GRADE_DIR / (Path(best_blend).stem + ".json")).read_text()) | |
| best = grade(d, best_blend, rp) | |
| total = best["_total"] | |
| Path(REWARD_PATH).parent.mkdir(parents=True, exist_ok=True) | |
| Path(REWARD_PATH).write_text(f"{total:.4f}\n") | |
| (GRADE_DIR / "grade.json").write_text(json.dumps(best, indent=1)) | |
| print(f"[verifier] graded file: {best_blend} ids={best['_ids']}") | |
| for k, v in best.items(): | |
| if k.startswith("_"): | |
| continue | |
| mark = "✓" if v["frac"] >= 0.999 else ("~" if v["frac"] > 0 else "✗") | |
| print(f"[verifier] {mark} {k:<20} {v['frac'] * v['weight']:.3f}/{v['weight']:.2f} {v['note']}") | |
| print(f"[verifier] REWARD {total:.4f}") | |
| return best | |
| def _mk(name): | |
| def test(scored): | |
| v = scored[name] | |
| assert v["frac"] >= 0.999, f"{name}: {v['note']}" | |
| test.__name__ = f"test_{name}" | |
| return test | |
| for _n in WEIGHTS: | |
| globals()[f"test_{_n}"] = _mk(_n) | |
| if __name__ == "__main__": | |
| import sys | |
| d = json.load(open(sys.argv[1])) | |
| rp = json.load(open(sys.argv[3])) if len(sys.argv) > 3 else None | |
| r = grade(d, sys.argv[2] if len(sys.argv) > 2 else PREFERRED, rp) | |
| for k, v in r.items(): | |
| if not k.startswith("_"): | |
| print(f"{k:<20} {v['frac']:.2f} x {v['weight']:.2f} {v['note']}") | |
| print("ids", r["_ids"], "TOTAL", round(r["_total"], 4)) | |