Files
MeltMind/tools/prepare_phase3_seed1_postfit.py
T

76 lines
5.7 KiB
Python

"""Metadata-only seed1 postfit preparation; never predict, score, or decode targets."""
from pathlib import Path
import time
from phase2_h1_worker_v2 import sha, checked, save
from phase2_home_freeze_io import verify
from phase3_seed1_v2_common import config as training_config
from phase3_seed1_postfit_common import OLD, PHASE3_PRIOR, GPU, BOOTSTRAP, TRAINING, read, roster
from track_a_h2_prepare import local_code_closure
B=Path(__file__).resolve().parents[1]
T=Path('/home/frank14f/MeltMind-runs/phase3-seed1-v2-2026-11-18')
S=T.parent/'phase2-h2-s2-postfit-2026-11-17'
R=T.parent/'phase3-seed1-postfit-2026-11-18'
def main():
start=time.process_time()
if R.exists():raise FileExistsError('Existing postfit entry; inspect rather than duplicate')
tc,pilot=training_config(T)
if verify(T,'implementation')['commit']!=TRAINING:raise ValueError('Exact active training pin')
old=read(S/'contract.json')
for name in ['implementation','predictions','terminal']:verify(S,name)
by=roster(old,pilot);manifest=read(S/'predictions-manifest.json')['entries']
seed0={e['case']:e for e in manifest}
if len(manifest)!=552 or len(seed0)!=552 or set(seed0)!=set(by):raise ValueError('Original prediction support')
for case,e in seed0.items():
row=by[case]
if e['fold']!=next(a['fold'] for a in row['assignments'] if a['role']=='test') or e['nodes']!=row['nodes'] or e['component_id']!=row['component_id']:
raise ValueError('Original seed0 test role identity')
sources=dict(tc['source_sha256'])
for p,h in {**old['source_sha256'],**old['code_sha256'],**tc['code_sha256']}.items():
if p in sources and sources[p]!=h:raise ValueError('Conflicting source pins')
sources[p]=h
for folder,names in [(T,['contract.json','implementation-git-freeze.json','implementation-authorization.json','review.json']),
(S,['contract.json','predictions-manifest.json','predictions-git-freeze.json','predictions-authorization.json','terminal-git-freeze.json','terminal-authorization.json','score/result.json'])]:
for name in names:sources[str(folder/name)]=sha(folder/name)
spec=B/'references/2026-11-18/phase3-seed-sensitivity/mold-seed-ensemble-spec.md'
sources[str(spec)]=sha(spec)
comparison=dict(approval='1794992262.078969',training_comparison_sha256=tc['comparison_contract_sha256'],
parts=552,components=204,roles='same original S2 five test folds',seeds=[0,1],new_fits=0,
seed0_predictions='hash reuse all552',seed0_metrics='reuse original S2 per-part H2 metrics; no recomputation',
metrics=['relative_l2','last_location','kendall_tau_b'],difference='seed1 minus seed0',
query='original eligible query/raw IDs/multiplicity/Rg/tie/undefined rules unchanged',
aggregation='within-component part means, then equal components; paired complete component intersection',
bootstrap=BOOTSTRAP,report=['each_fold','pooled','undefined_and_counts','negative_unclipped_nodes'],
performance_gate=None,descriptive_only=True,new_decodes=0,unique_test_target_cache_reads=552,
prior_three_seed_proposal_superseded=True,seed2=False,ensemble=False,
interpretation='Noise reference for later 1b/c/b discussion; no automatic later-stage launch; CI describes fixed-model component variability only')
codes=local_code_closure([B/'tools'/n for n in ['phase3_seed1_postfit.py','phase3_seed1_postfit_common.py',
'phase3_seed1_postfit_worker.py','phase3_seed1_postfit_guard.py','phase3_seed1_postfit_statistics.py',
'prepare_phase3_seed1_postfit.py','test_phase3_seed1_postfit.py']]+list((B/'tools/s2_models').glob('*.py')))
for p,h in tc['code_sha256'].items():checked(p,h)
R.mkdir();save(R/'comparison-contract.json',comparison)
c=dict(version='phase3-seed1-postfit-v1',approval='1794992262.078969',training_root=str(T),
training_contract_sha256=sha(T/'contract.json'),training_implementation=TRAINING,
comparison_contract=str(R/'comparison-contract.json'),comparison_contract_sha256=sha(R/'comparison-contract.json'),
seed0_root=str(S),seed0_manifest=str(S/'predictions-manifest.json'),seed0_score=str(S/'score/result.json'),
seed0_predictions=seed0,rows=old['rows'],baseline_predictions=old['baseline_predictions'],
source_sha256=sources,code_sha256=codes,jobs=[dict(id=j['id'],expected_parts=len(j['test'])) for j in tc['jobs']],
gpu_uuid=GPU,worker_cpus=[0,1],coordinator_cpus=[14,15],gpu_cap=167200,postfit_gpu_cap=7200,
postfit_cpu_cap=3600,phase3_gpu_cap=612000,old_seed1_gpu_once=OLD,phase3_prior_gpu_once=PHASE3_PRIOR,
prediction_per_fold_gpu_seconds=900,prediction_per_fold_cpu_seconds=300,score_cpu_seconds=900,
score_wall_seconds=1200,setup_cpu_seconds=180,terminal_cpu_reserve=120,
vram_bytes=15*2**30,rss_bytes=16*2**30,disk_bytes=20*2**30,idle_wait_seconds=20,no_retry=True,
bootstrap=BOOTSTRAP,performance_gate=None,no_auto_launch=True,all_five_training_terminals_before_prediction=True,
all_predictions_frozen_before_targets=True,new_fits=0,new_decodes=0,seed2_started=False,ensemble_started=False)
save(R/'contract.json',c)
save(R/'preparation-receipt.json',dict(status='PREPARED_PENDING_EXACT_PRE_SCORE_REVIEW',
contract_sha256=sha(R/'contract.json'),code_files=len(codes),parts=552,components=204,
metadata_cpu_seconds=time.process_time()-start,source_training_unchanged=True,model_weights_read=False,
scientific_arrays_decoded=False,target_values_read=False,old_scores_parsed=False,new_predictions=False,
training_complete_exists=(T/'complete.json').exists(),launched=False))
print(read(R/'preparation-receipt.json'))
if __name__=='__main__':main()