73 lines
4.4 KiB
Python
73 lines
4.4 KiB
Python
"""Supplement: existing five frozen trials on 4090, new output paths only."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
import urllib.request
|
|
import numpy as np
|
|
import pandas as pd
|
|
import yaml
|
|
|
|
ROOT=Path('/data/digital-drosophila')
|
|
MODEL=ROOT/'models/male-cns-lif/apl-pn-scope-audit-v1'
|
|
EXP=ROOT/'experiments/phase4aa-apl-pn-scope'
|
|
sys.path.insert(0,str(MODEL))
|
|
from audit import save,digest,immutable_check
|
|
|
|
def queues():
|
|
result=[]
|
|
for port in (8188,8189,8190):
|
|
with urllib.request.urlopen(f'http://192.168.10.51:{port}/queue',timeout=5) as r:q=json.load(r)
|
|
result.append({'port':port,'running':len(q.get('queue_running',[])),'pending':len(q.get('queue_pending',[]))})
|
|
return result
|
|
|
|
def main():
|
|
out=EXP/'gpu-frozen-regression';out.mkdir(exist_ok=False)
|
|
q=queues();assert all(x['running']==0 and x['pending']==0 for x in q),'ComfyUI busy; defer'
|
|
runtime=ROOT/'models/male-cns-lif/deterministic-runtime-v2'
|
|
cfg=yaml.safe_load((runtime/'phase4p.yaml').read_text())
|
|
os.environ['CUDA_VISIBLE_DEVICES']=cfg['device']['visible_gpu_uuid']
|
|
os.environ['TORCH_CUDA_ARCH_LIST']='8.9'
|
|
os.environ['CUDA_HOME']='/usr/local/cuda'
|
|
os.environ['MAX_JOBS']='2'
|
|
os.environ['PYTHONDONTWRITEBYTECODE']='1'
|
|
sys.path.insert(0,str(ROOT/'models/male-cns-lif'))
|
|
sys.path.insert(0,str(runtime))
|
|
import torch
|
|
import phase4p
|
|
free,total=torch.cuda.mem_get_info();assert free>2*1024**3,'Insufficient free VRAM; no service eviction'
|
|
save(out/'protocol-addendum.json',{'scope':'Five frozen reference v2 trials only; supplement to CPU structural audit',
|
|
'reason':'User confirmed ComfyUI is not in use; baseline behavior check before any future mechanism intervention',
|
|
'new_mechanism_or_training':False,'ComfyUI_queues':q,'available_vram_bytes':free,
|
|
'reference':'experiments/phase4p-deterministic-runtime/phase4c-v2/reference',
|
|
'historical_files_overwritten':False,'source_sha256':digest(Path(__file__)),
|
|
'runtime_sha256':digest(runtime/'phase4p.py'),'config_sha256':digest(runtime/'phase4p.yaml')})
|
|
torch.cuda.reset_peak_memory_stats();start=time.perf_counter();rt=phase4p.CanonicalRuntime(cfg,runtime,out)
|
|
rows=[]
|
|
for spec in cfg['reference_trials']:
|
|
q=queues();assert all(x['running']==0 and x['pending']==0 for x in q),'ComfyUI work arrived; stop between trials'
|
|
ref=ROOT/'experiments/phase4p-deterministic-runtime/phase4c-v2/reference'/spec['name']
|
|
events=pd.read_parquet(ref/'spike-events.parquet')
|
|
expected={'step':events.step.to_numpy(),'neuron_idx':events.neuron_idx.to_numpy(),
|
|
'counts':np.load(ref/'per-neuron-spike-counts.int32.npy'),'v':np.load(ref/'final-voltage.float32.npy'),'g':np.load(ref/'final-g.float32.npy')}
|
|
result=rt.run(np.flatnonzero(rt.pops[spec['population']]),spec['rate_hz'],spec['seed'],spec['duration_ms'])
|
|
exact={k:bool(np.array_equal(result[k],v)) for k,v in expected.items()}
|
|
finite=bool(np.isfinite(result['v']).all() and np.isfinite(result['g']).all())
|
|
row={'trial':spec['name'],'exact':exact,'finite':finite,'pass':all(exact.values()) and finite,
|
|
'wall_seconds':result['metrics']['wall_seconds'],'events':len(result['step']),
|
|
'events_sha256':phase4p.sha_bytes(result['step'],result['neuron_idx']),
|
|
'max_abs_V_error':float(np.max(np.abs(result['v'].astype(float)-expected['v']))),
|
|
'max_abs_g_error':float(np.max(np.abs(result['g'].astype(float)-expected['g'])))}
|
|
save(out/(spec['name']+'.json'),row);rows.append(row);print(json.dumps(row),flush=True)
|
|
assert row['pass'],'Frozen regression diverged'
|
|
save(out/'summary.json',{'pass':all(r['pass'] for r in rows),'trials':rows,'total_wall_seconds_including_build':time.perf_counter()-start,
|
|
'peak_allocated_VRAM_bytes':int(torch.cuda.max_memory_allocated()),'device':torch.cuda.get_device_name(),
|
|
'ComfyUI_models_unloaded':False,'new_dynamics':False,'original_reference_v1_not_overwritten':True,
|
|
'oracle':'deterministic v2 / original v1 preserved; not claiming v1 atomic runtime is deterministic'})
|
|
# No old scientific artifact may change even after imports/build/run.
|
|
post=immutable_check(ROOT,ROOT/'registry/snapshots/bootstrap-20260929',4)
|
|
save(out/'post-regression-integrity.json',post);assert post['pass']
|
|
|
|
if __name__=='__main__':main()
|