Files
MeltMind/artifacts/s2-e1-2026-11-14/superseded-1816-source/run_g1_registration_cost.py
T

43 lines
2.4 KiB
Python

"""One sequential 10-pair cost queue, within the shared E1 ledger."""
import fcntl
import json
from pathlib import Path
import sys
from s2_e1_supervisor import save, supervise
def main():
root=Path('artifacts/s2-e1-2026-11-14')
with (root/'g1-cost-batch.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
if (root/'g1-cost-batch.started.json').exists():raise FileExistsError('Batch already attempted')
save(root/'g1-cost-batch.started.json',{'scope':'10 pre-existing exposed pairs, cost only; no grouping decisions'})
results=[]
for index in range(10):
ledger=json.loads((root/'ledger.json').read_text())
phase=sum(r['cpu_seconds'] for r in ledger['attempts'] if r['name'].startswith('g1-cost-'))
left=min(10800-phase,57600-ledger['cpu_seconds_charged'])
if left<=0:
save(root/'g1-cost-batch.stopped.json',{'reason':'CPU_budget_exhausted','completed':len(results)})
return
limits=dict(total_cpu_seconds=57600,job_cpu_seconds=min(1800,left),job_wall_seconds=1800,
tree_rss_bytes=1342177280,disk_bytes=8*1024**3,max_processes=8)
name=f'g1-cost-{index:02d}'
receipt=supervise([sys.executable,'tools/g1_registration_cost.py',str(root),str(index)],root,name,limits)
results.append(receipt)
print(json.dumps({'index':index,**{k:receipt[k] for k in ['status','stop_reason','cpu_seconds','wall_seconds','peak_tree_rss_bytes']}}),flush=True)
if receipt['status']!='PASS':
save(root/'g1-cost-batch.stopped.json',{'reason':'failed_or_limited_attempt_no_retry','index':index,'receipt':receipt})
return
cpu=[r['cpu_seconds'] for r in results]
save(root/'g1-cost-summary.json',dict(status='TEN_COST_PAIRS_COMPLETE_NOT_GROUPING_ACCEPTED',records=results,
cpu_seconds=sum(cpu),wall_seconds=sum(r['wall_seconds'] for r in results),
full_2000_pair_cpu_hours_mean_scenario=(sum(cpu)/10)*2000/3600,
full_2000_pair_cpu_hours_max_scenario=max(cpu)*2000/3600,
extrapolation='Exposed easiest-near-candidate sample, not representative or upper bound; cached geometry shared within batch; all-corpus no reuse assumption not certified',
blind_review=False,threshold_fit=False,new_candidates=False))
if __name__=='__main__':main()