okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
28ce98bf1
main
1"""merge_dumps.py - add STRATA_ACT_DUMP files (int64 n, int64 count, double sum x^2 [n]) of several runs into one directory, and 2print the per-layer summary. 3 4python3 tools/trellis/merge_dumps.py OUT_DIR IN_DIR [IN_DIR ...] 5""" 6import pathlib 7import sys 8 9import numpy as np 10 11out = pathlib .Path (sys .argv [1 ]) 12out .mkdir (parents = True ,exist_ok = True ) 13names = sorted ({p .name for d in sys .argv [2 :]for p in pathlib .Path (d ).glob ("act_L*_*.bin" )if p .name .startswith ("act_L" )and p .stat ().st_size < 400_000_000 }) 14for name in names : 15tot ,cnt ,n0 ,cov = None ,0 ,None ,None 16for d in sys .argv [2 :]: 17p = pathlib .Path (d )/ name 18if not p .exists (): 19continue 20raw = p .read_bytes () 21n ,c = np .frombuffer (raw [:16 ],dtype = np .int64 ) 22sq = np .frombuffer (raw [16 :16 + 8 * n ],dtype = np .float64 ) 23tot = sq .copy ()if tot is None else tot + sq 24if len (raw )>= 16 + 8 * n + 8 * n * n : 25cv = np .frombuffer (raw [16 + 8 * n :16 + 8 * n + 8 * n * n ],dtype = np .float64 ) 26cov = cv .copy ()if cov is None else cov + cv 27cnt += int (c ) 28n0 = int (n ) 29 (out / name ).write_bytes (np .array ([n0 ,cnt ],dtype = np .int64 ).tobytes ()+ tot .astype (np .float64 ).tobytes () 30+ (cov .tobytes ()if cov is not None else b"" )) 31m = tot / cnt 32"%-16s n %d count %d mean E[x^2] %.4g cv over channels %.3f max/mean %.1f" % (name ,n0 ,cnt ,m .mean (),m .std ()/ m .mean (),m .max ()/ m .mean ()))