"""Run the bounded controls from the accompanying manuscript. Python >=3.11. Install numpy, sympy and pytest first; see README.json. """ from pathlib import Path import argparse from datetime import datetime, timezone import hashlib import json import os import subprocess import sys ROOT=Path(__file__).resolve().parent def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--tests',action='store_true',help='also run all 69 theory tests') parser.add_argument('--output-dir',type=Path,default=ROOT/'results') args=parser.parse_args() for row in json.loads((ROOT/'manifest.json').read_text())['files']: data=(ROOT/row['path']).read_bytes() if len(data)!=row['bytes'] or hashlib.sha256(data).hexdigest()!=row['sha256']: raise SystemExit('Payload integrity check failed: '+row['path']) output=args.output_dir.resolve() output.mkdir(parents=True,exist_ok=True) commands=[ ['-m','theory.code.density_checks','--ledger','certificates/scalar-lift/completed-order-inventory-v3.json','--output',str(output/'interval-counts.json')], ['-m','theory.code.structured_sources','--output',str(output/'structured-sources.json')], ['-m','theory.code.paley_t_product','--prime','43','--order-count-limit','1000000000','--output',str(output/'paley-t-product.json')], ['-m','theory.code.block_bootstrap','--output',str(output/'block-bootstrap.json')], ] if args.tests: commands.append(['-m','pytest','-q','-p','no:cacheprovider','theory/tests']) env=os.environ.copy() env['PYTHONPATH']=str(ROOT/'src')+os.pathsep+str(ROOT) env['PYTHONDONTWRITEBYTECODE']='1' env.pop('BUTSON_TOWERS_ROOT',None) results=[] for command in commands: print('Running: '+sys.executable+' '+' '.join(command),flush=True) done=subprocess.run([sys.executable,*command],cwd=ROOT,env=env,check=False) results.append({'arguments':command,'exit_code':done.returncode}) if done.returncode: raise SystemExit(done.returncode) report={'schema':'theory-finite-capsule-run-v1','completed_at_utc':datetime.now(timezone.utc).isoformat(),'commands':results,'all_passed':True,'tests_requested':args.tests,'scope':'Bounded exact controls; no analytic theorem or additional formal proof is established by these runs.'} (output/'run-summary.json').write_text(json.dumps(report,indent=2)+'\n') print('All requested finite controls passed.',flush=True) if __name__=='__main__': main()