36 lines
3.1 KiB
Python
36 lines
3.1 KiB
Python
"""Claude1794895409 dependency release only; original science workers unchanged."""
|
|
from phase2_b6_gate import *
|
|
|
|
def run(root):
|
|
c=config(root);os.sched_setaffinity(0,[c['cpu']]);lock=(root/'run.lock').open('a');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
|
if (root/'started.json').exists():raise FileExistsError('B6 zero retries')
|
|
start=time.process_time();u0=resource.getrusage(resource.RUSAGE_CHILDREN);charged=0.;records=[];entries=[]
|
|
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
|
|
save(root/'started.json',dict(pid=os.getpid(),unix=time.time(),contract_sha256=sha(root/'contract.json')))
|
|
try:
|
|
for i,row in enumerate(c['parts']):
|
|
if total()+c['part_cpu_seconds']+1050>7200:raise RuntimeError('B6 remaining CPU cannot reserve next part and postfit')
|
|
dest=root/'parts'/f'{i:02d}';dest.mkdir(parents=True,exist_ok=False)
|
|
remaining=c['disk_bytes']-disk_usage(root)
|
|
if remaining<=0:raise RuntimeError('B6 disk cap')
|
|
save(root/'live-progress.json',dict(stage='GEOMETRY_ONLY',index=i,parts=len(records),unix=time.time(),cumulative_cpu_seconds=total()))
|
|
g=supervise([sys.executable,'tools/phase2_b6_gate.py','field',str(root),str(i)],dest,dict(cpu_seconds=c['part_cpu_seconds'],wall_seconds=c['part_wall_seconds'],rss_bytes=c['rss_bytes'],disk_bytes=remaining))
|
|
charged+=g['cpu_seconds'];record=dict(index=i,case=row['case'],guard=g);records.append(record)
|
|
if g['monitor_errors']:raise RuntimeError('B6 monitor failure')
|
|
if g['status']!='PASS' and not (dest/'failure.json').exists() and not g['stop_reason']:raise RuntimeError('B6 input/configuration failure before field diagnostics')
|
|
if g['status']=='PASS':entries.append(dict(index=i,case=row['case'],result_sha256=sha(dest/'result.json')))
|
|
save(root/'phase-ledger.json',dict(records=records,cumulative_cpu_seconds=total()))
|
|
save(root/'fields-manifest.json',dict(entries=entries,records=records,all50_terminal=True,labels_read=False))
|
|
freeze(root,'fields',[root/'contract.json',root/'fields-manifest.json',*[BASE/p for p in c['code_sha256']]])
|
|
dest=root/'score';dest.mkdir(exist_ok=False)
|
|
g=supervise([sys.executable,'tools/phase2_b6_gate.py','score',str(root)],dest,dict(cpu_seconds=min(900,7200-total()-120),wall_seconds=1200,rss_bytes=c['rss_bytes'],disk_bytes=c['disk_bytes']-disk_usage(root)))
|
|
charged+=g['cpu_seconds'];records.append(dict(phase='score',guard=g))
|
|
if g['status']!='PASS' or total()>7200 or disk_usage(root)>c['disk_bytes']:raise RuntimeError('B6 scoring/resource failure')
|
|
save(root/'complete.json',dict(status='COMPLETE',cumulative_cpu_seconds=total(),records=records,scientific_gate=read(dest/'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]))
|