Download tools/verify_environment.py from luca0621/robocasa-delayed-recall-eval: direct link, hf CLI and curl.
- Browser
- Download file 6.69 kB
-
https://huggingface.co/datasets/luca0621/robocasa-delayed-recall-eval/resolve/main/tools/verify_environment.py
- Command line
-
hf download hf://datasets/luca0621/robocasa-delayed-recall-eval/tools/verify_environment.py
-
curl -L -o verify_environment.py https://huggingface.co/datasets/luca0621/robocasa-delayed-recall-eval/resolve/main/tools/verify_environment.py
6.69 kB
| """Verify one evaluation environment without any policy (CPU only). | |
| Rebuilds the world for a case exactly as the evaluators do (evaluate_parity.py for immediate, evaluate_delayed.py / | |
| evaluate_delayed_v2.py for delayed short sources, evaluate_delayed_v2.py for long sources), replays the recorded expert | |
| source up to the handoff step and checks, at every step: simulator state == recorded state (max abs error, must be 0 / | |
| <= 1e-8 as in the evaluators) and the 16-D proprio vector == recorded observation.state. At the end it checks the same | |
| handoff conditions the evaluators assert (target concealed since storage, phase RECALL, chores done, no violations, no | |
| cover/door chosen yet). No rendering, no policy. | |
| usage (repo root): RDR_ROOT=$PWD/root MUJOCO_GL=egl python tools/verify_environment.py --stage delay-01min --case cup-036 | |
| stages: immediate, delay-01min, delay-01min-extra, delay-05min, delay-15min, delay-30min, delay-60min | |
| """ | |
| import argparse, hashlib, importlib.util, json, os, random, sys, time | |
| from pathlib import Path | |
| ORIGINAL_ROOT = '/data/robo_ttt/robocasa_memory_20261103' | |
| ROOT = os.environ.get('RDR_ROOT', ORIGINAL_ROOT) | |
| E = Path(ROOT)/'evaluation-ck30000-20261108'; OLD = E/'cotrain-ck3000-20261114'; N = E/'cotrain-delay-n10-20261115' | |
| sys.path.insert(0, str(OLD/'code')) | |
| def L(p): | |
| p = str(p); return Path(ROOT+p[len(ORIGINAL_ROOT):]) if p.startswith(ORIGINAL_ROOT) else Path(p) | |
| def digest(p): | |
| with open(p, 'rb') as f: return hashlib.file_digest(f, 'sha256').hexdigest() | |
| def concealed(env, family): # identical to evaluate_delayed_v2.concealed | |
| if family == 'spice': return bool(env.armed and all(env.covered(i) for i in range(2))) | |
| f = env.privileged_facts() | |
| return bool(env.occlusion_gate.armed and f.cabinet_closed and len(f.cups_in_cabinet) == 3) | |
| def main(): | |
| a = argparse.ArgumentParser(); a.add_argument('--stage', required=True); a.add_argument('--case', required=True) | |
| a.add_argument('--out', default=None); a = a.parse_args() | |
| plan = json.loads((N/a.stage/'plan.json').read_text()) | |
| case = next(c for c in plan['cases'] if c['case'] == a.case) | |
| import h5py, numpy as np | |
| from experiments.robocasa_memory.evaluation.manifest import read, encode_state | |
| from experiments.robocasa_memory.dynamic_v2.protocol import Phase | |
| family = case['family']; b, h = case['storage_steps'], case['handoff_step'] | |
| src = L(case['source_dir']); g = read(src/'result.json') | |
| kind = 'immediate' if (h == b and case.get('chores') == []) else case.get('source_kind', 'short') | |
| assert g['status'] == 'verified' and g['trajectory_sha256'] == case['source_trajectory_sha256'] | |
| assert digest(src/'trajectory.hdf5') == case['source_trajectory_sha256'], 'source sha256 mismatch' | |
| out = Path(a.out or f'/tmp/rdr-verify/{a.stage}-{a.case}'); out.mkdir(parents=True, exist_ok=True) | |
| t0 = time.time() | |
| if kind in ('immediate', 'short'): | |
| spec = importlib.util.spec_from_file_location('frozen_data_env', E/case['generator_version']/'data_env.py') | |
| module = importlib.util.module_from_spec(spec); spec.loader.exec_module(module) | |
| if kind == 'short' and family == 'cup' and case['chores'] != ['pack_drink']: | |
| from dataclasses import replace | |
| from experiments.robocasa_memory.dynamic_v2.kitchen_demo import make_env as kitchen, program as base_program | |
| from experiments.robocasa_memory.dynamic_v2.protocol import Program | |
| pool = {r.key: replace(r, instruction=r.instruction.split(' Leave ')[0]) for r in base_program().chores} | |
| chosen = list(case['chores']) | |
| class DelayCup(module.DatasetCup): | |
| def build_program(self): | |
| base = super().build_program() | |
| return Program(5, base.family, base.initial_instruction, base.recall_instruction, tuple(pool[k] for k in chosen), base.reserved_objects) | |
| sc = g['scenario']; random.seed(sc['scene_seed']); np.random.seed(sc['scene_seed']) | |
| env = kitchen(DelayCup, minutes=1, scenario=sc, scene_seed=0, target_cup=1) | |
| else: | |
| env = module.make(g['scenario'], out/'assets') | |
| else: | |
| from experiments.robocasa_memory.evaluation.driver import make_environment | |
| with h5py.File(src/'trajectory.hdf5') as f: meta = json.loads(f.attrs['ep_meta']) | |
| asset = meta['memory_task'].get('asset_dir') | |
| env = make_environment(dict(metadata=meta, minutes=case['env_minutes']), L(asset) if asset else out/'assets') | |
| io = read(OLD/'io.json'); obs = env.reset() | |
| if kind == 'immediate': | |
| from experiments.robocasa_memory.evaluation.immediate_recall import begin_immediate_recall | |
| maxerr = 0.; hidden = [] | |
| with h5py.File(src/'trajectory.hdf5') as tr: | |
| actions = tr['actions']; states = tr['states']; prop = tr['observation.state'] | |
| assert len(actions) >= h | |
| for i in range(h+1): | |
| if kind == 'immediate' and i == b: assert begin_immediate_recall(env, family) == case['instruction'] | |
| err = float(np.max(np.abs(env.sim.get_state().flatten()-states[i]))) | |
| assert np.isfinite(err) and err <= 1e-8, ('state_replay', i, err); maxerr = max(maxerr, err) | |
| assert np.array_equal(encode_state(obs, io), prop[i]), ('proprio_replay', i) | |
| if i > b: hidden.append(concealed(env, family)) | |
| if i < h: obs = env.step(actions[i])[0] | |
| first_hidden = next((j for j, x in enumerate(hidden) if x), None) if hidden else None | |
| if hidden: assert first_hidden is not None and all(hidden[first_hidden:]), 'target became visible before handoff' | |
| if kind == 'short': assert first_hidden == 0, 'short sources must be concealed from the storage boundary on' | |
| assert env.session.phase == Phase.RECALL, env.session.phase | |
| chores_done = env.session.request_index | |
| if kind == 'short': assert chores_done == len(case['chores']), (chores_done, case['chores']) | |
| if kind == 'immediate': assert chores_done == 0 | |
| assert not env.session.violations | |
| assert (env.first_cover is None) if family == 'spice' else (env.occlusion_gate.first_opened_side is None) | |
| res = dict(passed=True, stage=a.stage, case=a.case, family=family, kind=kind, handoff_step=h, storage_steps=b, checked_steps=h+1, | |
| max_state_error=maxerr, proprio_equal_all_steps=True, concealed_steps_checked=len(hidden), first_concealed_offset=first_hidden, | |
| phase_at_handoff='RECALL', chores_done_before_handoff=chores_done, instruction=case['instruction'], seconds=round(time.time()-t0, 1)) | |
| (out/'verify.json').write_text(json.dumps(res, indent=1)+'\n'); print(json.dumps(res)) | |
| if __name__ == '__main__': | |
| main() | |