"""Generate manuscript tables and figures directly from released raw summaries.""" from pathlib import Path import json import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt ROOT=Path(__file__).resolve().parents[1];M=ROOT/'manuscript';F=M/'figures';F.mkdir(exist_ok=True) def read(name):return json.loads((ROOT/'results'/name).read_text()) h=read('heredity_summary.json') fig,ax=plt.subplots(figsize=(7.2,3.6)) labels=['Literal programs','Hereditary classes','Current signature classes'] values=[h['literal_programs'],h['hereditary_classes'],h['static_evaluation_classes']] bars=ax.barh(labels,values) for b,n in zip(bars,values):ax.text(n+1200,b.get_y()+b.get_height()/2,f'{n:,}',va='center',fontsize=11) ax.set_xlim(0,98000);ax.set_xlabel('Number of distinguishable classes under each contract') ax.invert_yaxis();ax.spines[['top','right']].set_visible(False);fig.tight_layout();fig.savefig(F/'v4_catalog.pdf');plt.close(fig) c=read('corridor_summary.json')['aggregates'];labels={'raw':'Raw simulation','selfloop_skip':'Self-loop skipping','compiled':'Compiled exit'} rows=[] for key in ['raw','selfloop_skip','compiled']: x=c[key];rows.append(f"{labels[key]} & {x['setup_cpu']:.6f} & {x['execution_cpu']:.6f} & {x['total_cpu']:.6f} & {x['random_draws']:,} \\\\") (M/'tables_v4_corridor.tex').write_text(r'''\begin{table}[htbp]\centering\small \begin{tabular}{lrrrr}\toprule Method & Setup CPU & Execution CPU & Total CPU & Draws\\\midrule '''+ '\n'.join(rows)+r''' \bottomrule\end{tabular} \caption{Cold-per-batch corridor comparison. CPU values are seconds summed over the same 12,288 completed episodes per method. Setup is charged in every batch.} \end{table} ''') r=read('reinvestment_summary.json')['aggregate'];rows=[] for key in ['raw','selfloop_skip','compiled']: x=r[key];rows.append(f"{labels[key]} & {x['mean_candidates']:,.1f} & {x['mean_best_utility']:.9f} & {x['mean_regret']:.7f} \\\\") (M/'tables_v4_reinvestment.tex').write_text(r'''\begin{table}[htbp]\centering\small \begin{tabular}{lrrr}\toprule Method & Mean candidates & Mean best utility & Mean regret\\\midrule '''+ '\n'.join(rows)+r''' \bottomrule\end{tabular} \caption{Setup-paid synthetic search: 20 seeds and 0.08 CPU seconds per method and seed. Regret is measured against the unit upper bound, not a proved attained optimum.} \end{table} ''') print('Generated one plot and two tables from recorded JSON.')