Skip to content

hylo.codeagents.replay_geom

Package: hylo-code-agents · Core contracts

replay_geom

Geometry, checks, video and the simulation client of replay-to-sim (RFC-0006 part 8), all without MuJoCo.

MuJoCo runs in the isolated worker replay_sim.py (uv run --script, like the hylo-tools and motion workers), so it never enters the agent's process. SimClient writes the objects' meshes, sends one request per call (build the scene, kinematic replay, physics replay) and reads the arrays back. Here: meshes (OBJ I/O, convex hulls, boxes, extrusion to the table), pose and size errors, event checks of the simulation, final-state success and the side-by-side video.

SIM_WORKER module-attribute

SIM_WORKER = Path(__file__).with_name('replay_sim.py')

SceneObject dataclass

SceneObject(name: str, label: str, parts: list[tuple[ndarray, ndarray]], visual: tuple[ndarray, ndarray] | None, pose0: ndarray, rgba: tuple[float, float, float, float] = (0.7, 0.7, 0.7, 1.0), dynamic: bool = True, mass: float = 0.1, info: dict[str, Any] = dict())

name instance-attribute

name: str

label instance-attribute

label: str

parts instance-attribute

parts: list[tuple[ndarray, ndarray]]

visual instance-attribute

visual: tuple[ndarray, ndarray] | None

pose0 instance-attribute

pose0: ndarray

rgba class-attribute instance-attribute

rgba: tuple[float, float, float, float] = (0.7, 0.7, 0.7, 1.0)

dynamic class-attribute instance-attribute

dynamic: bool = True

mass class-attribute instance-attribute

mass: float = 0.1

info class-attribute instance-attribute

info: dict[str, Any] = field(default_factory=dict)

SimClient

SimClient(out_dir: str | Path, timeout: float = 3600.0)

Runs replay_sim.py in its own uv environment. One call = one request with ops run in order.

out instance-attribute

out = Path(out_dir)

timeout instance-attribute

timeout = timeout

scene_info instance-attribute

scene_info: dict[str, Any] = {}

call

call(ops: list[str], params: dict[str, Any], arrays: dict[str, ndarray] | None = None) -> dict[str, Any]

build

build(*, table_z: float, table_extent: ndarray, objects: list[SceneObject], agent: str, arm_model: str | None = None, base: ndarray | None = None, camera: dict[str, Any] | None = None, gripper_T0: ndarray | None = None, image_size: tuple[int, int] = (640, 480), hand: dict[str, Any] | None = None) -> dict[str, Any]

replay

replay(*, time: ndarray, q: ndarray | None, tcp: ndarray | None, opening: ndarray, hand_cmd: ndarray, obj_poses: dict[str, ndarray], held: dict[int, str] | None = None, ops: Sequence[str] = ('kinematic', 'physics'), fingers: ndarray | None = None) -> dict[str, Any]

Kinematic replay (recorded motion into qpos) and physics replay in one worker call. fingers: (T, n) finger joint targets of a multi-finger hand (agent "hand").

write_obj

write_obj(path: Path, V: ndarray, F: ndarray) -> Path

read_obj

read_obj(path: str | Path) -> tuple[np.ndarray, np.ndarray]

hull_mesh

hull_mesh(points: ndarray) -> tuple[np.ndarray, np.ndarray]

box_mesh

box_mesh(size: Sequence[float], yaw: float, centre: Sequence[float]) -> tuple[np.ndarray, np.ndarray]

An oriented box (world frame) as a triangle mesh.

column_parts

column_parts(points: ndarray, table_z: float, cell: float = 0.015, min_pts: int = 3) -> list[tuple[np.ndarray, np.ndarray]]

A 2.5D height field of observed points as box columns standing on the table (one convex part per cell, height = the cell's 95th-percentile point). Keeps the concavity of a container seen from above (a bowl's floor is lower than its rim), which a convex hull would fill.

ground_mesh

ground_mesh(V: ndarray, table_z: float, max_gap: float = 0.03) -> np.ndarray

Points of a mesh extended down to the table (its footprint projected onto the plane) when the mesh floats less than max_gap above it: single-view meshes miss the hidden lower part of objects resting on the table.

pose_errors

pose_errors(ref: ndarray, est: ndarray, valid: ndarray | None = None) -> dict[str, Any]

Translation (m) and rotation (deg) error per frame and summarised.

size_error

size_error(est_size: Sequence[float], gt_size: Sequence[float]) -> dict[str, Any]

Axis-agnostic: sorted extents compared.

sim_events

sim_events(time: ndarray, phys: dict[str, Any], table_z: float, hand_cmd: ndarray) -> list[dict[str, Any]]

Events of the physics replay with the same detector as the recording (closed intervals from the command, since the simulated hand opening is a measurement of the same command), plus finger contact on grasps.

final_state

final_state(ref_final: dict[str, ndarray], sim_final: dict[str, ndarray], moved: Sequence[str], tol: float = 0.03) -> dict[str, Any]

side_by_side

side_by_side(original: ndarray, sim_video: str | Path | None, out: str | Path, fps: float, *, height: int = 360, max_bytes: int = 4000000, labels: tuple[str, str] = ('recording', 'simulation'), sim_frames: ndarray | None = None) -> dict[str, Any]

original | simulation as one MP4 (H.264), re-encoded at a lower bitrate until it fits max_bytes.

read_video

read_video(path: str | Path) -> np.ndarray

(T, H, W, 3) frames of a video file.

write_video

write_video(frames: Sequence[ndarray], out: str | Path, fps: float, max_bytes: int = 4000000) -> dict[str, Any]

Frames (same size, even dimensions after padding) as one H.264 MP4, re-encoded at a lower bitrate until it fits max_bytes.