diff --git a/.gitattributes b/.gitattributes index be6c7a4527a80b811c3df9ecc5f39c764af6c9e8..56164d3ecb6cf94f0d919e225b1df5718f36deab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -84,3 +84,7 @@ go2_sand_finetune/robot_20261124/video/1t.mov filter=lfs diff=lfs merge=lfs -tex go2_sand_finetune/robot_20261124/video/3m.mov filter=lfs diff=lfs merge=lfs -text go2_sand_finetune/robot_20261124/video/3t.mov filter=lfs diff=lfs merge=lfs -text go2_sand_finetune/robot_20261124/video/base.mov filter=lfs diff=lfs merge=lfs -text +so101_pick_place/arch_ablation/results/sealed_test_3t_control.json filter=lfs diff=lfs merge=lfs -text +so101_pick_place/arch_ablation/results/sealed_test_linmap_allsteps_stage2.json filter=lfs diff=lfs merge=lfs -text +so101_pick_place/arch_ablation/results/sealed_test_linmap_stage2.json filter=lfs diff=lfs merge=lfs -text +so101_pick_place/arch_ablation/results/sealed_test_stage2.json filter=lfs diff=lfs merge=lfs -text diff --git a/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced.py b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced.py new file mode 100644 index 0000000000000000000000000000000000000000..150c8a469ddf7f5b7a57a44bdcc20e7aeef6f6bb --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced.py @@ -0,0 +1,314 @@ +"""Verifier probe V4 (3M lens, 2026-11-23): teacher-forced NRD rollouts from MuJoCo-recorded states (no policy), own +code. Sources: the chain's CPU MuJoCo records of the 3T teacher runs a, b, c on the 256 development tasks (per step +q, cube pose, joint targets u, decoder mode, xg). Models: 3T, 3M stage-2 NRDs and two contact swaps built by +replacing the 'contact' TokenNet of a fresh load (TTM = 3T + 3M contact, MMT = 3M + 3T contact). +States: velocities = 20 ms step differences (checked against the NRD records' own cube_v), world spin from +q_t * conj(q_{t-1}). Command alignment: chosen by the smaller one-step arm error (part 0). +Parts + 0 alignment check: one TTT step from MuJoCo windows with u[t] or u[t+1]: arm angle error. + A carry rollouts: history = MuJoCo steps h0-3..h0 (h0 = first 'hold' step), MuJoCo targets, up to the MuJoCo place + trigger (+ 0 steps): closing-axis offset change, held-box exits, jaw overlap, by combo. + B static hold: same start, the target held at its carry-start value for 50 steps (the arm stops): offset change. + C grasp phase: history ends at the first 'g_close' step, MuJoCo targets until h0 + 10: closing-axis offset at h0 + against MuJoCo's (does the grasp itself put the cube at a wrong offset?). + D restoring: set_cube moves the cube by +-2 mm along the closing axis at h0 (velocity = MuJoCo's), reference = the + same call with 0 mm; ratio (x_pert - x_ref) / delta after 1, 12, 25, 50 steps, static target and MuJoCo targets. + E one-step closing-axis velocity error at every MuJoCo carry step (window ending at t, target of step t+1). + PYTHONPATH=/src python -P v4_forced.py OUT.json""" +import json, sys, time +import numpy as np +import torch + +from nedm.contact_nrd.arch_ablation import checkpoints as C +from nedm.so101_policy import task as T +from nedm.so101_policy import vec_env as VE +from nedm.so101_policy.nrd_sim import GraspNrdSim +from nedm.so101_policy.world import WorldState + +S = "/home/harry/arch_ablation_20261118/so101_pp" +N3T, N3M = f"{S}/chain/runs/3t/nrd/nrd_3t_c1_s62.pt", f"{S}/chain/runs/3m/nrd/nrd_3m_c1_s62.pt" +DT = 0.02 +dev = torch.device("cuda") +torch.set_num_threads(4) +kin = VE.kinematics("/home/harry/so101_policy/ckpt/kin_points_v1.npz", dev) +geom = VE.task_geometry("/home/harry/so101_policy/ckpt/task_geom_v2.npz", dev) +cfg = T.TaskConfig.evaluation() +f64 = dict(dtype=torch.float64, device=dev) + + +def model(code): + base = C.load_model(N3T if code[0] == "T" else N3M, "cpu")[0] + if code[2] != code[0]: + base.contact = C.load_model(N3T if code[2] == "T" else N3M, "cpu")[0].contact + if code[1] != code[0]: + base.collision = C.load_model(N3T if code[1] == "T" else N3M, "cpu")[0].collision + for p in base.parameters(): + p.requires_grad_(False) + return base.eval().to(dev) + + +def qconj(q): + return q * np.array([1, -1, -1, -1]) + + +def qmul(a, b): + w1, x1, y1, z1 = np.moveaxis(a, -1, 0) + w2, x2, y2, z2 = np.moveaxis(b, -1, 0) + return np.stack((w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2, w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2, + w1 * y2 - x1 * z2 + y1 * w2 + z1 * x2, w1 * z2 + x1 * y2 - y1 * x2 + z1 * w2), -1) + + +def states(rec): + q = rec["q"].astype(np.float64) + p = rec["cube"][..., :3].astype(np.float64) + qu = rec["cube"][..., 3:].astype(np.float64) + qu /= np.linalg.norm(qu, axis=-1, keepdims=True) + qd, v, w = np.zeros_like(q), np.zeros_like(p), np.zeros_like(p) + qd[:, 1:] = np.diff(q, axis=1) / DT + v[:, 1:] = np.diff(p, axis=1) / DT + dq = qmul(qu[:, 1:], qconj(qu[:, :-1])) + dq *= np.where(dq[..., :1] < 0, -1, 1) + s = np.linalg.norm(dq[..., 1:], axis=-1, keepdims=True) + ang = 2 * np.arctan2(s, dq[..., :1]) + w[:, 1:] = np.where(s > 1e-12, dq[..., 1:] / np.maximum(s, 1e-12), 0) * ang / DT + return dict(q=q, qd=qd, p=p, quat=qu, v=v, w=w) + + +def window(sim, st, b, t): + """history [n, 4, D, S] of MuJoCo steps t-3..t (newest last) in the sim's layout.""" + n = len(b) + h = torch.zeros(n, sim.K, sim.D, sim.S, **f64) + for j in range(sim.K): + tt = t - (sim.K - 1) + j + g = lambda k: torch.as_tensor(st[k][b, tt], **f64) # noqa: E731 + h[:, j, sim.ia, sim.c_aq] = g("q") + h[:, j, sim.ia, sim.c_aqd] = g("qd") + h[:, j, sim.ic, sim.c_cp] = g("p") + h[:, j, sim.ic, sim.c_cq] = g("quat") + h[:, j, sim.ic, sim.c_cv] = g("v") + h[:, j, sim.ic, sim.c_cw] = g("w") + return h + + +def feats(ws): + F = T.features(ws, kin, geom, cfg, overlap=True) + return dict(x=F["xg"][:, 0].cpu().numpy() * 1e3, y=F["xg"][:, 1].cpu().numpy() * 1e3, z=F["xg"][:, 2].cpu().numpy() * 1e3, + ov=F["jaw_overlap"].cpu().numpy() * 1e3, held=F["held"].cpu().numpy(), jaw=F["jaw"].cpu().numpy(), + rgx=F["rg"][:, :, 0].cpu().numpy()) + + +def mj_ws(st, b, t): + g = lambda k: torch.as_tensor(st[k][b, t], **f64) # noqa: E731 + n = len(b) + z = torch.zeros(n, dtype=torch.bool, device=dev) + return WorldState(q=g("q"), qd=g("qd"), cube_pos=g("p"), cube_quat=g("quat"), cube_v=g("v"), cube_w=g("w"), + contact=torch.zeros(n, 3, dtype=torch.bool, device=dev), arm_table=z, invalid=z.clone()) + + +def pc(a, p): + a = np.asarray(a, float) + a = a[np.isfinite(a)] + return None if a.size == 0 else [round(float(v), 3) for v in np.percentile(a, p)] + + +# ---- data ---------------------------------------------------------------------------------------------------------- +recs = {x: dict(np.load(f"{S}/chain/runs/3t/teacherA/mj/tA_3t_s62_{x}_final_gate2.npz")) for x in "abc"} +E = [] # (run, episode, h0, hold end (place trigger), g_close start) +for x, R in recs.items(): + for i in range(256): + m = R["mode"][i, :int(R["t_end"][i])].astype(int) + h = np.nonzero(m == 7)[0] + gc = np.nonzero(m == 4)[0] + if len(h) == 0 or len(gc) == 0 or gc[0] < 4: + continue + e = h[0] + while e < len(m) and m[e] == 7: + e += 1 + E.append((x, i, int(h[0]), int(e), int(gc[0]))) +ST = {x: states(R) for x, R in recs.items()} +# stack the three runs into one batch (run offset 256 per run) +off = {"a": 0, "b": 256, "c": 512} +STc = {k: np.concatenate([ST[x][k] for x in "abc"]) for k in ST["a"]} +U = np.concatenate([recs[x]["u"].astype(np.float64) for x in "abc"]) +XG = np.concatenate([recs[x]["xg"].astype(np.float64) for x in "abc"]) * 1e3 +B = np.array([off[e[0]] + e[1] for e in E]) +H0 = np.array([e[2] for e in E]) +HE = np.array([e[3] for e in E]) +GC = np.array([e[4] for e in E]) +n = len(B) +print("carries", n, "carry s p50", np.median(HE - H0) * DT, flush=True) +out = dict(n_carries=int(n), runs="3T teacher a, b, c MuJoCo records", carry_s_p10_50_90=pc((HE - H0) * DT, [10, 50, 90])) +COMBOS = ("TTT", "MMM", "TTM", "MMT", "MTT", "TMT") +MODELS = {c: model(c) for c in COMBOS} + + +def newsim(code, N): + return GraspNrdSim({code: MODELS[code]}, num_envs=N, device=dev, canonical=True, cuda_graph=False) + + +# ---- part 0: command alignment --------------------------------------------------------------------------------------- +sim = newsim("TTT", n) +ok = torch.ones(n, 4, dtype=torch.bool, device=dev) +al = {} +for name, du in (("u[t]", 0), ("u[t+1]", 1)): + sim.reset_history(None, window(sim, STc, B, H0), ok, finish=True) + ws = sim.step(torch.as_tensor(U[B, H0 + du], **f64)) + al[name] = float(np.median(np.abs(ws.q.cpu().numpy() - STc["q"][B, H0 + 1]).max(-1))) +out["part0_alignment_arm_err_rad_p50"] = al +DU = 1 if al["u[t+1]"] < al["u[t]"] else 0 +print("alignment", al, "DU", DU, flush=True) +Lmax = int((HE - H0).max()) + +# ---- part A / B: carry rollouts and static hold -------------------------------------------------------------------- +mjx = XG[B[:, None], np.minimum(H0[:, None] + np.arange(Lmax + 1)[None], 399), 0] +A, Bst = {}, {} +for code in COMBOS: + t0 = time.time() + for part in ("A", "B"): + sim = newsim(code, n) + sim.reset_history(None, window(sim, STc, B, H0), ok, finish=True) + f0 = feats(sim.observe()) + K = Lmax if part == "A" else 50 + xs, ovs, helds = [f0["x"]], [f0["ov"]], [f0["held"]] + for k in range(K): + if part == "A": + u = U[B, np.minimum(H0 + k + DU, 399)] + else: + u = U[B, H0 + DU - 1] if DU else U[B, H0] + f = feats(sim.step(torch.as_tensor(u, **f64))) + xs.append(f["x"]); ovs.append(f["ov"]); helds.append(f["held"]) + X, OV, HD = np.stack(xs, 1), np.stack(ovs, 1), np.stack(helds, 1) + kk = np.arange(X.shape[1])[None] + if part == "A": + inside = kk <= (HE - H0)[:, None] - 1 # MuJoCo carry steps + dx_end = X[np.arange(n), HE - H0 - 1] - X[:, 0] + sign = ((OV > 0.2) | (np.abs(X) > 12.0)) & inside + first = np.where(sign.any(1), sign.argmax(1), 10 ** 6) + r = dict(dx_end_mm_p5_50_95=pc(dx_end, [5, 50, 95]), abs_dx_end_mm_p50_95=pc(np.abs(dx_end), [50, 95]), + steps_abs_x_gt12mm_pct=round(100 * float(np.mean(np.abs(X)[inside] > 12)), 2), + steps_overlap_gt0p2mm_pct=round(100 * float(np.mean(OV[inside] > 0.2)), 2), + episodes_sign_pct=round(100 * float(np.mean(first < 10 ** 6)), 1), + sign_by_s={str(s): (lambda el: None if not el.any() else round(100 * float(np.mean(first[el] < int(s / DT))), 1))((HE - H0) >= int(s / DT)) + for s in (0.25, 0.5, 1.0)}, + abs_dx_after_s_mm_p50={str(s): pc(np.abs(X[:, int(s / DT)] - X[:, 0])[(HE - H0) > int(s / DT)], [50]) + for s in (0.1, 0.2, 0.3, 0.5, 1.0)}) + if code == "TTT": + out["A_mujoco_abs_dx_end_mm_p50_95"] = pc(np.abs(mjx[np.arange(n), HE - H0 - 1] - mjx[:, 0]), [50, 95]) + A[code] = r + if code in ("TTT", "MMM"): + np.savez_compressed(f"{sys.argv[1][:-5]}_A_{code}.npz", X=X.astype(np.float32), OV=OV.astype(np.float32), B=B, H0=H0, HE=HE) + else: + Bst[code] = dict(abs_dx_after_s_mm_p50_95={str(s): pc(np.abs(X[:, int(s / DT)] - X[:, 0]), [50, 95]) for s in (0.1, 0.2, 0.5, 1.0)}, + steps_abs_x_gt12mm_pct=round(100 * float(np.mean(np.abs(X) > 12)), 2), + steps_overlap_gt0p2mm_pct=round(100 * float(np.mean(OV > 0.2)), 2), + episodes_sign_pct=round(100 * float(np.mean(((OV > 0.2) | (np.abs(X) > 12)).any(1))), 1)) + del sim + print(code, "A", json.dumps(A[code]), "\n B", json.dumps(Bst[code]), round(time.time() - t0, 1), flush=True) +out["A_carry_rollouts"] = A +out["B_static_hold"] = Bst + +# motion along the closing axis (MuJoCo) against the 3M carry drift: per episode +d = np.load(f"{sys.argv[1][:-5]}_A_MMM.npz") +Xm = d["X"] +ax = [] +for j in range(n): + b, h0, he = B[j], H0[j], HE[j] + ws = None + ax.append(0.0) +F_h = T.features(mj_ws(STc, B, H0), kin, None, cfg, overlap=False) +rgx = F_h["rg"][:, :, 0].cpu().numpy() # closing axis (world) at h0 +vproj = np.array([np.max(np.abs(STc["v"][B[j], H0[j]:HE[j]] @ rgx[j])) for j in range(n)]) +vperp = np.array([np.max(np.linalg.norm(STc["v"][B[j], H0[j]:HE[j], :2], axis=-1)) for j in range(n)]) +dxm = np.abs(Xm[np.arange(n), HE - H0 - 1] - Xm[:, 0]) +out["A_3M_drift_vs_motion"] = dict( + corr_absdx_vs_peak_speed_along_closing_axis=round(float(np.corrcoef(dxm, vproj)[0, 1]), 3), + corr_absdx_vs_peak_horizontal_speed=round(float(np.corrcoef(dxm, vperp)[0, 1]), 3), + corr_absdx_vs_carry_len=round(float(np.corrcoef(dxm, HE - H0)[0, 1]), 3), + absdx_p50_by_closing_axis_speed_tercile=[pc(dxm[(vproj >= lo) & (vproj <= hi)], [50]) for lo, hi in + zip(np.percentile(vproj, [0, 33.3, 66.7]), np.percentile(vproj, [33.3, 66.7, 100]))], + closing_axis_speed_terciles_m_s=pc(vproj, [33.3, 66.7])) +print("drift vs motion", out["A_3M_drift_vs_motion"], flush=True) + +# ---- part C: grasp phase ----------------------------------------------------------------------------------------------- +Cg = {} +Kc = int((H0 - GC).max()) + 10 +mj_x_h0 = XG[B, H0, 0] +for code in ("TTT", "MMM", "TTM", "MMT"): + sim = newsim(code, n) + sim.reset_history(None, window(sim, STc, B, GC), ok, finish=True) + xs, jaws, helds = [], [], [] + for k in range(Kc): + f = feats(sim.step(torch.as_tensor(U[B, np.minimum(GC + k + DU, 399)], **f64))) + xs.append(f["x"]); jaws.append(f["jaw"]); helds.append(f["held"]) + X, J, HD = np.stack(xs, 1), np.stack(jaws, 1), np.stack(helds, 1) + idx = H0 - GC - 1 # step k+1 = GC + k + 1 -> h0 at k = h0 - gc - 1 + xh = X[np.arange(n), idx] + Cg[code] = dict(x_at_h0_mm_p5_50_95=pc(xh, [5, 50, 95]), x_minus_mujoco_at_h0_mm_p5_50_95=pc(xh - mj_x_h0, [5, 50, 95]), + abs_x_minus_mujoco_at_h0_mm_p50_90=pc(np.abs(xh - mj_x_h0), [50, 90]), + jaw_at_h0_rad_p50=pc(J[np.arange(n), idx], [50]), held_at_h0_pct=round(100 * float(HD[np.arange(n), idx].mean()), 1)) + print(code, "C", json.dumps(Cg[code]), flush=True) + del sim +out["C_grasp_phase"] = Cg +out["C_mujoco_x_at_h0_mm_p5_50_95"] = pc(mj_x_h0, [5, 50, 95]) + +# ---- part D: restoring ------------------------------------------------------------------------------------------------- +Dr = {} +for code in ("TTT", "MMM", "TTM", "MMT"): + row = {} + for drive in ("static", "mujoco"): + res = {} + for dl in (-2.0, 0.0, 2.0): + sim = newsim(code, n) + sim.reset_history(None, window(sim, STc, B, H0), ok, finish=True) + p = torch.as_tensor(STc["p"][B, H0] + dl * 1e-3 * rgx, **f64) + sim.set_cube(None, p, torch.as_tensor(STc["quat"][B, H0], **f64), torch.as_tensor(STc["v"][B, H0], **f64), + torch.as_tensor(STc["w"][B, H0], **f64)) + xs = [feats(sim.observe())["x"]] + for k in range(50): + if drive == "mujoco": + u = U[B, np.minimum(H0 + k + DU, 399)] + else: + u = U[B, H0 + DU - 1] if DU else U[B, H0] + xs.append(feats(sim.step(torch.as_tensor(u, **f64)))["x"]) + res[dl] = np.stack(xs, 1) + del sim + ratio = {} + for k in (1, 12, 25, 50): + r = 0.5 * ((res[2.0][:, k] - res[0.0][:, k]) / 2.0 + (res[-2.0][:, k] - res[0.0][:, k]) / -2.0) + if drive == "mujoco": + r = r[(HE - H0) > k] + ratio[f"{k * DT:.2f}s"] = pc(r, [10, 50, 90]) + row[drive] = dict(kept_fraction_p10_50_90=ratio, start_ratio_p50=pc(0.5 * ((res[2.0][:, 0] - res[0.0][:, 0]) / 2 + (res[-2.0][:, 0] - res[0.0][:, 0]) / -2), [50])) + Dr[code] = row + print(code, "D", json.dumps(row), flush=True) +out["D_restoring"] = Dr + +# ---- part E: one-step closing-axis velocity error over MuJoCo carry steps ------------------------------------------ +bb, tt = [], [] +for j in range(n): + for t in range(H0[j], HE[j] - 1): + bb.append(B[j]); tt.append(t) +bb, tt = np.array(bb), np.array(tt) +N = len(bb) +F1 = T.features(mj_ws(STc, bb, tt + 1), kin, None, cfg, overlap=False) +ax1 = F1["rg"][:, :, 0].cpu().numpy() +vtrue = STc["v"][bb, tt + 1] +Eo = {} +for code in COMBOS: + errs = [] + for a0 in range(0, N, 4096): + sl = slice(a0, min(N, a0 + 4096)) + m_ = sl.stop - sl.start + sim = newsim(code, m_) + sim.reset_history(None, window(sim, STc, bb[sl], tt[sl]), torch.ones(m_, 4, dtype=torch.bool, device=dev), finish=True) + ws = sim.step(torch.as_tensor(U[bb[sl], np.minimum(tt[sl] + DU, 399)], **f64)) + e = ws.cube_v.cpu().numpy() - vtrue[sl] + errs.append(np.sum(e * ax1[sl], -1)) + del sim + e = np.concatenate(errs) * 1e3 + Eo[code] = dict(rms_mm_s=round(float(np.sqrt(np.mean(e ** 2))), 3), mean_mm_s=round(float(np.mean(e)), 3), + p95_abs_mm_s=round(float(np.percentile(np.abs(e), 95)), 3)) + print(code, "E", Eo[code], flush=True) +out["E_one_step_closing_axis_v_err"] = dict(n=int(N), **Eo) +json.dump(out, open(sys.argv[1], "w"), indent=1) +print("saved", flush=True) diff --git a/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced_A_MMM.npz b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced_A_MMM.npz new file mode 100644 index 0000000000000000000000000000000000000000..56f1b669bbddff6c40b3b6521b430b77a6f0bd2f --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced_A_MMM.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99f9d1bfcbad26fdfe6cc398ff23019825305d2c2ddd00ac63d78551e3258cc6 +size 495833 diff --git a/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced_A_TTT.npz b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced_A_TTT.npz new file mode 100644 index 0000000000000000000000000000000000000000..34a52c620f4c6654769c1b44979e590783e6b5dc --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_forced_A_TTT.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1f260e51b40fa17dcdcbb13a8c641f52ab3403c57e7ebe3d783ece4bf0b6dd1 +size 440386 diff --git a/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_lib.py b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_lib.py new file mode 100644 index 0000000000000000000000000000000000000000..560c884b5769f669bfb46fffaa1264be9abc5410 --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/3m_verify/v4_lib.py @@ -0,0 +1,134 @@ +"""Helpers of v4_forced.py (copied verbatim up to its data section) + data(): importable library for v9.""" +"""Verifier probe V4 (3M lens, 2026-11-23): teacher-forced NRD rollouts from MuJoCo-recorded states (no policy), own +code. Sources: the chain's CPU MuJoCo records of the 3T teacher runs a, b, c on the 256 development tasks (per step +q, cube pose, joint targets u, decoder mode, xg). Models: 3T, 3M stage-2 NRDs and two contact swaps built by +replacing the 'contact' TokenNet of a fresh load (TTM = 3T + 3M contact, MMT = 3M + 3T contact). +States: velocities = 20 ms step differences (checked against the NRD records' own cube_v), world spin from +q_t * conj(q_{t-1}). Command alignment: chosen by the smaller one-step arm error (part 0). +Parts + 0 alignment check: one TTT step from MuJoCo windows with u[t] or u[t+1]: arm angle error. + A carry rollouts: history = MuJoCo steps h0-3..h0 (h0 = first 'hold' step), MuJoCo targets, up to the MuJoCo place + trigger (+ 0 steps): closing-axis offset change, held-box exits, jaw overlap, by combo. + B static hold: same start, the target held at its carry-start value for 50 steps (the arm stops): offset change. + C grasp phase: history ends at the first 'g_close' step, MuJoCo targets until h0 + 10: closing-axis offset at h0 + against MuJoCo's (does the grasp itself put the cube at a wrong offset?). + D restoring: set_cube moves the cube by +-2 mm along the closing axis at h0 (velocity = MuJoCo's), reference = the + same call with 0 mm; ratio (x_pert - x_ref) / delta after 1, 12, 25, 50 steps, static target and MuJoCo targets. + E one-step closing-axis velocity error at every MuJoCo carry step (window ending at t, target of step t+1). + PYTHONPATH=/src python -P v4_forced.py OUT.json""" +import json, sys, time +import numpy as np +import torch + +from nedm.contact_nrd.arch_ablation import checkpoints as C +from nedm.so101_policy import task as T +from nedm.so101_policy import vec_env as VE +from nedm.so101_policy.nrd_sim import GraspNrdSim +from nedm.so101_policy.world import WorldState + +S = "/home/harry/arch_ablation_20261118/so101_pp" +N3T, N3M = f"{S}/chain/runs/3t/nrd/nrd_3t_c1_s62.pt", f"{S}/chain/runs/3m/nrd/nrd_3m_c1_s62.pt" +DT = 0.02 +dev = torch.device("cuda") +torch.set_num_threads(4) +kin = VE.kinematics("/home/harry/so101_policy/ckpt/kin_points_v1.npz", dev) +geom = VE.task_geometry("/home/harry/so101_policy/ckpt/task_geom_v2.npz", dev) +cfg = T.TaskConfig.evaluation() +f64 = dict(dtype=torch.float64, device=dev) + + +def model(code): + base = C.load_model(N3T if code[0] == "T" else N3M, "cpu")[0] + if code[2] != code[0]: + base.contact = C.load_model(N3T if code[2] == "T" else N3M, "cpu")[0].contact + if code[1] != code[0]: + base.collision = C.load_model(N3T if code[1] == "T" else N3M, "cpu")[0].collision + for p in base.parameters(): + p.requires_grad_(False) + return base.eval().to(dev) + + +def qconj(q): + return q * np.array([1, -1, -1, -1]) + + +def qmul(a, b): + w1, x1, y1, z1 = np.moveaxis(a, -1, 0) + w2, x2, y2, z2 = np.moveaxis(b, -1, 0) + return np.stack((w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2, w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2, + w1 * y2 - x1 * z2 + y1 * w2 + z1 * x2, w1 * z2 + x1 * y2 - y1 * x2 + z1 * w2), -1) + + +def states(rec): + q = rec["q"].astype(np.float64) + p = rec["cube"][..., :3].astype(np.float64) + qu = rec["cube"][..., 3:].astype(np.float64) + qu /= np.linalg.norm(qu, axis=-1, keepdims=True) + qd, v, w = np.zeros_like(q), np.zeros_like(p), np.zeros_like(p) + qd[:, 1:] = np.diff(q, axis=1) / DT + v[:, 1:] = np.diff(p, axis=1) / DT + dq = qmul(qu[:, 1:], qconj(qu[:, :-1])) + dq *= np.where(dq[..., :1] < 0, -1, 1) + s = np.linalg.norm(dq[..., 1:], axis=-1, keepdims=True) + ang = 2 * np.arctan2(s, dq[..., :1]) + w[:, 1:] = np.where(s > 1e-12, dq[..., 1:] / np.maximum(s, 1e-12), 0) * ang / DT + return dict(q=q, qd=qd, p=p, quat=qu, v=v, w=w) + + +def window(sim, st, b, t): + """history [n, 4, D, S] of MuJoCo steps t-3..t (newest last) in the sim's layout.""" + n = len(b) + h = torch.zeros(n, sim.K, sim.D, sim.S, **f64) + for j in range(sim.K): + tt = t - (sim.K - 1) + j + g = lambda k: torch.as_tensor(st[k][b, tt], **f64) # noqa: E731 + h[:, j, sim.ia, sim.c_aq] = g("q") + h[:, j, sim.ia, sim.c_aqd] = g("qd") + h[:, j, sim.ic, sim.c_cp] = g("p") + h[:, j, sim.ic, sim.c_cq] = g("quat") + h[:, j, sim.ic, sim.c_cv] = g("v") + h[:, j, sim.ic, sim.c_cw] = g("w") + return h + + +def feats(ws): + F = T.features(ws, kin, geom, cfg, overlap=True) + return dict(x=F["xg"][:, 0].cpu().numpy() * 1e3, y=F["xg"][:, 1].cpu().numpy() * 1e3, z=F["xg"][:, 2].cpu().numpy() * 1e3, + ov=F["jaw_overlap"].cpu().numpy() * 1e3, held=F["held"].cpu().numpy(), jaw=F["jaw"].cpu().numpy(), + rgx=F["rg"][:, :, 0].cpu().numpy()) + + +def mj_ws(st, b, t): + g = lambda k: torch.as_tensor(st[k][b, t], **f64) # noqa: E731 + n = len(b) + z = torch.zeros(n, dtype=torch.bool, device=dev) + return WorldState(q=g("q"), qd=g("qd"), cube_pos=g("p"), cube_quat=g("quat"), cube_v=g("v"), cube_w=g("w"), + contact=torch.zeros(n, 3, dtype=torch.bool, device=dev), arm_table=z, invalid=z.clone()) + + +def pc(a, p): + a = np.asarray(a, float) + a = a[np.isfinite(a)] + return None if a.size == 0 else [round(float(v), 3) for v in np.percentile(a, p)] + + + +def data(): + recs = {x: dict(np.load(f"{S}/chain/runs/3t/teacherA/mj/tA_3t_s62_{x}_final_gate2.npz")) for x in "abc"} + E = [] + for x, R in recs.items(): + for i in range(256): + m = R["mode"][i, :int(R["t_end"][i])].astype(int) + h = np.nonzero(m == 7)[0] + gc = np.nonzero(m == 4)[0] + if len(h) == 0 or len(gc) == 0 or gc[0] < 4: + continue + e = h[0] + while e < len(m) and m[e] == 7: + e += 1 + E.append(({"a": 0, "b": 256, "c": 512}[x] + i, int(h[0]), int(e))) + ST = {x: states(R) for x, R in recs.items()} + STc = {k: np.concatenate([ST[x][k] for x in "abc"]) for k in ST["a"]} + U = np.concatenate([recs[x]["u"].astype(np.float64) for x in "abc"]) + XG = np.concatenate([recs[x]["xg"].astype(np.float64) for x in "abc"]) * 1e3 + return STc, U, XG, np.array([e[0] for e in E]), np.array([e[1] for e in E]), np.array([e[2] for e in E]) diff --git a/so101_pick_place/arch_ablation/mechanism/3m_verify/v8_jump.json b/so101_pick_place/arch_ablation/mechanism/3m_verify/v8_jump.json new file mode 100644 index 0000000000000000000000000000000000000000..165e1c66c15e271a54f95c7b204183e692410c7e --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/3m_verify/v8_jump.json @@ -0,0 +1,84 @@ +{ + "TTT": { + "median_abs_dx_mm_at_step": { + "0": 0.0, + "2": 0.009, + "5": 0.198, + "8": 0.634, + "10": 0.742, + "12": 0.884, + "15": 0.959, + "20": 1.137, + "25": 1.352, + "35": 1.356, + "50": 1.388 + }, + "median_abs_step_change_mm_at_step": { + "0": 0.0039, + "2": 0.0101, + "5": 0.1767, + "8": 0.1687, + "10": 0.1485, + "12": 0.1755, + "15": 0.2026, + "20": 0.2326, + "25": 0.2299, + "35": 0.242, + "50": 0.2307 + }, + "motion_onset_step_p10_50_90": [ + 1, + 3, + 5 + ], + "median_abs_dx_before_onset_mm": 0.02, + "median_abs_dx_in_0p2s_after_onset_mm": 0.961, + "share_of_final_abs_dx_reached_by_0p3s_p25_50_75_(final>2mm)": [ + 0.134, + 0.303, + 0.525 + ], + "n_final_abs_dx_gt2mm": 322 + }, + "MMM": { + "median_abs_dx_mm_at_step": { + "0": 0.0, + "2": 0.017, + "5": 0.239, + "8": 1.991, + "10": 3.725, + "12": 5.433, + "15": 6.05, + "20": 5.639, + "25": 5.612, + "35": 5.409, + "50": 5.099 + }, + "median_abs_step_change_mm_at_step": { + "0": 0.0068, + "2": 0.0201, + "5": 0.3589, + "8": 0.809, + "10": 0.7625, + "12": 0.5524, + "15": 0.3492, + "20": 0.3277, + "25": 0.3264, + "35": 0.3375, + "50": 0.3655 + }, + "motion_onset_step_p10_50_90": [ + 1, + 3, + 5 + ], + "median_abs_dx_before_onset_mm": 0.032, + "median_abs_dx_in_0p2s_after_onset_mm": 6.231, + "share_of_final_abs_dx_reached_by_0p3s_p25_50_75_(final>2mm)": [ + 0.5, + 0.893, + 1.488 + ], + "n_final_abs_dx_gt2mm": 635 + } +} \ No newline at end of file diff --git a/so101_pick_place/arch_ablation/mechanism/3m_verify/v8_jump.py b/so101_pick_place/arch_ablation/mechanism/3m_verify/v8_jump.py new file mode 100644 index 0000000000000000000000000000000000000000..d8c7571afe0bbb65baf1ee95c9e27f176fd73e8a --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/3m_verify/v8_jump.py @@ -0,0 +1,45 @@ +"""Verifier probe V8 (3M lens): time course of the closing-axis offset in the teacher-forced carry rollouts of V4 +(out/v4_forced_A_{TTT,MMM}.npz; 768 MuJoCo carries of the 3T teacher runs a/b/c, MuJoCo targets). numpy only. +Is the 3M drift a steady accumulation of step errors (random walk / constant bias) or a jump when the carry motion +starts? Per step k: median |x_k - x_0|, median |x_k - x_{k-1}| (per-step change), and the share of the final |dx| +already reached by 0.3 s; arm motion onset from MuJoCo: first step where the cube speed (MuJoCo) exceeds 20 mm/s. + python -I v8_jump.py OUT.json""" +import json, sys +import numpy as np +S = "/home/harry/arch_ablation_20261118/so101_pp" +recs = {x: np.load(f"{S}/chain/runs/3t/teacherA/mj/tA_3t_s62_{x}_final_gate2.npz") for x in "abc"} +cube = np.concatenate([recs[x]["cube"][..., :3].astype(float) for x in "abc"]) +out = {} +for code in ("TTT", "MMM"): + d = np.load(f"out/v4_forced_A_{code}.npz") + X, B, H0, HE = d["X"].astype(float), d["B"], d["H0"], d["HE"] + L = HE - H0 + n = len(B) + row = {} + ks = [0, 2, 5, 8, 10, 12, 15, 20, 25, 35, 50] + row["median_abs_dx_mm_at_step"] = {str(k): round(float(np.median(np.abs(X[L > k, k] - X[L > k, 0]))), 3) for k in ks} + step = np.abs(np.diff(X, axis=1)) + row["median_abs_step_change_mm_at_step"] = {str(k): round(float(np.median(step[L > k + 1, k])), 4) for k in ks} + # onset of motion: MuJoCo cube speed > 20 mm/s after h0 + onset, frac03, dx_onset = [], [], [] + for j in range(n): + p = cube[B[j], H0[j]:HE[j]] + sp = np.linalg.norm(np.diff(p, axis=0), axis=-1) / 0.02 + o = int(np.argmax(sp > 0.02)) if (sp > 0.02).any() else -1 + onset.append(o) + if L[j] > 15: + fin = abs(X[j, L[j] - 1] - X[j, 0]) + frac03.append(abs(X[j, 15] - X[j, 0]) / max(fin, 1e-6) if fin > 2.0 else np.nan) + if o >= 0 and o + 10 < L[j]: + dx_onset.append((abs(X[j, o] - X[j, 0]), abs(X[j, o + 10] - X[j, o]))) + onset = np.array(onset) + dx_onset = np.array(dx_onset) + row["motion_onset_step_p10_50_90"] = [int(v) for v in np.percentile(onset[onset >= 0], [10, 50, 90])] + row["median_abs_dx_before_onset_mm"] = round(float(np.median(dx_onset[:, 0])), 3) + row["median_abs_dx_in_0p2s_after_onset_mm"] = round(float(np.median(dx_onset[:, 1])), 3) + fr = np.array(frac03) + row["share_of_final_abs_dx_reached_by_0p3s_p25_50_75_(final>2mm)"] = [round(float(v), 3) for v in np.nanpercentile(fr, [25, 50, 75])] + row["n_final_abs_dx_gt2mm"] = int(np.sum(np.isfinite(fr))) + out[code] = row + print(code, json.dumps(row)) +json.dump(out, open(sys.argv[1], "w"), indent=1) diff --git a/so101_pick_place/arch_ablation/mechanism/RUN_ORDER.txt b/so101_pick_place/arch_ablation/mechanism/RUN_ORDER.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb27c3442e60a1dfa5486faff499b523da0ec8e5 --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/RUN_ORDER.txt @@ -0,0 +1,11 @@ +Run order (all python through bin/luffy_slot.sh; PYTHONPATH=/home/harry/NeDM_wt/abl-pp-policy-lt/src; env nedm): +1. scripts/extract_val.py scratch/val_subset validation (split 1) episodes -> scratch (unified_data.npz deleted after use, + sha256 3025cb32f9c5..., 3,269 episodes; re-create with this script) +2. scripts/fk_check.py FK cube-in-gripper == recorded cube_in_grasp (max 3.2e-8 m) +3. scripts/run_windows.sh window_probe.py per NRD (1 s rollouts, 154,465 windows) -> out/windows_.npz +4. scripts/analyze.py window classes, components, Spearman/Kendall -> out/metrics.{json,md} +5. scripts/breakdown.py, trace_check.py, turn_gain.py, rest_crosstalk.py component details -> out/*.txt/json +6. scripts/scales.py, input_scales.py, loss_scales.py, trainer_validation.py checkpoint / record reads -> out/* +7. scripts/mj_fail_modes.py, turn_accounting.py, turn_sign.py stored teacher-A episodes (dev tasks, both worlds) +8. scripts/final_corr.py rank correlations incl. transfer gap -> out/final_corr.{json,txt} +No sealed data loaded (sealed headline values read from results/sealed_test_*stage2.txt, see out/sealed_headline_SOURCE.txt). diff --git a/so101_pick_place/arch_ablation/mechanism/metrics.json b/so101_pick_place/arch_ablation/mechanism/metrics.json new file mode 100644 index 0000000000000000000000000000000000000000..e7a35bb1bea90d48a963719047cd950f070d792d --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/metrics.json @@ -0,0 +1,490 @@ +{ + "labels": [ + "3t", + "3m", + "1tlt", + "1mlt", + "1m", + "1t", + "1tlf", + "1mlf" + ], + "counts": { + "3t": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "3m": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "1tlt": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "1mlt": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "1m": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "1t": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "1tlf": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + }, + "1mlf": { + "carry": 29423, + "carry_turn": 22258, + "close": 2899, + "release": 1455, + "rest": 41069, + "arm_free": 41267, + "headline": 28822 + } + }, + "table": { + "3t": { + "headline: cube pos 1 s p95 (validation)": 8.172967750579113, + "carry: cube pos in gripper frame 1 s p95": 10.628970619291065, + "carry: cube pos in gripper frame 1 s p50": 2.9302258044481277, + "carry: cube world pos 1 s p95": 10.98871640861033, + "carry: grasp point (arm) pos 1 s p95": 2.322584856301542, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 3.5348145036321554, + "carry: cube rotation in gripper frame 1 s p95": 3.8279110049985325, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 3.8570009300840056, + "carry: jaw angle 1 s p95": 1.4973367680795464, + "close: jaw angle 1 s p95": 1.2707841931842263, + "close: cube pos in gripper frame 1 s p95": 6.157421506941317, + "release: cube world pos 1 s p95": 10.163975879549978, + "release: cube rotation 1 s p95": 8.206075112270083, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.089976807066705, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 0.34195289786032995, + "arm_free: 5 arm joints RMS 1 s p95": 7.093155011534689, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 25.955884851986543, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.021914339282670628 + }, + "3m": { + "headline: cube pos 1 s p95 (validation)": 15.84288561716675, + "carry: cube pos in gripper frame 1 s p95": 23.517969995737072, + "carry: cube pos in gripper frame 1 s p50": 8.084055036306381, + "carry: cube world pos 1 s p95": 23.570068739354596, + "carry: grasp point (arm) pos 1 s p95": 2.5548083474859595, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 5.4686445759556905, + "carry: cube rotation in gripper frame 1 s p95": 5.992040051063064, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 5.824091825198359, + "carry: jaw angle 1 s p95": 2.876618946902454, + "close: jaw angle 1 s p95": 2.791181812062858, + "close: cube pos in gripper frame 1 s p95": 7.722938153892753, + "release: cube world pos 1 s p95": 10.633494984358547, + "release: cube rotation 1 s p95": 7.891383110885026, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.1004224541247822, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 0.13877753912837912, + "arm_free: 5 arm joints RMS 1 s p95": 6.864586612209676, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 70.99208102504844, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.046263605152304654 + }, + "1tlt": { + "headline: cube pos 1 s p95 (validation)": 8.573253080248818, + "carry: cube pos in gripper frame 1 s p95": 11.519299261271946, + "carry: cube pos in gripper frame 1 s p50": 3.344431286677718, + "carry: cube world pos 1 s p95": 12.343015149235706, + "carry: grasp point (arm) pos 1 s p95": 2.9119913931936026, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 28.50829964368102, + "carry: cube rotation in gripper frame 1 s p95": 28.590608375066836, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 30.25118291985529, + "carry: jaw angle 1 s p95": 5.296716326847669, + "close: jaw angle 1 s p95": 5.203613871708511, + "close: cube pos in gripper frame 1 s p95": 5.955005856230854, + "release: cube world pos 1 s p95": 10.259832348674536, + "release: cube rotation 1 s p95": 25.66166514008608, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.5901633645407852, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 2.246977020885306, + "arm_free: 5 arm joints RMS 1 s p95": 6.845965096727007, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 31.05393739591476, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.17531471426136502 + }, + "1mlt": { + "headline: cube pos 1 s p95 (validation)": 12.34600539319216, + "carry: cube pos in gripper frame 1 s p95": 21.34742774069307, + "carry: cube pos in gripper frame 1 s p50": 5.632121115922928, + "carry: cube world pos 1 s p95": 21.624629572033882, + "carry: grasp point (arm) pos 1 s p95": 2.6017849100753665, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 33.10708086751206, + "carry: cube rotation in gripper frame 1 s p95": 33.749770249540084, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 35.25436410576239, + "carry: jaw angle 1 s p95": 11.774924676865309, + "close: jaw angle 1 s p95": 5.746900895610452, + "close: cube pos in gripper frame 1 s p95": 6.529101636260745, + "release: cube world pos 1 s p95": 10.448383074253792, + "release: cube rotation 1 s p95": 26.39601309945473, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.8192391251213842, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 2.4912113094247625, + "arm_free: 5 arm joints RMS 1 s p95": 6.978075718507166, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 55.83387146110186, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.4309820058925223 + }, + "1m": { + "headline: cube pos 1 s p95 (validation)": 8.954343898221843, + "carry: cube pos in gripper frame 1 s p95": 12.185905501246447, + "carry: cube pos in gripper frame 1 s p50": 3.6810203455388546, + "carry: cube world pos 1 s p95": 13.542545214295382, + "carry: grasp point (arm) pos 1 s p95": 7.383528258651494, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 17.831852171832583, + "carry: cube rotation in gripper frame 1 s p95": 20.06662381542581, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 18.91178354140969, + "carry: jaw angle 1 s p95": 1.6102245659567413, + "close: jaw angle 1 s p95": 12.457479070872056, + "close: cube pos in gripper frame 1 s p95": 5.2483746781945175, + "release: cube world pos 1 s p95": 9.864111803472033, + "release: cube rotation 1 s p95": 27.50920979547865, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.9850751375779508, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 4.4768387829936565, + "arm_free: 5 arm joints RMS 1 s p95": 35.51009185612201, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 33.75930394589267, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.7475224621977647 + }, + "1t": { + "headline: cube pos 1 s p95 (validation)": 8.879039948806163, + "carry: cube pos in gripper frame 1 s p95": 6.403281632810829, + "carry: cube pos in gripper frame 1 s p50": 1.9850591197609901, + "carry: cube world pos 1 s p95": 12.024735566228625, + "carry: grasp point (arm) pos 1 s p95": 14.494350738823409, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 18.569166311603045, + "carry: cube rotation in gripper frame 1 s p95": 19.536378130156418, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 19.821842727554614, + "carry: jaw angle 1 s p95": 2.555548935197292, + "close: jaw angle 1 s p95": 7.305729249492287, + "close: cube pos in gripper frame 1 s p95": 4.171104170382023, + "release: cube world pos 1 s p95": 10.14873590320348, + "release: cube rotation 1 s p95": 29.32348869753759, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.8244729833677408, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 2.9874077759740407, + "arm_free: 5 arm joints RMS 1 s p95": 407.0494234561919, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 9.414403697787446, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.3092356765443522 + }, + "1tlf": { + "headline: cube pos 1 s p95 (validation)": 8.126319618895645, + "carry: cube pos in gripper frame 1 s p95": 11.077642720192665, + "carry: cube pos in gripper frame 1 s p50": 2.9968172311782837, + "carry: cube world pos 1 s p95": 11.883323919028038, + "carry: grasp point (arm) pos 1 s p95": 2.9185070889070626, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 35.97514526038267, + "carry: cube rotation in gripper frame 1 s p95": 36.033529034389005, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 37.88157485491192, + "carry: jaw angle 1 s p95": 5.778738949447869, + "close: jaw angle 1 s p95": 6.715402379631992, + "close: cube pos in gripper frame 1 s p95": 5.45455659739673, + "release: cube world pos 1 s p95": 10.157806146889925, + "release: cube rotation 1 s p95": 29.90021996727917, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.7734442711807785, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 2.812564324731823, + "arm_free: 5 arm joints RMS 1 s p95": 6.810661964118471, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 26.15640825204772, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.326280162653096 + }, + "1mlf": { + "headline: cube pos 1 s p95 (validation)": 11.030493723228568, + "carry: cube pos in gripper frame 1 s p95": 17.938304506242268, + "carry: cube pos in gripper frame 1 s p50": 4.744236823171377, + "carry: cube world pos 1 s p95": 18.139254860579936, + "carry: grasp point (arm) pos 1 s p95": 2.5288362056016918, + "carry: cube turn in gripper frame 1 s p95 |yaw|": 39.00727899334397, + "carry: cube rotation in gripper frame 1 s p95": 39.392104145522964, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": 41.07083674821992, + "carry: jaw angle 1 s p95": 7.15364580973982, + "close: jaw angle 1 s p95": 8.09458801522851, + "close: cube pos in gripper frame 1 s p95": 6.471920385956762, + "release: cube world pos 1 s p95": 10.58495622128248, + "release: cube rotation 1 s p95": 32.21226119944328, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": 0.771064241416752, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": 3.8585154178107506, + "arm_free: 5 arm joints RMS 1 s p95": 6.893918151035903, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": 47.58182374333005, + "rest: share of windows with > 2 mm model drift at 1 s, %": 0.440721712240376 + } + }, + "sealed_headline": { + "3t": 4.13, + "3m": 13.69, + "1tlt": 6.35, + "1mlt": 10.5, + "1m": 7.73, + "1t": 6.69, + "1tlf": 5.607, + "1mlf": 9.313 + }, + "mujoco_best": [ + 98.8, + 2.0, + 10.9, + 11.3, + 81.2, + 0.0, + 12.9, + 18.4 + ], + "mujoco_mean": [ + 98.39999999999999, + 0.6666666666666666, + 5.7, + 8.733333333333334, + 75.10000000000001, + 0.0, + 12.633333333333333, + 16.566666666666666 + ], + "correlation": { + "SEALED headline: cube pos 1 s p95 (stored result)": { + "best": { + "spearman": 0.38095238095238104, + "kendall": 0.35714285714285715 + }, + "mean": { + "spearman": 0.38095238095238104, + "kendall": 0.35714285714285715 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "headline: cube pos 1 s p95 (validation)": { + "best": { + "spearman": 0.30952380952380953, + "kendall": 0.2857142857142857 + }, + "mean": { + "spearman": 0.30952380952380953, + "kendall": 0.2857142857142857 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "carry: cube pos in gripper frame 1 s p95": { + "best": { + "spearman": 0.07142857142857144, + "kendall": 0.14285714285714285 + }, + "mean": { + "spearman": 0.07142857142857144, + "kendall": 0.14285714285714285 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "carry: cube pos in gripper frame 1 s p50": { + "best": { + "spearman": 0.07142857142857144, + "kendall": 0.14285714285714285 + }, + "mean": { + "spearman": 0.07142857142857144, + "kendall": 0.14285714285714285 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "carry: cube world pos 1 s p95": { + "best": { + "spearman": 0.3333333333333334, + "kendall": 0.2857142857142857 + }, + "mean": { + "spearman": 0.3333333333333334, + "kendall": 0.2857142857142857 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "carry: grasp point (arm) pos 1 s p95": { + "best": { + "spearman": 0.4285714285714286, + "kendall": 0.2857142857142857 + }, + "mean": { + "spearman": 0.4285714285714286, + "kendall": 0.2857142857142857 + }, + "fair4_mean_spearman": 0.39999999999999997 + }, + "carry: cube turn in gripper frame 1 s p95 |yaw|": { + "best": { + "spearman": 0.07142857142857144, + "kendall": -0.07142857142857142 + }, + "mean": { + "spearman": 0.07142857142857144, + "kendall": -0.07142857142857142 + }, + "fair4_mean_spearman": 0.19999999999999998 + }, + "carry: cube rotation in gripper frame 1 s p95": { + "best": { + "spearman": -0.07142857142857144, + "kendall": -0.14285714285714285 + }, + "mean": { + "spearman": -0.07142857142857144, + "kendall": -0.14285714285714285 + }, + "fair4_mean_spearman": 0.19999999999999998 + }, + "carry_turn: cube turn in gripper frame 1 s p95 |yaw|": { + "best": { + "spearman": 0.07142857142857144, + "kendall": -0.07142857142857142 + }, + "mean": { + "spearman": 0.07142857142857144, + "kendall": -0.07142857142857142 + }, + "fair4_mean_spearman": 0.19999999999999998 + }, + "carry: jaw angle 1 s p95": { + "best": { + "spearman": 0.2380952380952381, + "kendall": 0.07142857142857142 + }, + "mean": { + "spearman": 0.2380952380952381, + "kendall": 0.07142857142857142 + }, + "fair4_mean_spearman": 0.19999999999999998 + }, + "close: jaw angle 1 s p95": { + "best": { + "spearman": -0.09523809523809526, + "kendall": -0.21428571428571427 + }, + "mean": { + "spearman": -0.09523809523809526, + "kendall": -0.21428571428571427 + }, + "fair4_mean_spearman": 0.19999999999999998 + }, + "close: cube pos in gripper frame 1 s p95": { + "best": { + "spearman": 0.0, + "kendall": 0.07142857142857142 + }, + "mean": { + "spearman": 0.0, + "kendall": 0.07142857142857142 + }, + "fair4_mean_spearman": 0.39999999999999997 + }, + "release: cube world pos 1 s p95": { + "best": { + "spearman": 0.2142857142857143, + "kendall": 0.14285714285714285 + }, + "mean": { + "spearman": 0.2142857142857143, + "kendall": 0.14285714285714285 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "release: cube rotation 1 s p95": { + "best": { + "spearman": -0.11904761904761905, + "kendall": -0.14285714285714285 + }, + "mean": { + "spearman": -0.11904761904761905, + "kendall": -0.14285714285714285 + }, + "fair4_mean_spearman": -0.39999999999999997 + }, + "rest: cube drift 1 s p95 (model; recorded < 1 mm)": { + "best": { + "spearman": 0.11904761904761905, + "kendall": 0.07142857142857142 + }, + "mean": { + "spearman": 0.11904761904761905, + "kendall": 0.07142857142857142 + }, + "fair4_mean_spearman": 0.19999999999999998 + }, + "rest: cube turn 1 s p95 (model; recorded < 1 deg)": { + "best": { + "spearman": -0.2380952380952381, + "kendall": -0.2857142857142857 + }, + "mean": { + "spearman": -0.2380952380952381, + "kendall": -0.2857142857142857 + }, + "fair4_mean_spearman": -0.39999999999999997 + }, + "arm_free: 5 arm joints RMS 1 s p95": { + "best": { + "spearman": -0.09523809523809526, + "kendall": -0.07142857142857142 + }, + "mean": { + "spearman": -0.09523809523809526, + "kendall": -0.07142857142857142 + }, + "fair4_mean_spearman": -0.7999999999999999 + }, + "carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, %": { + "best": { + "spearman": 0.07142857142857144, + "kendall": 0.14285714285714285 + }, + "mean": { + "spearman": 0.07142857142857144, + "kendall": 0.14285714285714285 + }, + "fair4_mean_spearman": 0.7999999999999999 + }, + "rest: share of windows with > 2 mm model drift at 1 s, %": { + "best": { + "spearman": -0.2380952380952381, + "kendall": -0.2857142857142857 + }, + "mean": { + "spearman": -0.2380952380952381, + "kendall": -0.2857142857142857 + }, + "fair4_mean_spearman": 0.19999999999999998 + } + }, + "note": "Spearman / Kendall of (-metric) with MuJoCo teacher-A success over 8 NRDs: +1 = lower error, higher success" +} \ No newline at end of file diff --git a/so101_pick_place/arch_ablation/mechanism/metrics.md b/so101_pick_place/arch_ablation/mechanism/metrics.md new file mode 100644 index 0000000000000000000000000000000000000000..1c7ff080c98ea2c2d7c337d1c21ccf50c47e48db --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/metrics.md @@ -0,0 +1,25 @@ +| metric | 3t | 3m | 1tlt | 1mlt | 1m | 1t | 1tlf | 1mlf | rho best | rho mean | tau mean | +|---|---|---|---|---|---|---|---|---|---|---|---| +| MuJoCo success best seed % | 98.8 | 2.0 | 10.9 | 11.3 | 81.2 | 0.0 | 12.9 | 18.4 | | | | +| MuJoCo success mean % | 98.4 | 0.7 | 5.7 | 8.7 | 75.1 | 0.0 | 12.6 | 16.6 | | | | +| SEALED headline: cube pos 1 s p95 (stored result) | 4.13 | 13.69 | 6.35 | 10.50 | 7.73 | 6.69 | 5.61 | 9.31 | +0.38 | +0.38 | +0.36 | +| headline: cube pos 1 s p95 (validation) | 8.17 | 15.84 | 8.57 | 12.35 | 8.95 | 8.88 | 8.13 | 11.03 | +0.31 | +0.31 | +0.29 | +| carry: cube pos in gripper frame 1 s p95 | 10.63 | 23.52 | 11.52 | 21.35 | 12.19 | 6.40 | 11.08 | 17.94 | +0.07 | +0.07 | +0.14 | +| carry: cube pos in gripper frame 1 s p50 | 2.93 | 8.08 | 3.34 | 5.63 | 3.68 | 1.99 | 3.00 | 4.74 | +0.07 | +0.07 | +0.14 | +| carry: cube world pos 1 s p95 | 10.99 | 23.57 | 12.34 | 21.62 | 13.54 | 12.02 | 11.88 | 18.14 | +0.33 | +0.33 | +0.29 | +| carry: grasp point (arm) pos 1 s p95 | 2.32 | 2.55 | 2.91 | 2.60 | 7.38 | 14.49 | 2.92 | 2.53 | +0.43 | +0.43 | +0.29 | +| carry: cube turn in gripper frame 1 s p95 |yaw| | 3.53 | 5.47 | 28.51 | 33.11 | 17.83 | 18.57 | 35.98 | 39.01 | +0.07 | +0.07 | -0.07 | +| carry: cube rotation in gripper frame 1 s p95 | 3.83 | 5.99 | 28.59 | 33.75 | 20.07 | 19.54 | 36.03 | 39.39 | -0.07 | -0.07 | -0.14 | +| carry_turn: cube turn in gripper frame 1 s p95 |yaw| | 3.86 | 5.82 | 30.25 | 35.25 | 18.91 | 19.82 | 37.88 | 41.07 | +0.07 | +0.07 | -0.07 | +| carry: jaw angle 1 s p95 | 1.50 | 2.88 | 5.30 | 11.77 | 1.61 | 2.56 | 5.78 | 7.15 | +0.24 | +0.24 | +0.07 | +| close: jaw angle 1 s p95 | 1.27 | 2.79 | 5.20 | 5.75 | 12.46 | 7.31 | 6.72 | 8.09 | -0.10 | -0.10 | -0.21 | +| close: cube pos in gripper frame 1 s p95 | 6.16 | 7.72 | 5.96 | 6.53 | 5.25 | 4.17 | 5.45 | 6.47 | +0.00 | +0.00 | +0.07 | +| release: cube world pos 1 s p95 | 10.16 | 10.63 | 10.26 | 10.45 | 9.86 | 10.15 | 10.16 | 10.58 | +0.21 | +0.21 | +0.14 | +| release: cube rotation 1 s p95 | 8.21 | 7.89 | 25.66 | 26.40 | 27.51 | 29.32 | 29.90 | 32.21 | -0.12 | -0.12 | -0.14 | +| rest: cube drift 1 s p95 (model; recorded < 1 mm) | 0.09 | 0.10 | 0.59 | 0.82 | 0.99 | 0.82 | 0.77 | 0.77 | +0.12 | +0.12 | +0.07 | +| rest: cube turn 1 s p95 (model; recorded < 1 deg) | 0.34 | 0.14 | 2.25 | 2.49 | 4.48 | 2.99 | 2.81 | 3.86 | -0.24 | -0.24 | -0.29 | +| arm_free: 5 arm joints RMS 1 s p95 | 7.09 | 6.86 | 6.85 | 6.98 | 35.51 | 407.05 | 6.81 | 6.89 | -0.10 | -0.10 | -0.07 | +| carry: share of windows with > 5 mm cube shift in gripper frame at 1 s, % | 25.96 | 70.99 | 31.05 | 55.83 | 33.76 | 9.41 | 26.16 | 47.58 | +0.07 | +0.07 | +0.14 | +| rest: share of windows with > 2 mm model drift at 1 s, % | 0.02 | 0.05 | 0.18 | 0.43 | 0.75 | 0.31 | 0.33 | 0.44 | -0.24 | -0.24 | -0.29 | + +Window counts: {"carry": 29423, "carry_turn": 22258, "close": 2899, "release": 1455, "rest": 41069, "arm_free": 41267, "headline": 28822} diff --git a/so101_pick_place/arch_ablation/mechanism/scripts/analyze.py b/so101_pick_place/arch_ablation/mechanism/scripts/analyze.py new file mode 100644 index 0000000000000000000000000000000000000000..9865163e72728d7b35d943f9f9806569d61e8e07 --- /dev/null +++ b/so101_pick_place/arch_ablation/mechanism/scripts/analyze.py @@ -0,0 +1,170 @@ +"""Window classes, error components and rank correlations with teacher-A MuJoCo success (validation windows only). + +Reads out/windows_