Datasets:
Download code/robohome/src/engine/source/scripts/run_mainline_pipeline.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 11 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/scripts/run_mainline_pipeline.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome@86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/scripts/run_mainline_pipeline.py
-
curl -L -o run_mainline_pipeline.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/86ffa4ecc1047bb404fdc283987bd22cbc259a96/code/robohome/src/engine/source/scripts/run_mainline_pipeline.py
11 kB
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import subprocess | |
| import sys | |
| from datetime import datetime | |
| from pathlib import Path | |
| from typing import Any | |
| def repo_root() -> Path: | |
| return Path(__file__).resolve().parents[1] | |
| def run_command(command: list[str], *, cwd: Path, env: dict[str, str], log_path: Path) -> int: | |
| log_path.parent.mkdir(parents=True, exist_ok=True) | |
| with log_path.open("w", encoding="utf-8") as handle: | |
| handle.write("$ " + " ".join(command) + "\n\n") | |
| handle.flush() | |
| result = subprocess.run(command, cwd=str(cwd), env=env, stdout=handle, stderr=subprocess.STDOUT, text=True) | |
| return result.returncode | |
| def load_json(path: Path) -> dict[str, Any]: | |
| if not path.exists(): | |
| return {} | |
| return json.loads(path.read_text(encoding="utf-8")) | |
| def find_visual_usds(root: Path) -> list[Path]: | |
| return sorted(root.glob("fullhome_asset_v16_*/visual_scene_full_real_mesh.usd")) | |
| def parse_args(argv: list[str] | None = None) -> argparse.Namespace: | |
| parser = argparse.ArgumentParser( | |
| description="Run the clean RoboHavenGen mainline: Stage 1 -> Stage 2 -> Stage 4 -> Stage 5." | |
| ) | |
| parser.add_argument("--out-root", required=True, type=Path, help="Generation output root for Stage 1.") | |
| parser.add_argument("--scene-count", type=int, default=1) | |
| parser.add_argument('--generation-mode',choices=('joint','legacy'),default='joint') | |
| parser.add_argument('--joint-request',type=Path) | |
| parser.add_argument("--rplan-index", type=int, default=None) | |
| parser.add_argument("--package-root", type=Path, default=None) | |
| parser.add_argument("--run-root", type=Path, default=None, help="Directory for mainline logs and reports.") | |
| parser.add_argument("--python", default=sys.executable) | |
| parser.add_argument("--blender", default=os.environ.get("RHG_BLENDER", os.environ.get("BLENDER", "blender"))) | |
| parser.add_argument("--isaac-root", type=Path, default=Path(os.environ.get("RHG_ISAAC_ROOT", "inputs/isaac-sim"))) | |
| parser.add_argument("--active-gpu", type=int, default=int(os.environ.get("RHG_ISAAC_ACTIVE_GPU", "0"))) | |
| parser.add_argument("--width", type=int, default=1280) | |
| parser.add_argument("--height", type=int, default=900) | |
| parser.add_argument("--rt-subframes", type=int, default=8) | |
| parser.add_argument("--preview", action="store_true", help="Also run optional Stage 3 Blender preview after generation.") | |
| parser.add_argument("--skip-stage1", action="store_true", help="Use an existing generation output root.") | |
| parser.add_argument("--skip-isaac-probes", action="store_true", help="Skip Isaac open/collision/settle probes in Stage 4.") | |
| parser.add_argument("--skip-isaac-render", action="store_true", help="Skip Stage 5 RTX rendering.") | |
| parser.add_argument("--fast", action="store_true", help="Forward to Stage 1 generation.") | |
| parser.add_argument("--no-astra-cache", action="store_true", help="Forward to Stage 1 generation.") | |
| return parser.parse_args(argv) | |
| def simulation_main(argv: list[str] | None = None) -> int: | |
| args = parse_args(argv) | |
| root = repo_root() | |
| scripts = root / "scripts" | |
| out_root = args.out_root.resolve() | |
| package_root = (args.package_root or (out_root / "scene_package")).resolve() | |
| default_run_root = out_root/'mainline_run' if args.skip_stage1 else out_root.parent/(out_root.name+'_mainline_run') | |
| run_root = (args.run_root or default_run_root).resolve() | |
| if not args.skip_stage1 and run_root.is_relative_to(out_root): | |
| raise ValueError('Pre-generation --run-root must be outside the new job output directory') | |
| log_root = run_root / "logs" | |
| run_root.mkdir(parents=True, exist_ok=True) | |
| env = os.environ.copy() | |
| env.setdefault("PYTHONNOUSERSITE", "1") | |
| report: dict[str, Any] = { | |
| "schema": "robohavengen.mainline_pipeline.v16_20261008", | |
| "created_at": datetime.now().isoformat(timespec="seconds"), | |
| "repo_root": str(root), | |
| "generation_root": str(out_root), | |
| "package_root": str(package_root), | |
| "run_root": str(run_root), | |
| "mainline_stages": ["stage1_generate_scene", "stage2_scene_package", "stage4_usd_physics_isaac", "stage5_isaac_rtx_render"], | |
| "optional_stage3_preview": bool(args.preview), | |
| "commands": [], | |
| "passed": False, | |
| } | |
| def record(name: str, command: list[str], log_name: str, cwd: Path = root) -> int: | |
| log_path = log_root / log_name | |
| code = run_command(command, cwd=cwd, env=env, log_path=log_path) | |
| report["commands"].append({"name": name, "code": code, "log": str(log_path), "command": command}) | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return code | |
| if not args.skip_stage1: | |
| generation_cmd = [ | |
| args.python, | |
| str(scripts / "run_generate_scene.py"), | |
| "--out-root", | |
| str(out_root), | |
| "--scene-count", | |
| str(args.scene_count), | |
| "--blender", | |
| str(args.blender), | |
| ] | |
| if args.rplan_index is not None: | |
| generation_cmd += ['--rplan-index',str(args.rplan_index)] | |
| generation_cmd += ['--generation-mode',args.generation_mode] | |
| if args.joint_request:generation_cmd += ['--joint-request',str(args.joint_request)] | |
| if args.fast: | |
| generation_cmd.append("--fast") | |
| if args.no_astra_cache: | |
| generation_cmd.append("--no-astra-cache") | |
| if record("stage1_generate_scene", generation_cmd, "01_generate_scene.log") != 0: | |
| report["status"] = "failed_at_stage1_generate_scene" | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| else: | |
| report["commands"].append({"name": "stage1_generate_scene", "code": 0, "status": "skipped_existing_output"}) | |
| if args.preview: | |
| scene_dirs = sorted(path for path in out_root.glob("fullhome_asset_v16_*") if path.is_dir()) | |
| preview_input = scene_dirs[0] if scene_dirs else out_root | |
| preview_cmd = [ | |
| args.python, | |
| str(scripts / "run_preview_blender.py"), | |
| "--input", | |
| str(preview_input), | |
| "--out", | |
| str(run_root / "optional_preview_blender"), | |
| "--blender", | |
| str(args.blender), | |
| ] | |
| if record("optional_stage3_preview_blender", preview_cmd, "03_preview_blender.log") != 0: | |
| report["status"] = "failed_at_optional_stage3_preview" | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| build_cmd = [ | |
| args.python, | |
| str(scripts / "run_build_scene_package.py"), | |
| "--source-root", | |
| str(out_root), | |
| "--out", | |
| str(package_root), | |
| "--copy-blend", | |
| ] | |
| if record("stage2_build_scene_package", build_cmd, "02_build_scene_package.log") != 0: | |
| report["status"] = "failed_at_stage2_build_scene_package" | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| validate_report = run_root / "scene_package_validation.json" | |
| validate_cmd = [ | |
| args.python, | |
| str(scripts / "run_validate_package.py"), | |
| "--root", | |
| str(package_root), | |
| "--report", | |
| str(validate_report), | |
| ] | |
| if record("stage2_validate_scene_package", validate_cmd, "02_validate_scene_package.log") != 0: | |
| report["status"] = "failed_at_stage2_validate_scene_package" | |
| report["scene_package_validation"] = load_json(validate_report) | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| report["scene_package_validation"] = load_json(validate_report) | |
| export_cmd = [ | |
| args.python, | |
| str(scripts / "run_export_usd_isaac.py"), | |
| "--root", | |
| str(package_root / "scenes"), | |
| "--include-textured-delivery", | |
| "--blender", | |
| str(args.blender), | |
| ] | |
| if not args.skip_isaac_probes: | |
| export_cmd.append("--include-isaac-probes") | |
| if record("stage4_export_usd_physics_isaac", export_cmd, "04_export_usd_physics_isaac.log") != 0: | |
| report["status"] = "failed_at_stage4_export_usd_physics_isaac" | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| usd_paths = find_visual_usds(package_root / "scenes") | |
| report["visual_usd_paths"] = [str(path) for path in usd_paths] | |
| if not usd_paths: | |
| report["status"] = "failed_missing_visual_usd" | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| if not args.skip_isaac_render: | |
| for index, usd_path in enumerate(usd_paths): | |
| render_cmd = [ | |
| args.python, | |
| str(scripts / "run_isaac_rtx_render.py"), | |
| "--usd", | |
| str(usd_path), | |
| "--out", | |
| str(run_root / "isaac_rtx_render" / usd_path.parent.name), | |
| "--isaac-root", | |
| str(args.isaac_root), | |
| "--active-gpu", | |
| str(args.active_gpu), | |
| "--width", | |
| str(args.width), | |
| "--height", | |
| str(args.height), | |
| "--rt-subframes", | |
| str(args.rt_subframes), | |
| ] | |
| if record(f"stage5_isaac_rtx_render_{index:03d}", render_cmd, f"05_isaac_rtx_render_{index:03d}.log") != 0: | |
| report["status"] = "failed_at_stage5_isaac_rtx_render" | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| return 1 | |
| else: | |
| report["commands"].append({"name": "stage5_isaac_rtx_render", "code": 0, "status": "skipped_by_user"}) | |
| report["status"] = "completed" | |
| report["passed"] = True | |
| (run_root / "mainline_pipeline_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(report, ensure_ascii=False, indent=2)) | |
| return 0 | |
| def main(argv: list[str] | None = None) -> int: | |
| arguments = list(sys.argv[1:] if argv is None else argv) | |
| if '--run-simulation' in arguments: | |
| arguments.remove('--run-simulation') | |
| return simulation_main(arguments) | |
| from run_generate_scene import main as generate_main | |
| return generate_main(arguments) | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |