File size: 3,855 Bytes
4ef198a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""build_dataset.py: raw run directories -> the per-trial JSONL tables of the HF dataset (data/*.jsonl).

  python3 build_dataset.py --out hf-dataset/data \
     --t1 repro:H-t1a:raw/t1a/<label> --t1 repro:H-t1b:raw/t1b/<label> \
     --t1 original:T1-A-full:<unpacked original A-full> ... \
     --fork repro:H-fork:raw/fork/out/B/raw --fork original:T2b-main:<t2b main raw> ...

Tables (one JSON object per line, every field copied from the raw rows, nothing recomputed except where named):
  t1_rollouts.jsonl  one row per rollout of the T1 bench (every pass, every rung, every arm)
  fork_ops.jsonl     one row per fork / reset operation of the T2b bench (W1p, W1)
"""
import argparse, glob, json, os

T1_FIELDS = ["rollout_id", "arm", "n", "slot", "task", "policy", "rep", "useful", "valid", "correct", "score",
             "failure_reason", "terminated_by", "reset_s", "gate_s", "setup_s", "act_s", "eval_s", "env_held_s", "t_start", "t_end"]


def t1_rows(source, host, raw):
    for d in sorted(glob.glob(os.path.join(raw, "p[12]-*", "rung-n*"))):
        pass_, arm = os.path.basename(os.path.dirname(d)).split("-", 1)
        if ".aborted-" in arm:
            arm, attempt = arm.split(".aborted-", 1)[0], "aborted"
        else:
            attempt = "final"
        p = os.path.join(d, "rollouts.jsonl")
        if not os.path.exists(p):
            continue
        for line in open(p):
            if not line.strip():
                continue
            r = json.loads(line)
            row = {"source": source, "host": host, "pass": pass_, "attempt": attempt, "rung_n": int(os.path.basename(d)[6:])}
            row.update({k: r.get(k) for k in T1_FIELDS})
            row["arm"] = r.get("arm") or arm
            yield row


def fork_rows(source, host, raw):
    for p in sorted(glob.glob(os.path.join(raw, "*-w1*.jsonl"))):
        label, workload = os.path.basename(p)[:-6].rsplit("-", 1)
        for line in open(p):
            r = json.loads(line)
            if r.get("kind") not in ("fork", "reset"):
                continue
            pf = ((r.get("server") or {}).get("prefork") or {})
            v = r.get("validity") or []
            yield {"source": source, "host": host, "label": label, "workload": workload, "kind": r["kind"],
                   "i": r.get("i", r.get("j")), "copies": r.get("n"), "wall_s": r.get("wall_s"), "error": r.get("error"),
                   "children_valid": sum(1 for x in v if x.get("valid")) if r["kind"] == "fork" else None,
                   "children_invalid": sum(1 for x in v if not x.get("valid")) if r["kind"] == "fork" else None,
                   "reset_valid": r.get("valid") if r["kind"] == "reset" else None,
                   "prefork_claimed": pf.get("claimed") if workload == "w1p" else None,
                   "prefork_waited_s": pf.get("waited_s"), "prefork_hash_check_s": pf.get("hash_check_s"),
                   "prefork_prepare_s": pf.get("prepare_seconds"),
                   "capture_s": (r.get("server") or {}).get("capture_s"), "children_ready_s": (r.get("server") or {}).get("children_ready_s"),
                   "epoch": r.get("epoch")}


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--out", required=True)
    ap.add_argument("--t1", action="append", default=[])
    ap.add_argument("--fork", action="append", default=[])
    a = ap.parse_args()
    os.makedirs(a.out, exist_ok=True)
    for name, specs, fn in (("t1_rollouts.jsonl", a.t1, t1_rows), ("fork_ops.jsonl", a.fork, fork_rows)):
        n = 0
        with open(os.path.join(a.out, name), "w") as f:
            for s in specs:
                source, host, raw = s.split(":", 2)
                for row in fn(source, host, raw):
                    f.write(json.dumps(row, sort_keys=True) + "\n"); n += 1
        print(name, n)


if __name__ == "__main__":
    main()