"""Generate the appendix tables of the paper from frame_board_paper_20261016/numbers/paper_numbers.json. Writes where_the_frame_goes_board_20261016/src/17_appendix_tables.tex (machine-generated; do not edit). """ import json from pathlib import Path AF = Path(__file__).resolve().parents[2] N = json.loads((AF / 'frame_board_paper_20261016/numbers/paper_numbers.json').read_text()) OUT = AF / 'where_the_frame_goes_board_20261016/src/17_appendix_tables.tex' def tex(s): return s.replace('_', '\\_') def fmt(x): return f'{x:,}'.replace(',', '{,}') if isinstance(x, int) else str(x) lines = ['% Machine-generated by scripts/project/gen_appendix_tables.py from paper_numbers.json.', '\\section{The forty P1 loops}\\label{app:loops}', 'Board ticks are the reviewed P1 readings (B23 has two readings three ticks apart). Instruction-table ticks are ' 'the cycles FBNeo\'s cost table charges for the same instruction trace, divided by eight. Model ticks are the current ' 'model on the same bodies. $N$ is the iteration count; the body of each loop and its access trace are in the companion ' 'data (\\file{benchmark_contracts.json}).', '\\begingroup\\footnotesize\\renewcommand{\\arraystretch}{1.0}', '\\begin{longtable}{@{}l l r r r r r r@{}}', '\\toprule ID & Loop & $N$ & Board & Table & Board/table & Model & Model error \\\\ \\midrule\\endfirsthead', '\\toprule ID & Loop & $N$ & Board & Table & Board/table & Model & Model error \\\\ \\midrule\\endhead'] for r in N['p1_loops']['rows']: lines.append(f"{r['id']} & \\texttt{{{tex(r['name'])}}} & {fmt(r['N'])} & {r['board_ticks']} & {r['legacy_ticks']} & " f"{r['board_over_legacy']:.2f} & {r['model_ticks']} & {r['model_error_pct']:+.2f}\\% \\\\") s = N['p1_loops'] lines += ['\\bottomrule', f"\\caption{{P1 loop totals in FRT ticks (\\textsc{{board model}}). Model \\hex{{20261017}}: " f"{s['within_1pct']} of 40 within 1\\%, median absolute error {s['median_abs_pct']:.2f}\\%, worst {s['max_abs_pct']:.2f}\\%.}}", '\\end{longtable}\\endgroup', '', '\\section{P2 loop groups}\\label{app:p2}', 'Warm medians of the 185 P2 CPU loops against two versions of the model. Build 12 was calibrated on P1 alone; ' '\\hex{20261017} was fitted to these data. Every loop\'s eight raw samples are in the companion data.', '\\begingroup\\setlength{\\intextsep}{2pt}\\begin{table}[H]\\centering\\footnotesize\\renewcommand{\\arraystretch}{1.0}', '\\begin{tabular}{@{}l r r r r r@{}}', '\\toprule & & \\multicolumn{2}{c}{within 1\\%} & \\multicolumn{2}{c}{median $|$error$|$, \\%} \\\\', 'Group & Loops & build 12 & \\hex{20261017} & build 12 & \\hex{20261017} \\\\ \\midrule'] order = ['p1_bridge', 'cache_conflict', 'instruction_capacity', 'load_dependency', 'multiply', 'write_read_handoff', 'copy', 'ram_spacing', 'spacing_control', 'frt_phase'] G = N['p2_groups']['groups'] for g in order: v = G[g] lines.append(f"{tex(g).replace('\\_', ' ')} & {v['n']} & {v['b12_within1']} & {v['m26_within1']} & {v['b12_median_abs']:.2f} & {v['m26_median_abs']:.2f} \\\\") S = N['p2_groups']['summary'] worst = max(N['p2_groups']['residuals'], key=lambda r: abs(r['err'])) lines += ['\\midrule', f"all & 185 & {N['p2_groups']['b12_within1']} & {S['within_one_percent']} & {N['p2_groups']['b12_median_abs']:.2f} & {S['median_absolute_pct']:.2f} \\\\", '\\bottomrule\\end{tabular}', f"\\caption{{P2 loop groups (\\textsc{{board model}}). Worst single loop: build 12 $-31.5\\%$ (a long multiply whose result is used), " f"\\hex{{20261017}} ${worst['err']:+.1f}\\%$ (\\texttt{{{tex(worst['name'])}}}).}}\\label{{tab:p2groups}}", '\\end{table}\\endgroup', ''] OUT.write_text('\n'.join(lines) + '\n', encoding='utf-8') print('wrote', OUT)