Files
MeltMind/tools/prepare_s1_execution.py
T

45 lines
4.6 KiB
Python

"""Freeze metadata, approval pins and source hashes before real S1 execution."""
import csv,json,sys
from pathlib import Path
from run_s1_fold import sha,read,save
def main():
out=Path(sys.argv[1]);out.mkdir(exist_ok=False);(out/'folds').mkdir()
code=read('artifacts/s1-scoring-code-2026-11-14/verification.json')
frozen=['s1_scoring.py','s1_scoring_io.py','test_s1_scoring.py','o2_rep.py','evaluate_s1_shortfall.py']
for name in frozen:
if sha('tools/'+name)!=code['source_hashes'][name]:raise ValueError('Reviewed source changed: '+name)
o2=Path('artifacts/s1-sampled-o2-2026-11-14');draw=Path('artifacts/s1-sampled-draw-2026-11-14');oc=read(o2/'execution_contract.json')
if not read(o2/'review_release.json')['process_hold_cleared']:raise ValueError('Panel review not released')
if read(o2/'verification.json')['status']!='PASS':raise ValueError('Panel verification missing')
if read(o2/'shortfall.json')['comparable_folds']!=24:raise ValueError('Shortfall not clear')
query=read('artifacts/s1-scoring-code-2026-11-14/query_cost.json')
foldcsv=list(csv.DictReader((draw/'fold_table.csv').open()));folds=[]
for f in foldcsv:
i=int(f['fold_index']);test=int(f['test_panel_index']);train=list(map(int,f['train_panel_indices'].split(';')))
if i!=test or train!=[j for j in range(24) if j!=test]:raise ValueError('Fold table changed')
folds.append(dict(fold_index=i,test_panel_index=test,test_case=f['test_case'],test_source=f['test_source_key'],train_panel_indices=train))
inputs=[o2/n for n in ['execution_contract.json','review_release.json','verification.json','shortfall.json','summary.csv']]+[draw/'fold_table.csv',Path('docs/s1-real-scoring-review-release-2026-11-14.txt')]
for spec in oc['panel']:
folder=o2/'panel'/spec['job'];r=read(folder/'result.json');supervisor=o2/'panel'/(spec['job']+'.supervisor.json')
if read(supervisor)['status']!='PASS':raise ValueError('Numerical supervisor failure')
if sha(folder/'nodes.npz')!=r['output_sha256']['nodes.npz']:raise ValueError('Numerical node hash differs')
for p in [spec['anchor_file'],str(Path(spec['anchor_file']).parent/'receipt.json')]:
if sha(p)!=spec['input_sha256'][p]:raise ValueError('Draw or receipt changed')
inputs.extend([folder/'result.json',supervisor])
files=['tools/'+n for n in frozen]+['tools/run_s1_fold.py','tools/supervise_s1_scoring.py','tools/supervise_sampled_o2.py','tools/test_s1_execution.py','tools/prepare_s1_execution.py']
c=dict(scope='Real S1 input coverage only; no model training',reviewed_scorer_commit='e425419c8012127400e8945baa8d04e2953646bd',numerical_parent='a86a74cbd943e0687ee69fb1cccdc003250113cc',draw_commit='94011fd8efe0512e6579c7c541ccd585dc710c2e',
claude_approval='https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1794643516496129',grok_targeted_pass='https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1794643523014799',interval_label_approval='https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1794643532162559',actual_resume_receipt='https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1794643986876739',
primary_decision='Only the five-permutation-seed mean source interval decides primary ranking. Per-seed results are stability diagnostics; report point-direction counts and interval-classification agreement out of five.',
source_interval_label='固定 LOPO 配对差的来源重加权区间',source_interval_scope='Ranks and reference pools not refitted; overlapping training folds retained; not a 95% coverage guarantee for new sources.',zero_convention='Interval containing or touching zero: 未分先后 / not separated; never equivalent.',
permutation_seeds=list(range(2026111401,2026111406)),query_bootstrap_seed=2026111406,query_bootstrap_replicates=200,source_bootstrap_seed=2026111407,source_bootstrap_replicates=2000,
sequential=True,wall_seconds_per_fold=1800,memory_bytes_per_fold=1342177280,monitor_poll_target_seconds=.02,
budget_failure='Stop offending fold, preserve partial results and supervision receipt, do not enlarge limits. Unexpected producer failure stops subsequent launch. No successful-panel aggregate if a required fold is missing.',
o2_root=str(o2),panel=oc['panel'],folds=folds,query_plan=query['folds'],
code_sha256={p:sha(p) for p in files},input_sha256={str(p):sha(p) for p in inputs},training=False)
save(out/'execution_contract.json',c);print(json.dumps(dict(folds=len(folds),core_source_unchanged=True,contract_sha256=sha(out/'execution_contract.json'),real_S1_started=False),indent=2))
if __name__=='__main__':main()