Files
MeltMind/tools/prepare_s2_ten_part_measurement.py
T

73 lines
6.6 KiB
Python

"""Freeze the existing ten-part list and data/code whitelist before any worker."""
import csv
import json
from pathlib import Path
import shutil
from freeze_g1_components import sha
ROOT=Path('artifacts/s2-ten-part-measurement-2026-11-15')
def main():
ROOT.mkdir(exist_ok=False);(ROOT/'public').mkdir()
plan_path=Path('artifacts/s2-e1-2026-11-14/preflight/ten_part_plan.csv')
rows=list(csv.DictReader(plan_path.open()))
assert [int(r['numeric_prefix']) for r in rows]==[1130,1324,842,367,746,777,1552,1379,610,666]
for r in rows:
for k in ['numeric_prefix','tet_nodes','tet_cells','tertile']:r[k]=int(r[k])
log_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(log_path.read_text())}
g1=json.loads(Path('artifacts/s2-g1-registration-2026-11-14/custodian/plan.json').read_text())['geometry_cache']
original_o2=Path('artifacts/o2-rep-v1.1a-2026-11-14')
old_contract=json.loads((original_o2/'execution_contract.json').read_text())
for r in rows:
case=r['case'];setting=settings[case]
assert setting['setting_before_filling_phase'] and setting['setting']['seconds']>0
r.update(t_set=setting['setting']['seconds'],t_set_provenance=setting,
g1_geometry=g1[case]['path'],input_sha256={g1[case]['path']:g1[case]['sha256'],str(log_path):sha(log_path)})
primary=Path('artifacts/s1-sampled-draw-2026-11-14')/case/'draw.npz'
if primary.exists():r['existing_primary_draw']=str(primary);r['input_sha256'][str(primary)]=sha(primary)
if r['numeric_prefix']==666:
old=next(s for s in old_contract['cases'] if s['case']==case)
result_path=original_o2/(case+'_original')/'result.json';result=json.loads(result_path.read_text())
r.update(legacy_geometry=old['sample'],existing_distance=old['distance'],existing_o2_nodes=str(result_path.parent/'nodes.npz'),existing_o2_result=str(result_path))
for path in [r['legacy_geometry'],r['existing_distance']]:r['input_sha256'][path]=old_contract['input_sha256'][path]
r['input_sha256'][r['existing_o2_nodes']]=result['full_output_sha256']['nodes.npz']
r['input_sha256'][str(result_path)]=sha(result_path)
for p,h in r['input_sha256'].items():assert sha(p)==h,p
paths=['tools/s2_preprocess.py','tools/run_s2_ten_part_measurement.py','tools/prepare_s2_ten_part_measurement.py','tools/test_s2_preprocess.py',
'tools/s2_e1_supervisor.py','tools/freeze_g1_components.py','tools/g1_candidate_fingerprints.py','tools/g1_registration_cost.py',
'tools/audit_samples.py','tools/boundary_distance.py','tools/run_e6_real_kernel.py','tools/o2_rep.py','tools/s2_models/features.py',
'tools/run_volume_quadrature_trial.py','tools/projector_remesh_probe.py','tools/route_feasibility.py','tools/physical_support_probe.py','tools/analyze_support_capacity_conditions.py']
contract=dict(version='S2-ten-part-preparation-v1',authorizing_rulings=['1794679459.056999'],fixed_split_commit='fb827178eca01ff71f9854c3eb3e985cf5d808fa',
cases=rows,code_sha256={p:sha(p) for p in paths},plan_sha256=sha(plan_path),
archive='data.zip',archive_stat=json.loads(Path('artifacts/intake-2026-11-13/archive_verification.json').read_text()),
limits=dict(stage_wall_seconds=10800,stage_total_cpu_seconds=10800,stage_disk_bytes=5*2**30,per_part_wall_seconds=1800,per_part_rss_bytes=1342177280,parallel_workers=1,numerical_threads=1,retries=0,replacements=0),
input_policy='Geometry-prefix VTU only; explicit geometry NPY whitelist for legacy 666 container; no fill_time array decoding. Existing process setting provenance only. No fitted statistics or labels.',
scales='full-node lumped lower weighted median d: t_part=4*median; R=10*median; full-part lumped center and Rg; no fallback',
draw='reuse any frozen S1 primary draw; otherwise PCG64(SeedSequence([2026111400,prefix])), 2000 PPS replacement slots, d>0, ascending tet/raw IDs',
eligibility='S2-v1-no-gate-q: d>0, O2 valid, N_eff>=64, complete incident-edge block with at least one finite valid endpoint; finite g and edge summary',
cache_policy='Reuse immutable compatible geometry/distance/O2; report new and reused stages separately. Nine missing distance/O2 fields are computed once. Largest 666 full O2 reused at drawn nodes.',
failure_policy='Each preselected part attempted at most once; retain failure and partial outputs; continue other parts within total deadline; never impute unreachable R2 graph or zero scale',
output='base10 all nodes; R2-G24 all nodes20; common query IDs/counts, g2 and E4 with coverage/rejections; no base standardizer fit, labels, optimizer, training or GPU',
pilot='Subsequent stage only, after ten-part evidence; 4 runs total<=2 GPU-h, each<=30min, test fold sealed, no retry')
(ROOT/'contract.json').write_text(json.dumps(contract,indent=2)+'\n')
shutil.copy2(plan_path,ROOT/'public/ten-part-plan.csv')
test=dict(status='PASS',new_adapter_synthetic_checks=6,passed=6,observed_unittest_seconds=.035,
names=['geometry-only whitelist','fixed draws and original IDs','nonpositive scale rejection','S2 no gate eligibility','all incident edge endpoints','stage wall and shared CPU budget'],
unchanged_supervisor_previous_checks=6,previous_receipt='artifacts/s2-e1-2026-11-14/preflight/synthetic-test-receipt.json',
previous_receipt_sha256=sha('artifacts/s2-e1-2026-11-14/preflight/synthetic-test-receipt.json'),
supervisor_source_matches_prior=sha('tools/s2_e1_supervisor.py')=='6753c9ceb0b932047ba505bd15681f109e9407bdb58fd96c55e1431a3f1b4a02',
source_sha256=contract['code_sha256'],labels_fit_gpu=False)
assert test['supervisor_source_matches_prior']
(ROOT/'public/implementation-acceptance.json').write_text(json.dumps(test,indent=2)+'\n')
splits=json.loads(Path('artifacts/s2-g1-components-2026-11-15/public/splits.json').read_text())
with (ROOT/'public/learning-curve-x-axis.csv').open('x') as f:
w=csv.writer(f);w.writerow(['fold','component_fraction_percent','actual_components','actual_parts','actual_nodes','x_axis_label'])
for fold in splits['folds']:
for pool,count in fold['counts']['pools'].items():w.writerow([fold['fold'],pool,count['components'],count['parts'],count['nodes'],'component fraction'])
print(json.dumps(dict(status='CONTRACT_FROZEN_NO_WORKER_YET',contract_sha256=sha(ROOT/'contract.json'),parts=10,legacy_666_reused=True)))
if __name__=='__main__':main()