#!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Per-class table from meter logs, by the pre-registered statistic (mean of per-pass differences of medians, SE across passes), plus a sensitivity column that was NOT pre-registered: the same with a 10%-trimmed mean inside each point, which keeps sub-quantum information a median of 10 mW-quantised samples throws away. Passes flagged in the log are dropped. python3 -I power_tables.py a.dat b.dat ... """ import statistics as st, sys, re def trimmed(xs, f=0.1): s = sorted(xs); k = int(len(s) * f) s = s[k:len(s) - k] if k else s return sum(s) / len(s) for path in sys.argv[1:]: pts, flagged = {}, set() for line in open(path): m = re.search(r'pass=(\d+)', line) if line.startswith('#'): if m and ('FLAGGED' in line or 'FOREIGN-LOAD' in line or 'NOT-OURS' in line): flagged.add(int(m.group(1))) continue f = line.split() if len(f) >= 4 and f[0].isdigit() and f[3].isdigit(): pts.setdefault((int(f[0]), f[1]), []).append(int(f[3]) / 1000.0) passes = sorted({p for p, _ in pts} - flagged) dm = [st.median(pts[(p, 'run')]) - st.median(pts[(p, 'halt')]) for p in passes] dt = [trimmed(pts[(p, 'run')]) - trimmed(pts[(p, 'halt')]) for p in passes] n = len(passes) fmt = lambda d: f"{st.mean(d):7.1f} +/- {st.stdev(d) / n ** 0.5:4.1f}" pr = st.mean(st.median(pts[(p, 'run')]) for p in passes) print(f"{path.split('/')[-1]:24s} passes {n:2d} medians {fmt(dm)} mW trimmed {fmt(dt)} mW P_run {pr:6.0f} mW flagged {sorted(flagged)}")