"""Independent file-level exact gate; no reliance on a stored backend PASS.""" import argparse import csv import hashlib import json import numpy as np from context import EXP,CFG,check,save,digest def jsonl(path): with path.open() as f: return [json.loads(line) for line in f if line.strip()] def bit_equal(a,b): return a.shape==b.shape and a.dtype==b.dtype and np.array_equal(np.ascontiguousarray(a).view(np.uint8),np.ascontiguousarray(b).view(np.uint8)) def evaluate(name): spec=json.loads((EXP/'cases'/name/'spec.json').read_text());steps=spec['steps'];n=CFG['neurons'] cpu=EXP/'oracle'/name;gpu=EXP/'gpu'/name;checks={};details={} arrays={key:np.load(cpu/filename,mmap_mode='r') for key,filename in ( ('v','v-history.float64.npy'),('g','g-history.float64.npy'),('ref','ref-history.int32.npy'))} expected={'v':np.dtype('float64'),'g':np.dtype('float64'),'ref':np.dtype('int32')} checks['history_shapes_dtypes']=all(x.shape==(steps,n) and x.dtype==expected[k] for k,x in arrays.items()) assert checks['history_shapes_dtypes'] hashes=jsonl(gpu/'tick-state-hashes.jsonl') checks['gpu_state_hash_coverage']=len(hashes)==steps and [x['tick'] for x in hashes]==list(range(steps)) assert checks['gpu_state_hash_coverage'] failures=[];finite=True for tick,row in enumerate(hashes): for key,value in arrays.items(): a=np.ascontiguousarray(value[tick]);sha=hashlib.sha256(a.tobytes()).hexdigest() if sha!=row[key+'_sha256']:failures.append(dict(tick=tick,field=key)) if key!='ref' and not np.isfinite(a).all():finite=False checks['all_tick_raw_state_hashes_exact']=not failures;checks['all_oracle_states_finite']=finite details['first_hash_mismatches']=failures[:10] with np.load(cpu/'state.npz',allow_pickle=False) as a,np.load(gpu/'state.npz',allow_pickle=False) as b: for key in ('step','neuron_idx','counts','v','g','ref'): checks['exact_'+key]=bit_equal(a[key],b[key]) checks['event_clock_range']=bool(np.all((a['step']>=0)&(a['step']=0)&(a['neuron_idx']