"""Auditable, bounded experiments; all favorable and unfavorable controls saved.""" from __future__ import annotations import copy import hashlib import json import math from pathlib import Path import platform import sys import time import numpy as np from synthesis import discover, digest, verify_tensor from arithmetic import Kernel, NTTKernel, P from native import build, NativeKernel, NativeNTTKernel from tasks import reciprocal, exponential, reversion, catalan from audit import CreditAccount, AnytimeGate, atomic_save ROOT = Path(__file__).resolve().parents[1] def arrayhash(x): return hashlib.sha256(np.asarray(x,dtype='a else 0) gate.update(sign) pairs.append({'trial':t,'order':order,'parent_ns':a,'candidate_ns':b, 'sign':sign,'parent_units':data[0]['meter']['ledger_units'], 'candidate_units':data[1]['meter']['ledger_units']}) if gate.accepted and t+1>=16: break if gate.accepted:cap+=1 records.append({'proposal':proposal,'length':n,'parent_cap':parent_cap, 'candidate_cap':parent_cap+1,'accepted':gate.accepted, 'after_cap':cap,'evidence':gate.snapshot(),'pairs':pairs}) result={'final_cap':cap,'accepted_proposals':sum(r['accepted'] for r in records), 'alpha':cfg['hardware_alpha'],'records':records, 'null':'For a proposal, conditional probability of a candidate timing win is at most one half on the sampled reciprocal workload.', 'limitations':'No distribution-free guarantee for future wall time; hardware-dependent outcomes; this gate is separate from the arithmetic lineage.'} self.save('hardware_gate.json',result) return result def payback(self,cap): cfg=self.config;rows=[];rng=np.random.default_rng(199903) for rep in range(cfg['payback_jobs']): seed=9100000+rep pair={};outs={} for j in rng.permutation(2): outs[int(j)],pair[int(j)]=self.run_job('reciprocal',cfg['payback_length'],seed,cap if j else 0) if not np.array_equal(outs[0],outs[1]): raise ArithmeticError('Payback task mismatch') rows.append({'replicate':rep,'frozen':pair[0],'evolved':pair[1]}) result={'deployed_cap':cap,'rows':rows, 'frozen_seconds':sum(r['frozen']['wall_ns'] for r in rows)/1e9, 'evolved_seconds':sum(r['evolved']['wall_ns'] for r in rows)/1e9, 'note':'A measured finite deployment workload, not a forecast. Subtract separately recorded discovery, compilation and all relevant proposal-validation costs before claiming net payback.'} self.save('payback.json',result) return result def fixed_budget(self,cap,wall_cap): cfg=self.config;rows=[] methods=[('frozen_schoolbook',0,False),('arithmetic_lineage',cap,False), ('wall_gated_lineage',wall_cap,False),('static_cap4',4,False), ('static_full_envelope',20,False),('conventional_NTT',0,True)] for name,d,ntt in methods: spent=0;completed=0;wall=0.;hashes=[] # Exact shape model makes cost constant for non-NTT methods. NTT # root setup is separately charged through measured counters. while completed<1000: out,r=self.run_job('reciprocal',cfg['budget_length'],9300000+completed,d,ntt) units=r['meter']['ledger_units'] if spent+units>cfg['budget_ledger_units']: # This look-ahead run belongs to audit, not the service # budget; its full cost is explicitly disclosed. lookahead={'units':units,'wall_ns':r['wall_ns']};break spent+=units;wall+=r['wall_ns']/1e9;completed+=1;hashes.append(r['output_sha256']) rows.append({'method':name,'completed':completed,'budget':cfg['budget_ledger_units'], 'spent_units':spent,'service_seconds':wall,'output_hashes':hashes, 'research_only_lookahead':lookahead}) result={'scope':'Equal warm-service abstract resource budgets; separate from end-to-end training budgets.', 'rows':rows} self.save('fixed_budget.json',result) return result def e_simulation(self): cfg=self.config;rng=np.random.default_rng(319127) result=[] for probability in [0.5,0.65,0.8]: successes=0;stops=[] for simulation in range(cfg['null_simulations']): gate=AnytimeGate(1,cfg['hardware_alpha']) for t in range(cfg['null_horizon']): if gate.update(1 if rng.random()