Files
MeltMind/tools/prepare_phase2_gate_outcome_continuation.py
T

37 lines
4.8 KiB
Python

"""Freeze measured final gate continuation; no scientific launch from preparation."""
import json,shutil,time
from pathlib import Path
from phase2_fixed_io import BASE
from phase2_h1_worker_v2 import checked,sha,save
from phase2_home_freeze_io import verify,freeze
from phase2_gate_outcome_queue import config as original_config
from phase2_gate_outcome_continuation import read,project,scope,original_exited,reused_identity,config
def main():
root=Path('/home/frank14f/MeltMind-runs/phase2-gate-outcome-v2-continuation-2026-11-17');oldroot=Path('/home/frank14f/MeltMind-runs/phase2-gate-outcome-calibration-v2-2026-11-17')
if root.exists():raise FileExistsError('Unique labelled continuation already exists')
old=original_config(oldroot);op=verify(oldroot,'launch');done=read(oldroot/'complete.json');original_exited(oldroot)
if op['commit']!='3443ae534e22de0bfdfa602355abf7f9a69591af':raise ValueError('Original implementation')
ids=sorted(r['index'] for r in done['records']);new=sorted(set(range(493))-set(ids))
if any((oldroot/'parts'/f'{i:04d}').exists() for i in new):raise ValueError('Never-attempted directory already exists')
projection=project(done['cumulative_cpu_seconds'],old['setup_seconds'],sum(old['parts'][i]['row']['nodes'] for i in ids),sum(old['parts'][i]['row']['nodes'] for i in new))
if not projection['within_final_ceiling']:raise RuntimeError('Projection exceeds final110000; no launch')
entries=[];by={r['index']:r for r in done['records']}
for i in ids:
d=oldroot/'parts'/f'{i:04d}';result=read(d/'result.json');e=dict(index=i,case=old['parts'][i]['row']['case'],path=str(d),result_sha256=sha(d/'result.json'),guard_result_sha256=sha(d/'guard-result.json'),output_sha256=result['output_sha256']);reused_identity(e,old['parts'][i],by[i]);entries.append(e)
codes={str(BASE/p):h for p,h in old['code_sha256'].items()}
for name in ['phase2_gate_outcome_continuation.py','prepare_phase2_gate_outcome_continuation.py','test_phase2_gate_outcome_continuation.py']:
p=BASE/'tools'/name;codes[str(p)]=sha(p)
doc=BASE/'docs/phase2-gate-outcome-v2-continuation-2026-11-17.md';codes[str(doc)]=sha(doc)
for p,h in codes.items():checked(p,h)
log=Path('/tmp/gate-v2-continuation-synthetic-attempt1.log').read_text()
if 'Ran 12 tests' not in log or not log.rstrip().endswith('OK'):raise ValueError('Actual12 synthetic PASS required')
c=dict(version='gate-outcome-v2-labelled-continuation-v1',approval='1794927353.190299',original_root=str(oldroot),original_implementation=op['commit'],original_contract_sha256=sha(oldroot/'contract.json'),original_complete_sha256=sha(oldroot/'complete.json'),prior_cpu_seconds=done['cumulative_cpu_seconds'],reused_indices=ids,new_indices=new,projection=projection,total_cpu_seconds=projection['total_cpu_seconds'],geometry_cpu_cap=projection['total_cpu_seconds']-3600,setup_seconds=600,terminal_reserve=120,postfit_reserve=3600,worker_cpus=old['worker_cpus'],coordinator_cpus=[30,31],code_sha256=codes,new_labels_read=False,new_fits=0,new_predictions=0,postfit_started=False,no_retry=True,old_stop_preserved=True,full_postfit_review_required_due_to_new_root_and_accounting=True)
scope(c,old,done);root.mkdir();save(root/'reused-manifest.json',dict(entries=entries,original_complete_sha256=c['original_complete_sha256'],reused_count=333));c['reused_manifest_sha256']=sha(root/'reused-manifest.json');save(root/'contract.json',c);save(root/'projection.json',projection)
shutil.copyfile('/tmp/gate-v2-continuation-synthetic-attempt1.log',root/'synthetic-attempt1.log')
save(root/'acceptance.json',dict(status='PASS',tests=12,log_sha256=sha(root/'synthetic-attempt1.log'),test_source_sha256=sha(BASE/'tools/test_phase2_gate_outcome_continuation.py'),scope='CPU-only synthetic scope, final projection, reservation, original function dispatch, guard limits, actual hash mismatch and process barriers; no real geometry/GPU/targets',unix=time.time()))
save(root/'preparation-audit.json',dict(status='PREPARED_NOT_STARTED',unix=time.time(),original_terminal_count=333,original_status='STOPPED',old_cpu_once=done['cumulative_cpu_seconds'],new_count=160,first_new_index=333,last_new_index=492,all_reused_results_and_arrays_hash_checked=True,original_processes_absent=True,original_scientific_pins_verified=True,new_root_interface=True,postfit_review='New exact full semantic review required; do not reuse old72000 PASS',GPU_training_untouched=True,new_labels_read=False,new_science_executed=False))
freeze(root,'launch',[root/'contract.json',root/'projection.json',root/'reused-manifest.json',root/'acceptance.json',root/'synthetic-attempt1.log',root/'preparation-audit.json',oldroot/'complete.json',*[Path(p) for p in codes]]);config(root)
print(json.dumps(dict(root=str(root),implementation=verify(root,'launch')['commit'],contract_sha256=sha(root/'contract.json'),projection=projection,started=False)))
if __name__=='__main__':main()