Files

40 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Window width and acceptance per arm of a draftround-ab.sh series: mean verified rows per round (round.T), mean accepted drafts per round (round.acc), drafts per
round (mtp.chain_step calls + 1 round graph = steps) from the 'DBG profile request:' lines; block-paired b - a.
python3 -I draftround-width.py <outroot>
"""
import glob, os, re, statistics, sys
def stats(d):
rounds = T = acc = steps = 0
cur = None
for ln in open(os.path.join(d, "inference.log"), errors="replace"):
if ln.startswith("DBG profile request:"):
cur = {m[0]: (float(m[1]), int(m[2])) for m in re.findall(r"(\S+?)=([\d.]+)/(\d+)", ln)}
elif "leleka-serve request outcome" in ln and cur:
r = int(re.search(r"rounds=(\d+)", ln).group(1))
rounds += r
T += cur.get("round.T", (0, 0))[0]
acc += cur.get("round.acc", (0, 0))[0]
steps += cur.get("mtp.chain_step", (0, 0))[1]
cur = None
return rounds, T / rounds, acc / rounds, steps / rounds
root = sys.argv[1]
by = {}
for d in sorted(glob.glob(os.path.join(root, "b*p*-*"))):
m = re.match(r"b(\d+)p(\d+)-([ab])", os.path.basename(d))
if not m or not os.path.exists(os.path.join(d, "VALIDITY.txt")) or not open(os.path.join(d, "VALIDITY.txt")).read().startswith("VALID"):
continue
by.setdefault(int(m.group(1)), {})[m.group(3)] = stats(d)
print("block arm rounds rows/round accepted/round chain steps/round")
for b, v in sorted(by.items()):
for arm in "ab":
if arm in v:
print("%5d %s %6d %10.3f %14.3f %17.3f" % (b, arm, *v[arm]))
pairs = [(v["a"], v["b"]) for v in by.values() if "a" in v and "b" in v]
for i, name in ((1, "rows/round"), (2, "accepted/round"), (3, "chain steps/round")):
d = [pb[i] - pa[i] for pa, pb in pairs]
print("b - a %-18s per block %s mean %+.3f (se %.3f)" % (name, " ".join("%+.3f" % x for x in d), statistics.mean(d), statistics.stdev(d) / len(d) ** 0.5))