63 lines
8.5 KiB
Python
63 lines
8.5 KiB
Python
"""Prepare exact S2 review binding while original training continues; no launch."""
|
|
import json,shutil,time
|
|
from pathlib import Path
|
|
from phase2_fixed_io import BASE,verify as old_verify
|
|
from phase2_home_freeze_io import freeze,verify
|
|
from phase2_h1_worker_v2 import checked,sha,save
|
|
from phase2_h2_s2_common import config as training_config
|
|
from phase2_h2_s2_postfit_common import read,roster,config
|
|
|
|
def main():
|
|
root=Path('/home/frank14f/MeltMind-runs/phase2-h2-s2-postfit-2026-11-17')
|
|
if root.exists():raise FileExistsError('Existing S2 postfit; inspect, never duplicate')
|
|
train=Path('/home/frank14f/MeltMind-runs/phase2-h2-s2-2026-11-17');tc,pilot=training_config(train);tp=verify(train,'implementation')
|
|
if tp['commit']!='1f57bad66eb062d4f2269347532321929f873717' or sha(train/'contract.json')!='76e1976bed88fc390812238c3d80693446daea3840dc009ac7d8870ddc43a31d':raise ValueError('Original pinned training identity')
|
|
s1=Path(tc['s1_root']);sc=read(s1/'contract.json');s1pred=verify(s1,'predictions');s1terminal=verify(s1,'terminal')
|
|
aroot=BASE/'artifacts/phase2-b13-e1b-2026-11-17';a=read(aroot/'contract.json');old_verify(aroot,'predictions');old_verify(aroot,'terminal-result')
|
|
hroot=BASE/'artifacts/phase2-h1-execution-2026-11-17';h=read(hroot/'contract.json');jobs={j['fold']:j for j in h['jobs'] if j['protocol']=='grouped' and j['pool']==100}
|
|
rows=[];models=[]
|
|
for f in pilot['folds']:
|
|
af=a['folds'][f['fold']];hj=jobs[f['fold']]
|
|
if hj['baseline_model']!=af['A_baseline'] or set(hj['learning'])!=set(f['learning']) or set(hj['test'])!=set(f['test']):raise ValueError('H1/A/H2 original roles or baseline model differ')
|
|
if {r['case'] for r in af['rows']['learning']}!=set(f['learning']) or {r['case'] for r in af['rows']['test']}!=set(f['test']):raise ValueError('Original E1b learning/test roles differ')
|
|
by={r['case']:r for r in af['rows']['test']};rows.extend(by[k] for k in f['test']);models.append(hj['baseline_model'])
|
|
entries=read(aroot/'predictions-manifest.json')['entries'];baseline={e['case']:e for e in entries};fold0=read(s1/'predictions-manifest.json')['entries']
|
|
if len(entries)!=552 or len(baseline)!=552 or len(fold0)!=121 or {e['case'] for e in fold0}!=set(pilot['folds'][0]['test']):raise ValueError('Frozen prediction manifest coverage')
|
|
for e in entries:
|
|
if e['A_source_sha256']!=a['A_predictions'][e['case']]['sha256']:raise ValueError('Frozen A source identity')
|
|
for e in fold0:
|
|
if e['fold']!=0 or e['A_source_sha256']!=baseline[e['case']]['sha256']:raise ValueError('S1 original baseline pairing')
|
|
sources={}
|
|
def add(p,digest):
|
|
p=str((BASE/Path(p)).resolve())
|
|
if p in sources and sources[p]!=digest:raise ValueError('Conflicting input hash: '+p)
|
|
sources[p]=digest
|
|
for old in [tc,sc]:
|
|
for p,digest in old['source_sha256'].items():add(p,digest)
|
|
for p in [train/'contract.json',train/'implementation-git-freeze.json',Path(tc['pilot_contract']),s1/'contract.json',s1/'predictions-manifest.json',s1/'predictions-git-freeze.json',s1/'terminal-git-freeze.json',s1/'complete.json',s1/'post-terminal-cost.json',s1/'score/result.json',aroot/'contract.json',aroot/'predictions-manifest.json',aroot/'score/result.json',aroot/'predictions-git-freeze.json',aroot/'terminal-result-git-freeze.json',hroot/'contract.json']:add(p,sha(p))
|
|
for e in entries+fold0:add(e['path'],e['sha256'])
|
|
for m in models:add(m['path'],m['sha256'])
|
|
for p,digest in sources.items():checked(p,digest) # Opaque bytes only; no score/target value parsing.
|
|
codes={}
|
|
for old in [tc,sc,a]:
|
|
for p,digest in old['code_sha256'].items():
|
|
p=str((BASE/Path(p)).resolve())
|
|
if p in codes and codes[p]!=digest:raise ValueError('Conflicting source pin: '+p)
|
|
checked(p,digest);codes[p]=digest
|
|
for name in ['phase2_h2_s2_postfit_common.py','phase2_h2_s2_postfit.py','phase2_h2_s2_prediction_guard.py','prepare_phase2_h2_s2_postfit.py','test_phase2_h2_s2_postfit.py']:
|
|
p=BASE/'tools'/name;codes[str(p)]=sha(p)
|
|
doc=BASE/'docs/phase2-h2-s2-postfit-2026-11-17.md';codes[str(doc)]=sha(doc)
|
|
comparison=dict(approval='1794925470.101149',test_parts=552,test_components=204,fold0_prediction_and_metric_hash_reuse=True,new_prediction_parts=431,checkpoint_folds=[1,2,3,4],checkpoint_epoch=200,seed=0,A_models=models,clocks=[dict(fold=f['fold'],c=f['c'],path=f['clock_path'],sha256=f['clock_sha256']) for f in pilot['folds']],metrics=['relative_l2','last_location','kendall_tau_b'],query='Original eligible S2 queries; multiplicities once; raw-ID minimum tie rule; last distance/Rg',pooling='Original E1b pooled(): per-arm component requires all constituent part metrics defined; component means equally weighted; paired intersection',bootstrap=dict(replicates=2000,seed=2026111408),confirmation='CONFIRMED iff complete552/204 paired field H2-A upper95CI<0; strict finite bound; incomplete field support PARK',report_only=['H2-B13_E1b','last_location','kendall_tau_b'],negative_clipping=False,all_four_checkpoints_frozen_and_training_exited_before_prediction=True,actual_new_semantic_PASS_before_any_target=True,predictions_frozen_before_score=True,new_fits=0,new_decodes=0,no_retry=True,no_follow_on_launch=True,interpretation='Five-fold recipe confirmation after observing fold0; not an untouched-five-fold preregistration or connectivity causal claim')
|
|
log=Path('/tmp/h2-s2-postfit-synthetic-attempt1.log').read_text()
|
|
if 'Ran 23 tests' not in log or not log.rstrip().endswith('OK'):raise ValueError('Actual23 synthetic PASS required')
|
|
c=dict(version='H2-S2-pooled-postfit-v1',approval='1794925470.101149',postfit_root=str(root),training_root=str(train),training_implementation=tp['commit'],training_jobs=tc['jobs'],s1_root=str(s1),pilot_contract=tc['pilot_contract'],fold0_manifest=str(s1/'predictions-manifest.json'),fold0_score=str(s1/'score/result.json'),baseline_score=str(aroot/'score/result.json'),rows=rows,baseline_predictions=baseline,source_sha256=sources,code_sha256=codes,total_h2_gpu_seconds=144000,prediction_gpu_seconds=2400,postfit_cpu_seconds=3600,setup_cpu_seconds=360,prediction_per_fold_gpu_seconds=600,prediction_per_fold_worker_cpu_seconds=540,score_worker_cpu_seconds=600,terminal_cpu_reserve=120,coordinator_cpus=[12,13],vram_bytes=15*2**30,rss_bytes=16*2**30,disk_bytes=20*2**30,comparison_contract=str(root/'comparison-contract.json'),new_fits=0,new_decodes=0,no_retry=True,actual_new_semantic_PASS_required=True,all_four_terminal_before_prediction=True,no_auto_launch=True)
|
|
roster(c,pilot);root.mkdir();save(root/'comparison-contract.json',comparison);c['comparison_contract_sha256']=sha(root/'comparison-contract.json');save(root/'contract.json',c)
|
|
shutil.copyfile('/tmp/h2-s2-postfit-synthetic-attempt1.log',root/'synthetic-attempt1.log')
|
|
save(root/'acceptance.json',dict(status='PASS',tests=23,elapsed_seconds=1.477,log_sha256=sha(root/'synthetic-attempt1.log'),test_source_sha256=sha(BASE/'tools/test_phase2_h2_s2_postfit.py'),scope='CPU synthetic plus actual isolated Git/file review-validator tests; no real prediction, target read, fitting or CUDA workload',setup_cpu_seconds_reserved=360,unix=time.time()))
|
|
save(root/'preparation-audit.json',dict(status='PREPARED_NOT_LAUNCHED',unix=time.time(),training_implementation=tp['commit'],S1_prediction_commit=s1pred['commit'],S1_terminal_commit=s1terminal['commit'],test_parts=552,test_components=204,fold_test_counts=[len(f['test']) for f in pilot['folds']],original_learning_test_roles_and_A_models_equal=True,original_prediction_hashes_checked=673,new_fits=0,new_predictions=0,new_scores=0,old_score_values_read=False,test_target_values_read=False,training_untouched=True,gate_queue_untouched=True,future_checkpoint_adoption='Not present or required at preparation; all four original models/terminal freezes and process exit mandatory at execution',actual_new_review_pending=True))
|
|
freeze(root,'implementation',[root/'contract.json',root/'comparison-contract.json',root/'acceptance.json',root/'synthetic-attempt1.log',root/'preparation-audit.json',*[Path(p) for p in codes]])
|
|
proof=verify(root,'implementation');save(root/'expected-review-binding.json',dict(reviewed_commit=proof['commit'],contract_sha256=sha(root/'contract.json'),implementation_proof_sha256=sha(root/'implementation-git-freeze.json'),comparison_contract_sha256=c['comparison_contract_sha256'],code_sha256=codes))
|
|
freeze(root,'review-binding',[root/'contract.json',root/'expected-review-binding.json',root/'implementation-git-freeze.json',root/'implementation-authorization.json']);config(root)
|
|
print(json.dumps(dict(root=str(root),implementation=proof['commit'],contract_sha256=sha(root/'contract.json'),binding_sha256=sha(root/'expected-review-binding.json'),code_files=len(codes),review_pending=True,launched=False)))
|
|
if __name__=='__main__':main()
|