"""Sample scene layouts for our dev tasks from their config, the way RoboDojo's eval layouts are laid out (PROD-104). python dev_suite/sample_layouts.py [--tasks open_laptop ...] [--num 20] [--seed 0] Writes dev_suite/layouts/RoboDojo/arx_x5//_.json (robodojo_agent links to arx_x5). The simulator reads them when ROBODOJO_LAYOUT_ROOT=dev_suite/layouts (patches/robodojo-layout-root.patch; the launchers set it). Reads only the task config, RoboDojo's scene config and the object metadata, never Assets/Eval_Layout. Config, as in RoboDojo task configs: per section (Rigid, Geometry, Articulation; Clutter = a clutter asset as a rigid body) a list of groups {common, category, select_mode}. common: xlim, ylim (env frame, metres), rotate_rand + rotate_deg (scalar d = [-d, d], or [lo, hi]), relative_plane (Table or Ground), margin, and either zlim + qpos (fixed height and orientation) or place_tag (the asset's resting frame from its metadata, default "up"). Ours: physics overrides and, for an articulation, joint_ratio [lo, hi] (where its joints start). """ from __future__ import annotations import argparse import json import math import os import random import sys from pathlib import Path import yaml HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE.parent / "src")) from robodojo_agent import eval_guard # noqa: E402 ROBODOJO_ROOT = Path(os.environ.get("ROBODOJO_ROOT", Path.home() / "persist/coding/simulation/RoboDojo")) OBJECTS = ROBODOJO_ROOT / "Assets/Object/RoboDojo" SECTIONS = ["Geometry", "Articulation", "Rigid", "Clutter"] # placement order: fixtures first TASKS: dict[str, dict] = json.loads((HERE / "tasks.json").read_text()) def qmul(a, b): aw, ax, ay, az = a bw, bx, by, bz = b return [aw * bw - ax * bx - ay * by - az * bz, aw * bx + ax * bw + ay * bz - az * by, aw * by - ax * bz + ay * bw + az * bx, aw * bz + ax * by - ay * bx + az * bw] def qrot(q, v): w, x, y, z = qmul(qmul(q, [0.0, *v]), [q[0], -q[1], -q[2], -q[3]]) return [x, y, z] def uniform(rng: random.Random, lim) -> float: lo, hi = sorted(float(v) for v in lim) return rng.uniform(lo, hi) def plane_height(scene: dict, plane: str) -> float: if plane == "Table": return scene["Table"]["default_pos"][2] + scene["Table"]["scale"][2] / 2 if plane == "Ground": return scene["Ground"]["default_pos"][2] + scene["Ground"]["thickness"] / 2 raise ValueError(f"relative_plane {plane!r}: only Table and Ground are supported") def instance(rng, scene, section, category, idx, label, common, occupied, placed=None) -> dict: """One object record. `placed` (label -> (x, y, half_x, half_y, z_bottom, z_top, yaw), filled in here) serves our relative placements: `inside: