"""Freeze fold-0 non-test preparation after completed ten-part measurement.""" import json from pathlib import Path import shutil from freeze_g1_components import sha ROOT=Path('artifacts/s2-pilot-inputs-2026-11-15') TEN=Path('artifacts/s2-ten-part-measurement-2026-11-15') def main(): measured=json.loads((TEN/'public/measurement-result.json').read_text()) ten_contract=json.loads((TEN/'contract.json').read_text()) assert measured['attempted']==10 and not measured['not_run'],'Finish fixed ten-part evidence first' assert not ROOT.exists(),'Do not overwrite prior preparation' parts=json.loads(Path('artifacts/s2-g1-components-2026-11-15/custodian/part-splits.json').read_text()) role_lists={r:sorted(p['case'] for p in parts if p['assignments'][0]['role']==r) for r in ['learning','validation','test']} assert [len(role_lists[k]) for k in ['learning','validation','test']]==[387,112,125] manifest=dict(fold=0,seed=0,pool=100,learning_parts=role_lists['learning'],validation_parts=role_lists['validation'],sealed_test_parts=role_lists['test'], split_sha256=sha('artifacts/s2-g1-components-2026-11-15/public/splits.json'),ruling='1794680129.303719') by_case={p['case']:p for p in parts} plan=json.loads(Path('artifacts/s2-g1-candidates-2026-11-14/custodian/plan.json').read_text()) g1=json.loads(Path('artifacts/s2-g1-registration-2026-11-14/custodian/plan.json').read_text())['geometry_cache'] settings_path=Path('artifacts/s2-e1-2026-11-14/log-flow-setting-check/fill-time-setting-context.json') settings={r['member'].removesuffix('.log'):r for r in json.loads(settings_path.read_text())} geometry_counts={r['case']:r for r in __import__('csv').DictReader(open('artifacts/s2-e1-2026-11-14/preflight/geometry_counts.csv'))} passed={r['case']:r for r in measured['rows'] if r['status']=='PASS' and r.get('preparation_status')=='COMPLETE'} prior_failed={r['case'] for r in measured['rows'] if r['case'] not in passed} candidates=sorted(role_lists['learning']+role_lists['validation']);cases=[] for case in candidates: p=by_case[case];meta=geometry_counts[case];setting=settings[case] # Census field spelling is checked below, rather than guessed at execution. tets=int(meta['tet_cells']) spec=dict(case=case,numeric_prefix=int(case.split('_')[0]),source_key=p['source_key'],component_id=p['component_id'], tet_nodes=p['nodes'],tet_cells=tets,t_set=setting['setting']['seconds'],t_set_provenance=setting, g1_geometry=g1[case]['path'],input_sha256={g1[case]['path']:g1[case]['sha256'],str(settings_path):sha(settings_path)}) if case in prior_failed: spec['prior_failed_preparation']=str(TEN/'parts'/case) elif case in passed: source=TEN/'parts'/case;spec.update(reuse_preparation=str(source),reuse_result_sha256=sha(source/'result.json')) else: count_root=Path('artifacts/s1-panel-precheck-2026-11-14')/case if (count_root/'result.json').exists(): result=json.loads((count_root/'result.json').read_text());assert result['status']=='COUNT_COMPLETE' spec.update(legacy_geometry=str(count_root/'geometry.npz'),existing_distance=str(count_root/'boundary_distance_raw.npy')) for name in ['geometry.npz','boundary_distance_raw.npy']:spec['input_sha256'][str(count_root/name)]=result['output_sha256'][name] primary=Path('artifacts/s1-sampled-draw-2026-11-14')/case/'draw.npz' if primary.exists(): dr=json.loads((primary.parent/'receipt.json').read_text());assert dr['status']=='DRAW_COMPLETE' spec['existing_primary_draw']=str(primary);spec['input_sha256'][str(primary)]=dr['output_sha256']['draw.npz'] o2=Path('artifacts/s1-sampled-o2-2026-11-14/panel')/(case+'_original') if (o2/'result.json').exists(): old=json.loads((o2/'result.json').read_text());assert old['status']=='COMPLETE' spec.update(existing_sampled_o2_nodes=str(o2/'nodes.npz'),existing_sampled_o2_result=str(o2/'result.json')) spec['input_sha256'][str(o2/'nodes.npz')]=old['output_sha256']['nodes.npz'];spec['input_sha256'][str(o2/'result.json')]=sha(o2/'result.json') cases.append(spec) assert len(cases)==499 and not ({s['case'] for s in cases}&set(role_lists['test'])) new=[r for r in measured['rows'] if r['case'] in passed and not r['case'].startswith('00000666')] assert new,'Need measured newly prepared cases' rate=sum(r['cpu_seconds'] for r in new)/sum(r['nodes'] for r in new) bpn=max(r['output_disk_bytes']/r['nodes'] for r in measured['rows'] if r['case'] in passed) # Conservative planning charges the full measured preparation rate even to # reusable parts, and reserves 25% for label extraction / corpus differences. projected_cpu=rate*sum(s['tet_nodes'] for s in cases)*1.25/3600 projected_gib=bpn*sum(s['tet_nodes'] for s in cases)*1.25/2**30 ROOT.mkdir();(ROOT/'public').mkdir() (ROOT/'role-manifest.json').write_text(json.dumps(manifest,indent=2)+'\n') added=['tools/s2_preprocess_pilot.py','tools/s2_pilot_prepare.py','tools/s2_pilot_data.py','tools/run_s2_pilot_preparation.py','tools/prepare_s2_pilot_inputs.py','tools/test_s2_pilot_data.py','tools/test_s2_pilot_preparation.py'] paths=list(ten_contract['code_sha256'])+added c=dict(ten_contract,cases=cases,version='S2-pilot-non-test-preparation-v1',code_sha256={p:sha(p) for p in paths}, authorizing_rulings=['1794679459.056999','1794680129.303719'],role_manifest_sha256=sha(ROOT/'role-manifest.json'), ten_measurement_sha256=sha(TEN/'public/measurement-result.json'),initial_cpu_seconds_per_node=rate, initial_projection_cpu_hours=projected_cpu,initial_projection_gib=projected_gib, projection_method='Pooled CPU/node from successful nine new measurement cases excluding cached 666, times all 499 roster nodes, plus 25% reserve; max measured output bytes/node plus 25%', limits=dict(worker_cpu_hours=60,workers=16,disk_bytes=100*2**30,per_part_wall_seconds=1800,per_part_tree_rss_bytes=1342177280,retries=0,replacements=0), input_policy='Only fixed fold0 learning/validation labels may be decoded; sealed tests rejected before IO. Fill_time only. No fitting or GPU.', failure_policy='Retain/drop failed pilot parts with reason; no replacements or retries; original component identity preserved; not a main-matrix completeness waiver', checkpoint='Exactly first 50 terminal jobs before launching job 50; separate reused/new observed per-node CPU rates, extrapolate disk; stop/report if over total cap') (ROOT/'contract.json').write_text(json.dumps(c,indent=2)+'\n') report=dict(status='READY_WITHIN_PLANNING_CAPS' if projected_cpu<=60 and projected_gib<=100 else 'PROJECTION_OVER_CAP_REPORT_BEFORE_LAUNCH', parts=499,learning=387,validation=112,sealed_test=125,fold=0,seed=0,projected_worker_cpu_hours=projected_cpu,projected_gib=projected_gib, cpu_seconds_per_node=rate,full_preparations_reused=sum(bool(s.get('reuse_preparation')) for s in cases), S1_sampled_O2_reused=sum(bool(s.get('existing_sampled_o2_nodes')) for s in cases),contract_sha256=sha(ROOT/'contract.json'), role_manifest_sha256=sha(ROOT/'role-manifest.json'),labels_read=False,workers_started=False) (ROOT/'public/prelaunch-projection.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report)) if __name__=='__main__':main()