Download tools/prepare_scene.py from YiyangJin/ARISE-Real2Sim: direct link, hf CLI and curl.
- Browser
- Download file 4.12 kB
-
https://huggingface.co/datasets/YiyangJin/ARISE-Real2Sim/resolve/main/tools/prepare_scene.py
- Command line
-
hf download hf://datasets/YiyangJin/ARISE-Real2Sim/tools/prepare_scene.py
-
curl -L -o prepare_scene.py https://huggingface.co/datasets/YiyangJin/ARISE-Real2Sim/resolve/main/tools/prepare_scene.py
4.12 kB
| """Resolve a released scene and optional source-layout overlay without running simulation.""" | |
| from pathlib import Path | |
| import argparse | |
| import json | |
| import shutil | |
| import sys | |
| import zipfile | |
| import yaml | |
| parser=argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--task',required=True) | |
| parser.add_argument('--layout') | |
| parser.add_argument('--output',type=Path,required=True) | |
| parser.add_argument('--machine-config',type=Path) | |
| parser.add_argument('--robodojo',type=Path,help='Optional existing RoboDojo checkout: compile an owned runtime after resolving inputs') | |
| args=parser.parse_args() | |
| repo=Path(__file__).resolve().parents[1] | |
| out=args.output.resolve() | |
| if out.exists()and any(out.iterdir()):raise ValueError('Use a new empty output directory') | |
| out.mkdir(parents=True,exist_ok=True) | |
| manifest=json.loads((repo/'scenes'/args.task/'manifest.json').read_text()) | |
| family=manifest['runtime_family'] | |
| with zipfile.ZipFile(repo/'runtime'/(family+'.zip'))as z: | |
| for name in z.namelist(): | |
| assert not Path(name).is_absolute()and '..'not in Path(name).parts | |
| z.extractall(out/'matched-runtime') | |
| project=out/'matched-runtime/project' | |
| machine=yaml.safe_load(args.machine_config.read_text())if args.machine_config else {} | |
| machine.setdefault('gsplat_cache',str(out/'gsplat-cache')) | |
| if machine.get('gsplat_source'): | |
| machine.setdefault('gsplat_libraries',[str(project),machine['gsplat_source']]) | |
| active={} | |
| def merge(base,patch): | |
| if isinstance(base,dict)and isinstance(patch,dict): | |
| result=dict(base) | |
| for key,value in patch.items():result[key]=merge(result.get(key),value) | |
| return result | |
| return patch | |
| def resolve(value): | |
| if isinstance(value,dict):return {k:resolve(v)for k,v in value.items()} | |
| if isinstance(value,list): | |
| result=[] | |
| for item in value: | |
| item_value=resolve(item) | |
| if isinstance(item,str)and item.startswith('machine://')and isinstance(item_value,list):result.extend(item_value) | |
| else:result.append(item_value) | |
| return result | |
| if not isinstance(value,str):return value | |
| if value.startswith('machine://'): | |
| key=value[len('machine://'):] | |
| if key not in machine:raise ValueError('Configure '+key+' in --machine-config; see machine-config.example.yaml') | |
| return machine[key] | |
| if value.startswith('bundle://'): | |
| source=(repo/value[len('bundle://'):]).resolve() | |
| assert source.is_relative_to(repo)and source.is_file(),source | |
| if source.suffix in {'.yaml','.yml'}: | |
| if source not in active: | |
| destination=out/'resolved-resources'/source.relative_to(repo) | |
| active[source]=destination | |
| data=resolve(yaml.safe_load(source.read_text())) | |
| destination.parent.mkdir(parents=True,exist_ok=True) | |
| destination.write_text(yaml.safe_dump(data,sort_keys=False)) | |
| return str(active[source]) | |
| return str(source) | |
| return value | |
| scene=yaml.safe_load((repo/'scenes'/args.task/'scene.yaml').read_text()) | |
| if args.layout: | |
| overlay=yaml.safe_load((repo/'scenes'/args.task/'layouts'/(args.layout+'.yaml')).read_text()) | |
| assert overlay['task']==args.task | |
| scene=merge(scene,overlay['overrides']) | |
| scene=resolve(scene) | |
| path=out/'scene.yaml';path.write_text(yaml.safe_dump(scene,sort_keys=False)) | |
| sys.path.insert(0,str(project)) | |
| from arise.domain.contracts import SceneSpec | |
| spec=SceneSpec.model_validate(scene) | |
| if args.robodojo: | |
| from arise.adapters.backends.robodojo import compile_bundle,snapshot | |
| runtime=out/'runtime' | |
| snapshot(args.robodojo.resolve(),runtime,out/'ledger.sqlite') | |
| native=out/'matched-runtime/native' | |
| if native.exists():shutil.copytree(native,runtime,dirs_exist_ok=True) | |
| description=yaml.safe_load(Path(spec.robots[0].description).read_text()) | |
| compile_bundle(spec,path,runtime,Path(description['usd']),observation_hz=30,camera_hz=30,render_interval=10,quantized_control=True) | |
| print(json.dumps({'scene':str(path),'task':args.task,'layout':args.layout,'matched_project':str(project),'schema_valid':True,'simulation_started':False})) | |