"""Pick best LR per rank on test[0:200] (tie -> lower LR); freeze the choice to ev/selection.json before confirmation.""" import json, glob, hashlib, time, os GRID = {1: ["1e-4", "3e-4", "1e-3"], 32: ["1e-4", "3e-4", "1e-3"]} EXT = {"low": "3e-5", "high": "3e-3"} sel = {"rule": "argmax test[0:200] greedy accuracy per rank; ties -> lower LR; grid edge -> extend once with 3e-5/3e-3 if feasible", "frozen_before_confirmation": True, "ranks": {}} eids = set() for rank in (1, 32): cands = [] for lr in GRID[rank] + list(EXT.values()): f = f"ev/score_selection_rank{rank}_lr{lr}.json" if os.path.exists(f): s = json.load(open(f)); cands.append((float(lr), lr, s["accuracy"], s["evaluator_id"])); eids.add(s["evaluator_id"]) cands.sort() best = max(cands, key=lambda c: (c[2], -c[0])) lrs = [c[0] for c in cands] edge = best[0] in (min(lrs), max(lrs)) sel["ranks"][str(rank)] = {"candidates": {c[1]: c[2] for c in cands}, "selected_lr": best[1], "selected_arm": f"rank{rank}_lr{best[1]}", "selected_accuracy": best[2], "grid_edge": edge} assert len(eids) == 1, eids sel["selection_evaluator_id"] = eids.pop() sel["frozen_at_unix"] = time.time() out = json.dumps(sel, indent=1, sort_keys=True) name = os.environ.get("SEL_OUT", "ev/selection.json") open(name, "w").write(out) print(out); print("sha256", hashlib.sha256(out.encode()).hexdigest())