"""Freeze the independent 180-HPO +15-final R2 plan, bound to the617 roster.""" import json from pathlib import Path from freeze_g1_components import sha from s2_models.features import histgbrt_grid from s2_main_data import select_cell from s2_recovery_supervisor import save ROOT=Path('artifacts/s2-r2-main-2026-11-15') def build_jobs(roster): grid=histgbrt_grid();jobs=[];cells=[] for fold in range(5): for pool in [25,50,100]: rows,roles=select_cell(roster,fold,pool);index=len(cells) learn=sum(rows[k]['preparation']['eligible_unique'] for k in roles['learning_parts']) val=sum(rows[k]['preparation']['eligible_unique'] for k in roles['validation_parts']) cell=dict(index=index,fold=fold,pool=pool,learning_queries=learn,validation_queries=val, learning_parts=roles['learning_parts'],validation_parts=roles['validation_parts'],hpo_indices=[]) for cfg,params in enumerate(grid): cell['hpo_indices'].append(len(jobs));jobs.append(dict(index=len(jobs),cell=index,fold=fold,pool=pool,kind='HPO', config_index=cfg,params=params,cost_units=learn*params['max_iter']*params['max_leaf_nodes'],cost_queries=learn+val)) cells.append(cell) for cell in cells: jobs.append(dict(index=len(jobs),cell=cell['index'],fold=cell['fold'],pool=cell['pool'],kind='FINAL', config_index=None,cost_units=cell['learning_queries']*1000*63,cost_queries=cell['learning_queries'])) return jobs,cells def main(): assert not ROOT.exists(),'Never replace an R2 attempt root' matrix_path=Path('artifacts/s2-main-matrix-2026-11-15/training-contract.json');matrix=json.loads(matrix_path.read_text()) roster=json.loads(Path(matrix['roster']).read_text());assert sha(matrix['roster'])==matrix['roster_sha256'] for p,h in matrix['code_sha256'].items():assert sha(p)==h,p jobs,cells=build_jobs(roster) added=['tools/s2_r2_data.py','tools/run_s2_r2_fit.py','tools/run_s2_r2.py','tools/prepare_s2_r2.py','tools/test_s2_r2.py'] paths=set(matrix['code_sha256'])|set(added) sources=[str(matrix_path),matrix['roster'],matrix['old_labels_manifest'], 'artifacts/s2-e1-2026-11-14/preflight/claude-gre24-mapping-1b55e166.md', 'artifacts/s2-e1-2026-11-14/preflight/claude-target-9b71d565.md','docs/s2-r2-execution-2026-11-15.md'] c={k:matrix[k] for k in ['roster','roster_sha256','old_labels_manifest','old_labels_manifest_sha256','archive','archive_stat']} c.update(version='S2-R2-G24-independent-v1',jobs=jobs,cells=cells,grid=histgbrt_grid(),sklearn_version='1.7.2', authorizing_rulings=['1794699027.366469','1794707190.141609'],final_refit='same_learning_pool_only', selection_policy='best_finished_config_fixed_grid_tie_order', worker_cpus=[8,10,12,14],coordinator_cpus=[30,31],neural_reserved_cpus=list(range(8)), limits=dict(workers=4,worker_cpu_seconds=100*3600,per_fit_cpu_seconds=1800,per_fit_wall_seconds=7200, per_fit_tree_rss_bytes=16*2**30,per_fit_disk_bytes=5*2**30,disk_bytes=100*2**30,retries=0), first_fit='Job0 alone, empirical full-grid query/iteration/leaf cost forecast with25percent reserve; continue if<=100CPUh. Failed firsttrial uses capped195*30min cost bound only, without a completion forecast.', weighting='Eligible multiplicity / part count-sum / parts-in-component / learning component count; sum1, no rescaling.', test_policy='Current fold test rejected before IO; final fit reads learning only; no test predictions or scoring before all90+15 terminal and unified custody.', failure_policy='Failed configuration NA, no retry; select best finished by component-equal validation relativeL2; all12fail or finalfailure=>cellNA. Report finished/failed config count.', code_sha256={p:sha(p) for p in sorted(paths)},source_sha256={p:sha(p) for p in sources}) ROOT.mkdir();save(ROOT/'contract.json',c) save(ROOT/'prelaunch.json',dict(status='FROZEN_NOT_STARTED',contract_sha256=sha(ROOT/'contract.json'),roster_sha256=c['roster_sha256'], HPO_trials=180,final_fits=15,worker_cpus=c['worker_cpus'],coordinator_cpus=c['coordinator_cpus'],labels_decoded=False,fits_started=False)) print(json.dumps(json.loads((ROOT/'prelaunch.json').read_text()))) if __name__=='__main__':main()