File size: 1,737 Bytes
d980d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
"""Regenerate the manuscript's table fragments from the main verification ledger."""
from pathlib import Path
import json
ROOT=Path(__file__).resolve().parents[1]

def table(header: str, rows: list[str], columns: str) -> str:
    return ('\\begin{center}\n\\begin{tabular}{@{}'+columns+'@{}}\n'
            '\\toprule\n'+header+' \\\\\n\\midrule\n'+''.join(rows)+
            '\\bottomrule\n\\end{tabular}\n\\end{center}\n')

def main():
    d=json.loads((ROOT/'results'/'verification.json').read_text(encoding='utf-8'))
    out=ROOT/'source';out.mkdir(exist_ok=True)
    rows=[]
    for r in d['dose_table']:
        if r['q']==.5 and r['m'] in [2,3,4,8,16,32,64]:
            rows.append(f"{r['m']} & {r['action']:.6f} & {r['total_action']:.6f} & {r['ratio']:.9f} \\\\\n")
    (out/'dose_table.tex').write_text(table(
        r'$m$ & Per-gate action $u_m(1/2)$ & Total $U_m(1/2)$ & $U_m/m^3$',rows,'rrrr'))
    rows=[f"{r['action']:.3f} & {r['passes']:,} & {r['factor_gates']:,} & {r['error']:.6f} & {r['bound']:.6f} \\\\\n"
          for r in d['hazard_examples']]
    (out/'hazard_table.tex').write_text(table(
        r'$a$ & Passes & Patterned gates & Grid sup error & Global upper bound',rows,'rrrrr'))
    rows=[]
    for r in d['diffusion_examples']:
        if r['m'] in [4,6] and r['diffusion'] in [0.,.0001,.001]:
            rows.append(f"{r['m']} & {r['diffusion']:g} & {r['max_dark']:.6f} & {r['min_bright']:.6f} & {r['max_dark_bound']:.6f} \\\\\n")
    (out/'diffusion_table.tex').write_text(table(
        r'$m$ & $D_\theta$ & Maximum node fraction & Minimum midpoint fraction & Node upper bound',rows,'rrrrr'))
    print('Three table fragments regenerated.')

if __name__=='__main__':
    main()