Datasets:
Download code/robohome/src/engine/source/packages/benchmark/packager.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 5.83 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/packages/benchmark/packager.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome@86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/packages/benchmark/packager.py
-
curl -L -o packager.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/packages/benchmark/packager.py
5.83 kB
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from packages.core.files import atomic_write_text | |
| from packages.schemas.models import BenchmarkEpisode, SceneManifest, TaskSpec | |
| class BenchmarkPackager: | |
| def package( | |
| self, | |
| task: TaskSpec, | |
| scene: SceneManifest, | |
| robot_id: str, | |
| output_dir: Path, | |
| *, | |
| benchmark_version: str = "0.1.0", | |
| episode_id: str | None = None, | |
| max_duration_s: float = 120.0, | |
| split: str = "train", | |
| factor_values: dict[str, object] | None = None, | |
| evaluator_policy: dict[str, object] | None = None, | |
| ) -> BenchmarkEpisode: | |
| self._validate_contract(task, scene, output_dir) | |
| episode = BenchmarkEpisode( | |
| benchmark_version=benchmark_version, | |
| episode_id=episode_id or f"episode-{task.task_id.removeprefix('task-')}-{robot_id}", | |
| task_id=task.task_id, | |
| scene_id=scene.scene_id, | |
| root_usd_uri=scene.layer_plan.root_layer, | |
| robot_profile=robot_id, | |
| seed=task.random_seed, | |
| evaluator_uri="manifests/evaluator.json", | |
| max_duration_s=max_duration_s, | |
| split=split, # type: ignore[arg-type] | |
| factor_values=factor_values | |
| or {"difficulty": task.plan.difficulty.model_dump(mode="json")}, | |
| ) | |
| manifests = output_dir / "manifests" | |
| manifests.mkdir(parents=True, exist_ok=True) | |
| atomic_write_text(manifests / "task.json", task.model_dump_json(indent=2)) | |
| atomic_write_text(manifests / "episode.json", episode.model_dump_json(indent=2)) | |
| evaluator = { | |
| "schema_version": "1.1", | |
| "task_id": task.task_id, | |
| "scene_id": scene.scene_id, | |
| "entity_prim_paths": scene.entity_prim_paths, | |
| "robot_prim_path": scene.robot_prim_path, | |
| "goals": [item.model_dump(mode="json") for item in task.goal_predicates], | |
| "safety": [item.model_dump(mode="json") for item in task.safety_predicates], | |
| "stages": [item.model_dump(mode="json") for item in task.stages], | |
| "validation_contract": (evaluator_policy or {}).get("isaac_validation", {}), | |
| "observation_contract": { | |
| "trajectory_aware": any( | |
| item.params.get("temporal") in {"ever", "always"} | |
| for item in task.goal_predicates + task.safety_predicates | |
| ), | |
| "required_streams": sorted( | |
| { | |
| stream | |
| for item in task.goal_predicates + task.safety_predicates | |
| for stream in ( | |
| (["contact_report"] if item.name == "contact" else []) | |
| + (["joint_position"] if item.name in {"pressed", "open"} else []) | |
| ) | |
| } | |
| ), | |
| "synchronization_groups": self._synchronization_groups(task), | |
| "joint_position_unit": "degrees", | |
| "contact_evidence_fields": ["subject_body", "object_link"], | |
| }, | |
| } | |
| atomic_write_text( | |
| manifests / "evaluator.json", json.dumps(evaluator, indent=2, sort_keys=True) | |
| ) | |
| checksums = [] | |
| for path in sorted(output_dir.rglob("*")): | |
| if path.is_file() and path.name != "checksums.sha256": | |
| checksum = hashlib.sha256(path.read_bytes()).hexdigest() | |
| checksums.append(f"{checksum} {path.relative_to(output_dir)}") | |
| atomic_write_text(output_dir / "checksums.sha256", "\n".join(checksums) + "\n") | |
| return episode | |
| def _synchronization_groups(task: TaskSpec) -> dict[str, dict[str, object]]: | |
| groups: dict[str, dict[str, object]] = {} | |
| for index, predicate in enumerate(task.goal_predicates): | |
| group = predicate.params.get("synchronization_group") | |
| if not group: | |
| continue | |
| entry = groups.setdefault( | |
| str(group), | |
| { | |
| "window_s": float(predicate.params.get("synchronization_window_s", 0.0)), | |
| "goal_indices": [], | |
| }, | |
| ) | |
| current_window = entry["window_s"] | |
| assert isinstance(current_window, (int, float)) | |
| entry["window_s"] = min( | |
| float(current_window), | |
| float(predicate.params.get("synchronization_window_s", 0.0)), | |
| ) | |
| goal_indices = entry["goal_indices"] | |
| assert isinstance(goal_indices, list) | |
| goal_indices.append(index) | |
| return groups | |
| def _validate_contract(task: TaskSpec, scene: SceneManifest, output_dir: Path) -> None: | |
| if scene.task_id != task.task_id: | |
| raise ValueError( | |
| f"scene task_id {scene.task_id!r} does not match task {task.task_id!r}" | |
| ) | |
| if scene.random_seed != task.random_seed: | |
| raise ValueError( | |
| f"scene seed {scene.random_seed} does not match task seed {task.random_seed}" | |
| ) | |
| expected_entities = {entity.entity_id for entity in task.entities if entity.required} | |
| missing = expected_entities - scene.entity_prim_paths.keys() | |
| if missing: | |
| raise ValueError(f"scene is missing required task entities: {sorted(missing)}") | |
| root_layer = Path(scene.layer_plan.root_layer) | |
| if root_layer.is_absolute() or ".." in root_layer.parts: | |
| raise ValueError("scene root layer must be a relative path inside the benchmark") | |
| if not (output_dir / root_layer).is_file(): | |
| raise ValueError(f"scene root layer does not exist: {root_layer}") | |