Files
sim-numerics/numbers_for_article.py
T

73 lines
3.1 KiB
Python

"""The exact numbers the new sections of the paper must quote, printed from the sweep files.
Nothing here is typed by hand into the paper: verify_article.py re-checks every one of them.
python -u numbers_for_article.py
"""
from __future__ import annotations
import json
import os
FILES = {"published": "sweep_full.json", "slope": "sweep_slope.json",
"shape": "sweep_points.json", "dissimilar": "sweep_direction.json",
"combo": "sweep_combo.json", "progress": "sweep_gate.json",
"logspace": "sweep_log.json"}
GUARANTEE = ("credit", "project", "safe")
def load(path):
if not os.path.exists(path):
return None
with open(path, encoding="utf8") as fh:
return json.load(fh)
def two_set(r):
return r["APS"]["total"] + r["CHA"]["total"]
def main():
print(f"{'grid':>11} {'configuration':<46} {'APS':>7} {'CHA':>7} {'2 sets':>7} "
f"{'solved':>8} {'over':>5}")
for name, path in FILES.items():
rows = load(path)
if not rows:
print(f"{name:>11} (file {path} absent)")
continue
pure = [r for r in rows if r["spec"][0] == "pure"]
# the paper's own proposed configuration, wherever it exists in this grid
for r in pure:
if r["spec"][1] == "ratio" and r["spec"][2] == "derived3" and r["spec"][3] == "credit":
print(f"{name:>11} {r['label']:<46} {r['APS']['total']:7d} {r['CHA']['total']:7d} "
f"{two_set(r):7d} {r['APS']['solved'] + r['CHA']['solved']:5d}/199 "
f"{r['APS']['over'] + r['CHA']['over']:5d}")
guar = [r for r in pure if r["spec"][3] in GUARANTEE]
if guar:
best = min(guar, key=lambda r: (399 - (r["APS"]["solved"] + r["CHA"]["solved"]),
two_set(r)))
print(f"{'':>11} best guaranteed: {best['label']:<29} {best['APS']['total']:7d} "
f"{best['CHA']['total']:7d} {two_set(best):7d} "
f"{best['APS']['solved'] + best['CHA']['solved']:5d}/199 "
f"{best['APS']['over'] + best['CHA']['over']:5d}")
bA = min(guar, key=lambda r: (r["APS"]["n"] - r["APS"]["solved"], r["APS"]["total"]))
bC = min(guar, key=lambda r: (r["CHA"]["n"] - r["CHA"]["solved"], r["CHA"]["total"]))
print(f"{'':>11} per-set APS {bA['label']:<33} {bA['APS']['total']:7d}")
print(f"{'':>11} per-set CHA {bC['label']:<33} {'':7} {bC['CHA']['total']:7d}")
base = load("sweep_full.json")
if base:
print("\nbaselines (from the published sweep):")
for nm in ("chandrupatla", "toms748", "brent", "itp", "itp_oracle", "bisection"):
cand = [r for r in base if r["spec"][0] == "base" and r["label"] == nm]
if cand:
r = cand[0]
print(f"{'':>11} {nm:<46} {r['APS']['total']:7d} {r['CHA']['total']:7d} "
f"{two_set(r):7d} {r['APS']['solved'] + r['CHA']['solved']:5d}/199 "
f"{r['APS']['over'] + r['CHA']['over']:5d}")
if __name__ == "__main__":
main()