# MIT License, Bryan Cheng, 2026. One-off edit (D-038 follow-up): hardware-configuration centering in crosses.py. p = "src/analysis/crosses.py" s = open(p).read() s = s.replace(''' deg = np.array([r.get("ppl_ratio", 1.0) > 3 for r in recs]) return D, A, Y, deg ''', ''' deg = np.array([r.get("ppl_ratio", 1.0) > 3 for r in recs]) hw = np.array([f"{r.get('gpu', '?')}|{r.get('bs', '?')}" for r in recs]) return D, A, Y, deg, hw def hw_center(Y, hw, rows): """Offspring are measured on several GPU models / batch sizes (D-035, D-038). Parents are assigned at random, so hardware is independent of genotype; each hardware group is shifted to the overall mean, with group and overall means estimated on `rows` only (training rows in analyze, so held-out offspring do not inform the adjustment).""" out = Y.copy() groups = np.unique(hw) if len(groups) < 2: return out with np.errstate(all="ignore"): mu = np.nanmean(Y[:, rows], 1) for g in groups: gm = hw == g if (gm & rows).sum() == 0: continue out[:, gm] = Y[:, gm] - np.nanmean(Y[:, gm & rows], 1)[:, None] + mu[:, None] return out ''') s = s.replace(''' D, A, Y, deg = load_offspring(a.design, P, prim) npar, S = len(D["parents"]), A.shape[1] ref = D["parents"].index("__base__") keep = ~deg ''', ''' D, A, Y, deg, hw = load_offspring(a.design, P, prim) npar, S = len(D["parents"]), A.shape[1] ref = D["parents"].index("__base__") keep = ~deg hw_groups = {g: int((hw[keep] == g).sum()) for g in np.unique(hw[keep])} ''') s = s.replace(''' if a.cmd == "layers": var = np.zeros(S)''', ''' if a.cmd == "layers": Y = hw_center(Y, hw, keep) var = np.zeros(S)''') s = s.replace(''' te[rng.permutation(n)[: n // 5]] = True ''', ''' te[rng.permutation(n)[: n // 5]] = True train_full = keep.copy() train_full[keep] = ~te Y = hw_center(Y, hw, train_full) ''') s = s.replace('''"resolution": D.get("resolution"), "traits": {}}''', '''"resolution": D.get("resolution"), "hardware_groups": hw_groups, "traits": {}}''') assert s.count("hw_center(Y, hw") == 3 and '"hardware_groups": hw_groups' in s and "D, A, Y, deg, hw = load_offspring" in s open(p, "w").write(s) print("crosses hw ok")