29 lines
2.4 KiB
Python
29 lines
2.4 KiB
Python
"""Claude1794895409 dependency release only; original science workers unchanged."""
|
|
from phase2_b7_gate import *
|
|
|
|
def run(root):
|
|
c=config(root);os.sched_setaffinity(0,[24]);start=time.process_time();u0=resource.getrusage(resource.RUSAGE_CHILDREN);charged=0.;records=[]
|
|
lock=(root/'run.lock').open('a');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
|
if (root/'started.json').exists():raise FileExistsError('B7 no retry')
|
|
save(root/'started.json',dict(pid=os.getpid(),unix=time.time(),contract_sha256=sha(root/'contract.json')))
|
|
def total():
|
|
u=resource.getrusage(resource.RUSAGE_CHILDREN);return 60+max(charged,u.ru_utime+u.ru_stime-u0.ru_utime-u0.ru_stime)+time.process_time()-start
|
|
try:
|
|
for mode in ['train','predict','score']:
|
|
if mode=='predict':freeze(root,'model',[root/'contract.json',root/'phases/train/model.ubj',root/'phases/train/result.json',*[BASE/p for p in c['code_sha256']]])
|
|
if mode=='score':freeze(root,'predictions',[root/'contract.json',root/'phases/predict/manifest.json',*[BASE/p for p in c['code_sha256']]])
|
|
dest=root/'phases'/mode;dest.mkdir(parents=True,exist_ok=False);cap=min(c['phase_limits'][mode],7200-total()-120)
|
|
disk_remaining=c['disk_bytes']-disk_usage(root)
|
|
if disk_remaining<=0:raise RuntimeError('B7 cumulative disk cap')
|
|
if cap<=0:raise RuntimeError('B7 cumulative CPU cap')
|
|
save(root/'live-progress.json',dict(stage=mode,unix=time.time(),cumulative_cpu_seconds=total()))
|
|
g=supervise([sys.executable,'tools/phase2_b7_gate.py',mode,str(root)],dest,dict(cpu_seconds=cap,wall_seconds=c['phase_limits'][mode],rss_bytes=c['rss_bytes'],disk_bytes=disk_remaining))
|
|
charged+=g['cpu_seconds'];records.append(dict(phase=mode,guard=g));save(root/'phase-ledger.json',dict(records=records,cumulative_cpu_seconds=total()))
|
|
if g['status']!='PASS' or total()>7200 or disk_usage(root)>c['disk_bytes']:raise RuntimeError('B7 phase/resource stop')
|
|
save(root/'complete.json',dict(status='COMPLETE',cumulative_cpu_seconds=total(),records=records,scientific_gate=read(root/'phases/score/result.json')['decision'],retry=False))
|
|
except BaseException as exc:
|
|
save(root/'complete.json',dict(status='STOPPED',reason=type(exc).__name__+': '+str(exc),cumulative_cpu_seconds=total(),records=records,retry=False));raise
|
|
|
|
|
|
if __name__=='__main__':run(Path(sys.argv[1]))
|