"""Independent no-optimizer GPU replay and reference-control baseline.""" import os from pathlib import Path ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'output/foundationpose_spider_20260915';TASK=OUT/'datasets/processed/current/l20/bimanual/boxes' os.environ['WARP_CACHE_PATH']=str(ROOT/'.spider_cache/warp');os.environ.setdefault('MUJOCO_GL','osmesa') import numpy as np,json,mujoco,mujoco_warp as mw,warp as wp r=np.load(TASK/'0/trajectory_kinematic_act.npz');a=np.load(TASK/'0/trajectory_mjwp_act.npz');ctrl=a['ctrl'].reshape(-1,56);expected=a['qpos'].reshape(-1,66) m=mujoco.MjModel.from_xml_path(str(TASK/'scene_act.xml'));m.opt.iterations=20;m.opt.ls_iterations=50;m.opt.o_solref[:]=[.02,1];m.opt.o_solimp[:]=[0,.95,.03,.5,2] assert not m.actuator_gainprm[-12:].any() and not m.actuator_biasprm[-12:].any() d=mujoco.MjData(m);d.qpos[:]=r['qpos'][0];d.qvel[:]=r['qvel'][0];d.ctrl[:]=r['ctrl'][0];mujoco.mj_step(m,d);d.time=0 wp.init();rows=[] with wp.ScopedDevice('cuda:0'): wm=mw.put_model(m);wd=mw.put_data(m,d,nworld=2,nconmax=512,njmax=1536) with wp.ScopedCapture() as capture:mw.step(wm,wd) for i,u in enumerate(ctrl): wd.ctrl.assign(np.stack([r['ctrl'][i],u]).astype(np.float32));wp.capture_launch(capture.graph);wp.synchronize();rows.append(wd.qpos.numpy()) rows=np.array(rows);np.savez_compressed(OUT/'independent_gpu_replay.npz',baseline=rows[:,0],optimized_controls=rows[:,1]) report=dict(all_finite=bool(np.isfinite(rows).all()),max_difference_from_native_spider_qpos=float(np.nanmax(np.abs(rows[:,1]-expected))),zero_assistance=True,steps=len(rows),note='Fresh two-world GPU rollout; numerical contact divergence can differ from 96-world MPC replay.') (OUT/'independent_gpu_replay.json').write_text(json.dumps(report,indent=2));print(json.dumps(report,indent=2),flush=True)