reneeice's picture
full research archive: code, models, datasets, experiments, logs
152228b verified
Raw History Blame Contribute Delete
3.95 kB
"""Post-deploy era analysis: per-task submitted strategy, all candidates (closeness),
settled uid64/top comparison from lb_real. Usage: python3 scripts/era_analysis.py [era_marker]"""
from __future__ import annotations
import sys, json, re, statistics as st
from collections import defaultdict
LOG = "/root/miner_live.log"
marker = sys.argv[1] if len(sys.argv) > 1 else "ERA revert_gridslice"
lines = open(LOG, errors="ignore").read().splitlines()
start = next((i for i, l in enumerate(lines) if marker in l), None)
if start is None:
print("era marker not found"); sys.exit(1)
# parse tasks: candidates + final strategy
tasks = {} # task_id -> dict(row, cands=[(name,score,margin,rmse)], final=(name,score,margin))
tid_re = re.compile(r"task=(\S+)")
for l in lines[start:]:
tid_m = tid_re.search(l)
if not tid_m:
continue
tid = tid_m.group(1)
t = tasks.setdefault(tid, {"cands": [], "final": None})
t["row"] = int(tid.split("-")[-1])
m = re.search(r"candidate (\S+) score=([0-9.]+) margin=([0-9.e+-]+) rmse=([0-9.]+)", l)
if m:
t["cands"].append((m.group(1), float(m.group(2)), float(m.group(3)), float(m.group(4))))
continue
m = re.search(r"strategy=(\S+) true_idx=\d+ score=([0-9.]+) reason=success .*rmse=([0-9.]+) margin=([0-9.e+-]+)", l)
if m:
t["final"] = (m.group(1), float(m.group(2)), float(m.group(4)))
# lb_real lookups: row -> (uid64, top, our_settled)
lb = {}
for line in open("/root/lb_real/lb_real.jsonl", errors="ignore"):
line = line.strip()
if not line:
continue
d = json.loads(line)
r = d.get("row")
best = 0.0; u64 = None; ours = None
for mmm in d.get("miners", []):
if isinstance(mmm, dict) and mmm.get("result") == "Valid":
s = float(mmm.get("lastScore", 0.0))
best = max(best, s)
if mmm.get("uid") == "64":
u64 = s
if mmm.get("uid") == "137":
ours = s
lb[r] = (u64, best, ours)
done = [(tid, t) for tid, t in sorted(tasks.items(), key=lambda kv: kv[1]["row"]) if t["final"]]
print(f"{'row':<8}{'strategy':<18}{'score':<8}{'marg':<7}{'rmse':<9}{'runner-up':<16}{'gap2up':<8}{'u64':<8}{'d64':<8}{'top':<8}{'dtop':<8}")
strat_wins = defaultdict(lambda: [0, 0.0])
gaps64, gapstop, gaps_up = [], [], []
settled_n = 0
for tid, t in done:
name, sc, mg = t["final"]
rm = next((c[3] for c in t["cands"] if c[0] == name), float("nan"))
others = sorted([c for c in t["cands"] if c[0] != name], key=lambda c: -c[1])
up = others[0] if others else None
u64, top, ours = lb.get(t["row"], (None, None, None))
strat_wins[name][0] += 1; strat_wins[name][1] += sc
if up:
gaps_up.append(sc - up[1])
row_s = f"{t['row']:<8}{name:<18}{sc:<8.4f}{mg:<7.2f}{rm:<9.5f}"
row_s += f"{(up[0] if up else '-'):<16}{(f'{sc-up[1]:.4f}' if up else '-'):<8}"
if u64:
gaps64.append(sc - u64); gapstop.append(sc - top); settled_n += 1
row_s += f"{u64:<8.4f}{sc-u64:<+8.4f}{top:<8.4f}{sc-top:<+8.4f}"
print(row_s)
print(f"\ntasks submitted: {len(done)} | settled in tracker: {settled_n}")
print("strategy win counts:")
for k, (n, s) in sorted(strat_wins.items(), key=lambda kv: -kv[1][0]):
print(f" {k:<18} n={n:<3} mean={s/n:.4f}")
if gaps_up:
print(f"\nrunner-up gap: mean={st.mean(gaps_up):+.4f} median={st.median(gaps_up):+.4f} "
f"close(<0.002)={sum(1 for g in gaps_up if g < 0.002)}/{len(gaps_up)}")
if gaps64:
print(f"vs UID64: mean={st.mean(gaps64):+.4f} | we beat 64 on {sum(1 for g in gaps64 if g>0)}/{len(gaps64)}")
print(f"vs TOP: mean={st.mean(gapstop):+.4f} | we topped on {sum(1 for g in gapstop if g>0)}/{len(gapstop)}")
# overshoot stats
overs = [t["final"][2] for _, t in done if t["final"] and t["final"][2] > 10.5]
print(f"margin overshoot (>10.5): {len(overs)}/{len(done)} mean={st.mean(overs) if overs else 0:.2f}")
print("ERA_ANALYSIS_DONE")