"""Chooses B1 and B2 (amendment 3.2 C6 as amended by 3.4 E4) from validation scores and writes selection.json. usage: python -I select_b1b2.py --scores DATA/outputs/r5/scores --out DATA/outputs/r5/selection.json [--preds DATA/outputs/r5/preds] [--arms-info arms_info.json] [--models-tsv a.tsv,b.tsv] [--vlm-arms x,y] [--line-checkpoint auto] [--allow-short-b1] arms_info.json: {"": {"unique_params_b": 0.96, "final_checkpoint": "leader", "flags": ["short of P"]}, ...}; keys that start with an underscore are comments. B1 and B2 are chosen among the FINAL checkpoints at leader length (more samples than P_short, read from meta.json samples_seen; the six runs of 3.4 E2). An arm left at P_short can not become B1; it can be B2 only when no arm of another size class reached leader length. Seed means are used for arms with two seeds. --allow-short-b1 is a provisional dry run (arms at P_short compete; the output says 'provisional'). Line arms (amendment 3.4 E5, clarification J1): each line role carries TWO checkpoints. checkpoint = section 3 (A2 against A1, A3, A4, A1s): the P_long checkpoint, arms_info final_checkpoint else 'long', two seeds for A1 and A2; section4_checkpoint = section 4 and the H10 block: arms_info section4_checkpoint ('auto' = long2x if it has a complete V1 score, else long), seed 1 only at long2x (G1). The samples of both are read from meta.json. Options: [--section4-checkpoint auto]. Reads only score files of validation sets and meta.json files. Run it before the test pass, then hash the output; verdict.py reads it and never changes it. """ import argparse import hashlib import json import os import sys import time HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.normpath(os.path.join(HERE, "..", "..", "src"))) def main(): ap = argparse.ArgumentParser() ap.add_argument("--scores", required=True) ap.add_argument("--out", required=True) ap.add_argument("--preds", default=None, help="DATA/outputs/r5/preds: meta.json of each checkpoint (samples_seen); else the meta named in the score file") ap.add_argument("--arms-info", default=None) ap.add_argument("--line-checkpoint", default="auto", help="checkpoint of the line arms for SECTION 3 (J1): auto = arms_info final_checkpoint, else long (P_long)") ap.add_argument("--section4-checkpoint", default="auto", help="checkpoint of the line arms for SECTION 4 and the H10 block (J1): auto = long2x if it has a complete V1 score, else long") ap.add_argument("--models-tsv", default=None, help="models tables of the VLM arms (comma list): their arms are the VLM allow-list and give the unique parameters") ap.add_argument("--vlm-arms", default="", help="comma list of further VLM arm names") ap.add_argument("--allow-short-b1", action="store_true", help="provisional dry run: arms at P_short may compete (not the rule of amendment 3.4 E4)") a = ap.parse_args() from r5eval import selection info = selection.clean_arms_info(json.load(open(a.arms_info, encoding="utf-8")) if a.arms_info else {}) params = selection.read_params(a.models_tsv) selection.fill_params(info, params) # unique parameters from the models tables unless arms_info gives them (B2 needs the size class of B1) allow = set(params) | {x for x in a.vlm_arms.split(",") if x} res = selection.select(a.scores, info, a.line_checkpoint, vlm_allow=allow or None, preds_dir=a.preds, strict_final=not a.allow_short_b1, section4_checkpoint=a.section4_checkpoint) res["generated_utc"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) res["arms_info_sha256"] = hashlib.sha256(open(a.arms_info, "rb").read()).hexdigest() if a.arms_info else None with open(a.out, "w", encoding="utf-8") as f: json.dump(res, f, ensure_ascii=False, indent=1) with open(a.out + ".sha256", "w") as f: f.write("%s %s %s\n" % (hashlib.sha256(open(a.out, "rb").read()).hexdigest(), os.path.basename(a.out), res["generated_utc"])) print("B1:", res["B1"], "-", res["B1_reason"]) print("B2:", res["B2"], "-", res["B2_reason"]) for w in res["warnings"] + res["decisions_needed"]: print("NOTE:", w) if __name__ == "__main__": main()