"""Recompute the comparison from per-trial records, without API calls. Install: python -m pip install pyarrow Run: python reproduce.py /path/to/dataset --verify """ import argparse,collections,json,math,pathlib import pyarrow.parquet as pq def reproduce(root,verify=False): rows=pq.read_table(root/'runs.parquet').to_pylist();out={} assert len(rows)==len({r['record_id'] for r in rows}) for (experiment,arm),group in __import__('itertools').groupby(sorted(rows,key=lambda r:(r['experiment_id'],r['arm'])),key=lambda r:(r['experiment_id'],r['arm'])): group=list(group);by_task=collections.defaultdict(list) for r in group:by_task[r['task_id']].append(r) assert all(len(g)==4 and {r['trial'] for r in g}=={0,1,2,3} for g in by_task.values()) n=len(group);known=all(r['compliant_success'] is not None for r in group) counts={ 'trials':n,'tasks':len(by_task),'successes':sum(r['success'] for r in group), 'compliant_successes':sum(r['compliant_success'] is True for r in group) if known else None, 'success':sum(r['success'] for r in group)/n, 'compliant_success':sum(r['compliant_success'] is True for r in group)/n if known else None, 'pass4':sum(all(r['success'] for r in g) for g in by_task.values())/len(by_task), 'compliant_pass4':sum(all(r['compliant_success'] is True for r in g) for g in by_task.values())/len(by_task) if known else None, 'audited_trials':sum(r['audited'] for r in group),'audit_errors':sum(r['audit_errors'] for r in group), 'violations_executed':sum(r['violations_executed'] or 0 for r in group),'refusals':sum(r['refusals'] for r in group), 'recovery_exhaustions':sum(r['recovery_exhaustions'] for r in group)} for key in ['agent_input_tokens','agent_cached_input_tokens','agent_output_tokens','agent_total_tokens','fact_output_tokens','fact_input_tokens','user_input_tokens','user_output_tokens','recovery_retry_input_tokens','recovery_retry_output_tokens','recovery_retry_total_tokens']: counts[key]=sum(r[key] for r in group) if all(r.get(key) is not None for r in group) else None if verify: native=json.loads((root/'experiments'/experiment/'provenance'/f'{arm}.reported_summary.json').read_text())['common']['overall'] for key in ['success','compliant_success']:assert math.isclose(counts[key],native[key],abs_tol=1e-12) assert counts['pass4']==native['pass']['pass^4'] and counts['compliant_pass4']==native['compliant_pass']['pass^4'] for key in ['violations_executed','refusals','audit_errors']: assert counts[key]==native['policy']['engine_refusals' if key=='refusals' else key] for key in ['input','output','total','cached_input']:assert counts['agent_'+key+'_tokens']==native['tokens'][key]['sum'] out.setdefault(experiment,{})[arm]=counts if verify: decisions=pq.read_table(root/'decisions.parquet',columns=['arm','decision','final_attempt']).to_pylist() for arms in out.values(): for arm,v in arms.items():assert sum(d['arm']==arm and d['decision']=='refuse' and d['final_attempt'] for d in decisions)==v['refusals'] return out if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('root',type=pathlib.Path,nargs='?',default=pathlib.Path(__file__).resolve().parent);p.add_argument('--verify',action='store_true');a=p.parse_args() print(json.dumps(reproduce(a.root,a.verify),indent=2))