"""Experiment 2 orchestrator: select -> build -> cache -> queue of (arm, seed) jobs over 4 GPUs; each job = train 20k -> eval native 200 -> eval rate-matched 200.""" import subprocess, os, sys, json, time, threading, queue R = "/workspace/isr"; P = "aloha_transfer_cube"; SRC = f"{R}/datasets/aloha_sim_transfer_cube_human"; T = "AlohaTransferCube-v0" ARMS = {"raw": (None, 1), "uni3": (["--uniform", "3"], 3), "isr": (["--isr", "--d", "3.5", "--lam", "0.0004", "--gthr", "2.84"], 3)} BUILD_ONLY = os.environ.get("BUILD_ARMS", "").split(",") if os.environ.get("BUILD_ARMS") else list(ARMS) SEEDS = [1000, 2000, 3000]; STEPS = int(os.environ.get("STEPS", "20000")); EPS = int(os.environ.get("EPS", "200")); GPUS = [0, 1, 2, 3, 0, 1, 2, 3] def sh(cmd, log): with open(log, "a") as f: return subprocess.run(cmd, shell=True, executable="/bin/bash", stdout=f, stderr=subprocess.STDOUT, cwd=R).returncode env = dict(os.environ, ISR_SRC=SRC, ISR_TRAJS=f"{R}/trajs_{P}", ISR_KEEPS=f"{R}/keeps2_{P}", ISR_CAMS="observation.images.top", ISR_FPS="50", ISR_ROBOT="aloha") if os.environ.get("STAGE", "data") == "data": if os.environ.get("SKIP_SELECT") != "1": for arm, (sel, rep) in ARMS.items(): if arm not in BUILD_ONLY: continue args = " ".join(sel) if sel else ""; sh(f"source .venv/bin/activate && python select_frames.py --trajs trajs_{P} --out keeps2_{P} --arm {P}2_{arm} {args}", f"{R}/logs/exp2_select.log") procs = [subprocess.Popen(f"source .venv/bin/activate && python -u build.py --arm {P}2_{arm} --workers 10 > logs/exp2_build_{arm}.log 2>&1 && python -u cache_videos.py --arm {P}2_{arm} --procs 10 >> logs/exp2_build_{arm}.log 2>&1", shell=True, executable="/bin/bash", cwd=R, env=env) for arm in BUILD_ONLY] rc = [p.wait() for p in procs]; print("build rc", rc, flush=True) if any(rc): sys.exit(1) print("DATA_DONE", flush=True) jobs = queue.Queue() for seed in SEEDS: for arm, (sel, rep) in ARMS.items(): jobs.put((arm, seed, rep)) def worker(gpu): while True: try: arm, seed, rep = jobs.get_nowait() except queue.Empty: return job = f"{P}2_{arm}" + ("" if seed == 1000 else f"_s{seed}"); log = f"{R}/logs/exp2_job_{arm}_{seed}.log"; t0 = time.time() st = f"{STEPS:06d}"; ck = f"{R}/ckpts/{job}/checkpoints/{st}/pretrained_model/train_config.json" rc = 0 if os.path.exists(ck) else sh(f"bash train_aloha.sh {gpu} {P}2_{arm} {STEPS} 10000 {seed}", log) if rc == 0: if not os.path.exists(f"{R}/results/{job}_{st}_rep1_native/eval_info.json"): sh(f"EPS={EPS} bash eval_rep_aloha.sh {gpu} {job} {st} 1 {T} 400 _native", log) if rep > 1 and not os.path.exists(f"{R}/results/{job}_{st}_rep{rep}/eval_info.json"): sh(f"EPS={EPS} bash eval_rep_aloha.sh {gpu} {job} {st} {rep} {T}", log) print(f"JOB_DONE {arm} seed={seed} gpu={gpu} rc={rc} {time.time()-t0:.0f}s", flush=True) ths = [threading.Thread(target=worker, args=(g,)) for g in GPUS]; [t.start() for t in ths]; [t.join() for t in ths]; print("EXP2_DONE", flush=True)