85 lines
5.3 KiB
Python
85 lines
5.3 KiB
Python
"""Labelled full-panel A/H1 continuation only; original EIK is never rerun."""
|
|
import argparse
|
|
import fcntl
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import resource
|
|
import shutil
|
|
import sys
|
|
import time
|
|
import phase2_b11_gate as original
|
|
from phase2_h1_worker_v2 import sha,checked,save
|
|
from r4bc_guard import supervise
|
|
|
|
BASE=original.BASE
|
|
OLD=BASE/'artifacts/phase2-b11-gate-2026-11-17'
|
|
H1V2=BASE/'artifacts/phase2-h1-labelled-recovery-2026-11-17'
|
|
ROOT=BASE/'artifacts/phase2-b11-labelled-continuation-2026-11-17'
|
|
def read(p):return json.loads(Path(p).read_text())
|
|
|
|
|
|
def prepare():
|
|
old=read(OLD/'complete.json')
|
|
if old['status']!='COMPLETE' or old['completed']!=['eik','models']:raise ValueError('Original B11 not terminal')
|
|
original.config(OLD);ROOT.mkdir(exist_ok=False);shutil.copyfile(OLD/'contract.json',ROOT/'contract.json')
|
|
save(ROOT/'engineering-contract.json',dict(approval='1794892722.876299',original_complete_sha256=sha(OLD/'complete.json'),
|
|
original_cumulative_cpu_seconds=old['cumulative_cpu_seconds'],new_setup_charge_seconds=60,total_cpu_cap=7200,
|
|
code_sha256={'tools/phase2_b11_continuation.py':sha(BASE/'tools/phase2_b11_continuation.py')},
|
|
source='B1-v2 canonical full-node100 out-of-fold paired A/H1',arms=['A','H1'],rerun_EIK=False,refit=False,retry=False))
|
|
|
|
|
|
def config(root):
|
|
e=read(root/'engineering-contract.json')
|
|
if e['approval']!='1794892722.876299' or e['arms']!=['A','H1'] or e['rerun_EIK']:raise PermissionError('Continuation scope differs')
|
|
for p,h in e['code_sha256'].items():checked(p,h)
|
|
checked(OLD/'complete.json',e['original_complete_sha256'])
|
|
original.H1=H1V2
|
|
return e,original.config(root)
|
|
|
|
|
|
def run(root):
|
|
e,c=config(root);os.sched_setaffinity(0,[22]);start=time.process_time();u0=resource.getrusage(resource.RUSAGE_CHILDREN);charged=0.;records=[]
|
|
def total():
|
|
u=resource.getrusage(resource.RUSAGE_CHILDREN)
|
|
return e['original_cumulative_cpu_seconds']+60+max(charged,u.ru_utime+u.ru_stime-u0.ru_utime-u0.ru_stime)+time.process_time()-start
|
|
with (root/'run.lock').open('a') as lock:
|
|
fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
|
if (root/'started.json').exists():raise FileExistsError('Only one labelled B11 continuation')
|
|
save(root/'started.json',dict(pid=os.getpid(),unix=time.time(),engineering_sha256=sha(root/'engineering-contract.json')))
|
|
try:
|
|
while not (H1V2/'scoring-git-freeze.json').exists():
|
|
if (H1V2/'complete.json').exists():raise RuntimeError('B1-v2 stopped before canonical freeze')
|
|
save(root/'live-progress.json',dict(stage='WAIT_B1_V2_FROZEN_PREDICTIONS',unix=time.time(),cumulative_cpu_seconds=total()))
|
|
if total()>7080:raise RuntimeError('B11 shared CPU cap')
|
|
time.sleep(15)
|
|
entries=original.model_entries(check_git=True)
|
|
for row in c['parts']:original.select_entry(row,entries)
|
|
save(root/'models-source-authorization.json',dict(freeze_sha256=sha(H1V2/'scoring-git-freeze.json'),manifest_sha256=sha(H1V2/'predictions-freeze.json')))
|
|
for mode in ['build','score']:
|
|
name='models-'+mode;dest=root/'phases'/name;dest.mkdir(parents=True,exist_ok=False)
|
|
if mode=='score':
|
|
original.freeze(root,'models',[root/'contract.json',root/'engineering-contract.json',root/'phases/models-build/manifest.json',BASE/'tools/phase2_b11_continuation.py',*[BASE/p for p in c['code_sha256']]])
|
|
original.verify_freeze(root/'models-git-freeze.json');save(root/'models-score-authorization.json',dict(freeze_sha256=sha(root/'models-git-freeze.json')))
|
|
cap=min(1800,7200-total()-120)
|
|
if cap<=0:raise RuntimeError('B11 shared budget exhausted')
|
|
save(root/'live-progress.json',dict(stage=name,unix=time.time(),cumulative_cpu_seconds=total()))
|
|
g=supervise([sys.executable,'tools/phase2_b11_continuation.py',mode,str(root)],dest,
|
|
dict(cpu_seconds=cap,wall_seconds=1800,rss_bytes=8*1024**3,disk_bytes=5*1024**3))
|
|
charged+=g['cpu_seconds'];records.append(dict(phase=name,guard=g))
|
|
save(root/'phase-ledger.json',dict(records=records,cumulative_cpu_seconds=total()))
|
|
if g['status']!='PASS' or total()>7200:raise RuntimeError('B11 labelled phase stopped')
|
|
score=read(root/'phases/models-score/result.json')
|
|
if score['failures'] or any(v['parts']!=50 for v in score['summaries'].values()):raise RuntimeError('Full50 A/H1 continuation incomplete')
|
|
save(root/'complete.json',dict(status='COMPLETE',records=records,old_cpu_seconds=e['original_cumulative_cpu_seconds'],cumulative_cpu_seconds=total(),arms=['A','H1'],rerun_EIK=False,retry=False))
|
|
except BaseException as exc:
|
|
save(root/'complete.json',dict(status='STOPPED',reason=type(exc).__name__+': '+str(exc),records=records,cumulative_cpu_seconds=total(),original_receipts_preserved=True,retry=False));raise
|
|
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('mode',choices=['prepare','run','build','score']);p.add_argument('root',nargs='?',type=Path,default=ROOT);a=p.parse_args()
|
|
if a.mode=='prepare':prepare()
|
|
elif a.mode=='run':run(a.root)
|
|
else:
|
|
e,c=config(a.root);(original.build if a.mode=='build' else original.score)(a.root,c,'models')
|