62 lines
6.3 KiB
Python
62 lines
6.3 KiB
Python
"""Freeze full authorized calibration preparation without opening target values."""
|
|
import json,time,sys
|
|
from pathlib import Path
|
|
from phase2_fixed_io import BASE
|
|
from phase2_h1_worker_v2 import sha,checked,save
|
|
from phase2_home_freeze_io import freeze,verify
|
|
from phase2_gate_outcome_queue import validate_scope,config
|
|
|
|
def read(p):return json.loads(Path(p).read_text())
|
|
def partition_source(directory,case,expected,sources):
|
|
for _ in range(4):
|
|
r=read(directory/'result.json');checked(directory/'result.json',expected)
|
|
p=directory/'G-partition.npz'
|
|
if p.exists():return checked(p,r['partition_sha256'])
|
|
if 'source_partition' in r:return checked(r['source_partition'],r['partition_sha256'])
|
|
contract=directory.parent.parent/'contract.json';sources[str(contract)]=sha(contract)
|
|
match=[x for x in read(contract)['reused_geometry'] if x['case']==case]
|
|
if len(match)!=1 or match[0]['result_sha256']!=expected:raise ValueError('Unresolved original partition provenance')
|
|
directory=Path(match[0]['source'])
|
|
raise ValueError('Partition provenance chain too long')
|
|
def main():
|
|
root=Path('/home/frank14f/MeltMind-runs/phase2-gate-outcome-calibration-v2-2026-11-17')
|
|
if root.exists():raise FileExistsError('Single preparation root already exists')
|
|
old=Path('/home/frank14f/MeltMind-runs/phase2-holdout-gate-calibration-2026-11-17');groot=BASE/'artifacts/phase2-b13-e1b-2026-11-17'
|
|
verify(old,'terminal');cal=read(old/'calibration-result.json');extract=read(old/'extractor-receipt.json');science=read(groot/'contract.json');rows={r['case']:r for r in science['parts']};gmanifest=read(groot/'features-manifest.json')['entries'];pred={e['case']:e for e in read(groot/'predictions-manifest.json')['entries']}
|
|
if cal['accepted_for_v2'] or cal['exact_match_parts']!=52 or len(rows)!=552:raise ValueError('Original exact FAIL must stand')
|
|
sources={str(p):sha(p) for p in [old/'contract.json',old/'complete.json',old/'calibration-result.json',old/'extractor-receipt.json',groot/'contract.json',groot/'features-manifest.json',groot/'predictions-manifest.json']}
|
|
G={}
|
|
for e in gmanifest:
|
|
d=groot/'parts'/f"{e['index']:04d}";p=checked(d/'result.json',e['result_sha256']);v=read(p);sources[str(p)]=e['result_sha256'];valid=v['status']=='GEOMETRY_COMPLETE'
|
|
g=dict(valid=valid,extra_path=str(d/'extra.npy'),extra_sha256=v['extra_sha256'],result_path=str(p),result_sha256=sha(p))
|
|
checked(g['extra_path'],g['extra_sha256'])
|
|
if valid:
|
|
partition=partition_source(d,e['case'],e['result_sha256'],sources)
|
|
g.update(partition_path=str(checked(partition,v['partition_sha256'])),partition_sha256=v['partition_sha256'])
|
|
G[e['case']]=g
|
|
parts=[];reuse=[];invalid=[]
|
|
for entry in cal['rows']:
|
|
case=entry['case'];row=rows[case];gatefile=old/'gate-ids'/(case+'.json');ids=read(checked(gatefile,extract['output_sha256'][case+'.json']))['gate_raw_ids']
|
|
if ids!=entry['extracted_gate_raw_ids']:raise ValueError('Sealed gate identity')
|
|
if not ids:invalid.append(case);continue
|
|
if not entry['extracted_all_in_tet_domain']:raise ValueError('Invalid seed coverage')
|
|
if entry['exact_node_set_match']:
|
|
files={str(Path(row['v5_cache']['output'])/(k+'.npy')):row['v5_cache']['output_sha256'][k+'.npy'] for k in ['features','Di','Df','Dw','Vf','raw_ids']}
|
|
files[G[case]['extra_path']]=G[case]['extra_sha256'];files[pred[case]['path']]=pred[case]['sha256']
|
|
for p,h in files.items():checked(p,h)
|
|
reuse.append(dict(case=case,component_id=row['component_id'],row=row,G=G[case],prediction=pred[case],source_sha256=files,sealed_gate_sha256=sha(gatefile)))
|
|
else:parts.append(dict(row=row,gate_raw_ids=ids,sealed_gate_sha256=sha(gatefile),G=G[case]))
|
|
if set(invalid)!=set(extract['invalid_gate_input_cases']):raise ValueError('Invalid roster')
|
|
codes=dict(science['code_sha256'])
|
|
for p in ['tools/phase2_gate_outcome_features.py','tools/phase2_gate_outcome_queue.py','tools/prepare_phase2_gate_outcome.py','tools/test_phase2_gate_outcome_features.py','tools/test_phase2_gate_outcome_queue.py','tools/phase2_home_freeze_io.py','tools/phase2_local_freeze_io.py']:
|
|
codes[p]=sha(BASE/p)
|
|
for p,h in codes.items():checked(BASE/p,h)
|
|
c=dict(version='gate-outcome-v2-preparation-v1',approval='1794916421.489089',total_cpu_seconds=72000,geometry_cpu_cap=68400,postfit_reserve=3600,setup_seconds=600,worker_cpus=list(range(16,28)),disk_bytes=12*2**30,parts=parts,exact_reuse=reuse,invalid_cases=invalid,original_cases=list(rows),source_sha256=sources,code_sha256=codes,archive=science['archive'],archive_stat=science['archive_stat'],first_ten='first ten recomputed cases in frozen original order',first_ten_workers=4,after_cost_workers=12,new_fits=0,new_v2_label_reads=0,predictions_pending=True,comparison_pending=True,comparison_requires_semantic_assist_pass=True,acceptance_bands=dict(field=.001,last_location=.010,both_models=['A','B13-E1b']),exact_set_fail_preserved=True,download_42_paused=True,old_holdout_cost_not_charged_here=True,no_retry=True)
|
|
c['comparison_rule']=dict(approval='1794917650.044649',paired_parts='both label-gate and LOG-gate predictions defined',within_component='mean over defined paired parts',component_weight='equal',bootstrap_replicates=2000,bootstrap_seed=2026111408,no_imputation=True,eligibility_denominator=552,invalid_gate_parts=7,eligibility_loss='7/552',exclude_only_components_with_zero_defined_parts=True,report_excluded_component_count=True)
|
|
validate_scope(c);root.mkdir();save(root/'contract.json',c)
|
|
save(root/'acceptance.json',dict(status='PASS',tests=10,command='python -m unittest tools.test_phase2_gate_outcome_features tools.test_phase2_gate_outcome_queue',reported_elapsed_seconds=1.106,scope='3 original-algorithm bitwise synthetic checks plus7 scope/budget/actual guard checks',new_real_geometry_executions=0,setup_charged_seconds=600,unix=time.time()))
|
|
save(root/'preparation-audit.json',dict(status='PASS',recompute=len(parts),exact_reuse=len(reuse),invalid=len(invalid),no_labels_opened=True,exact_reuse_files_hash_checked=True,partitions_hash_checked=True,original_exact_fail=True,archive_metadata_only=True,unix=time.time()))
|
|
freeze(root,'launch',[root/'contract.json',root/'acceptance.json',root/'preparation-audit.json',*[BASE/p for p in codes]])
|
|
config(root);print(json.dumps(dict(root=str(root),commit=verify(root,'launch')['commit'],contract_sha256=sha(root/'contract.json'),real_queue_started=False)))
|
|
if __name__=='__main__':main()
|