#!/usr/bin/env python3 """Read-only audit of a U5 campaign folder or its share.zip. NumPy only. Usage: python3 audit_ahc5.py path/to/ahc5-stationary-out/share.zip Checks counters, preserved source hash, every retained start and endpoint, all stored spectra, and the saved positive-curvature witness. The two original ahc5 launch scripts must be beside this file. No optimization is performed. """ from functools import lru_cache from collections import Counter import hashlib import importlib.util import json from pathlib import Path import sqlite3 import sys import tempfile import zipfile import numpy as np ROOT=Path(__file__).resolve().parent def audit(folder): db=sqlite3.connect('file:'+str((folder/'results.sqlite').resolve())+'?mode=ro',uri=True) try: assert db.execute('PRAGMA integrity_check').fetchone()[0]=='ok' meta={k:json.loads(v) for k,v in db.execute('select key,value from meta')} cfg=meta['config'];mode=cfg['mode'];assert mode in ('ascent','stationary') path=ROOT/('ahc5_'+mode+'.py') digest=hashlib.sha256(path.read_bytes()).hexdigest() assert digest==cfg['sha256'], 'Use the matching original script version for this archive.' assert hashlib.sha256((folder/path.name).read_bytes()).hexdigest()==digest spec=importlib.util.spec_from_file_location('ahc5_audit_module',path) p=importlib.util.module_from_spec(spec);spec.loader.exec_module(p) groups=[(family,status,json.loads(data)) for family,status,data in db.execute('select * from aggregates')] assert sum(d['n'] for _,_,d in groups)==meta['next_batch']*p.BATCH flags=sum(d['n'] for _,status,d in groups if status in ('candidate','hessian_uncertain')) assert db.execute("select count(*) from slots where pool='flags'").fetchone()[0]==flags assert db.execute('select count(*) from slots s left join kept k on k.id=s.run_id where k.id is null').fetchone()[0]==0 @lru_cache(maxsize=32) def starts(bid): return p.starts_for(cfg['seed'],bid)[1] worst_metric=worst_spectrum=worst_witness=0.;count=spectra=0 retained=Counter(); unresolved_curvatures=[] for idx,txt,initial,raw,endpoint,full,hor,witness in db.execute('select * from kept order by id'): m=json.loads(txt);count+=1;retained[m['status']]+=1 u0=np.frombuffer(initial,dtype='