Files
MeltMind/tools/prepare_g1_candidate_fingerprints.py

57 lines
4.9 KiB
Python

"""Freeze missing note16 fingerprints and k=3 counting, with no threshold refit."""
from pathlib import Path
from zipfile import ZipFile
import json,hashlib
from g1_candidate_fingerprints import ROOT
from s2_e1_supervisor import save
def sha(path):return hashlib.sha256(Path(path).read_bytes()).hexdigest()
def main():
ROOT.mkdir(exist_ok=False);private=ROOT/'custodian';private.mkdir(mode=0o700);(ROOT/'public').mkdir()
inventory=Path('artifacts/s2-g1-inventory-2026-11-14/custodian/parts.json');parts=json.loads(inventory.read_text())
calibration=Path('artifacts/s2-g1-copy-calibration-2026-11-14/public/calibration-thresholds.json');t=json.loads(calibration.read_text())
assert t['status']=='CALIBRATION_THRESHOLDS_FROZEN'
development=json.loads(Path('artifacts/s2-g1-copy-calibration-2026-11-14/custodian/plan.json').read_text())
dev=sorted({case for j in development['jobs'] for case in j['cases']});assert len(dev)==24
jobs=[]
for r in sorted(parts,key=lambda r:r['case']):
cache=None
for item in r['surface_caches']:
if item['contains_field_labels']:continue
with ZipFile(item['path']) as z:keys={n.removesuffix('.npy') for n in z.namelist()}
if {'points_raw','tetra'}<=keys:cache=item['path'];break
jobs.append({'case':r['case'],'source_key':r['source_key'],'tet_cache':cache,
'tet_cache_sha256':sha(cache) if cache else None,'prior_exposure':r['exposure_state']})
assert len(jobs)==624
save(private/'plan.json',{'jobs':jobs,'development_cases':dev,'purpose':'missing tet-volume note16 fingerprints, not repeated calibration'})
(private/'plan.json').chmod(0o600)
files=['prepare_g1_candidate_fingerprints','g1_candidate_fingerprints','run_g1_candidate_fingerprints','count_g1_candidates',
's2_e1_supervisor','g1_registration_cost','audit_samples','boundary_distance']
contract={'authorizing_rulings':['1794661944.308269','1794662380.787319','1794664166.242149'],
'code_sha256':{f'tools/{name}.py':sha(f'tools/{name}.py') for name in files},
'input_sha256':{str(p):sha(p) for p in [inventory,private/'plan.json',calibration]},'thresholds_sha256':sha(calibration),
'historical_pairs':'artifacts/s2-g1-inventory-2026-11-14/custodian/old_exposed_pairs.json',
'archive':'data.zip','archive_verification':'artifacts/intake-2026-11-13/archive_verification.json',
'shape_columns':['log(A/Rg^2)','log(V/Rg^3)','exact_volume_cov_eigenvalue_ratio_ascending_0','exact_volume_cov_eigenvalue_ratio_ascending_1','area_PPS_radial_over_Rg_P10','area_PPS_radial_over_Rg_P50','area_PPS_radial_over_Rg_P90'],
'physical_extra_column':'log(Rg / one_original_numerical_length_unit)',
'integrals':'V and volume center exact linear tetrahedra; covariance exact degree-2 tetra integration; A exact triangles',
'rg':'unchanged registration convention: tetra-volume/4 nodal quadrature of centered squared radius; not replaced by sqrt(trace(exact covariance))',
'radial':'2000 area PPS points; same numeric-prefix seed convention as fixed registration; P10/P50/P90 inverted_cdf',
'scaling':'within-key median over 24 calibration source parts then equal-key median and linear IQR; drop exactly zero IQR columns',
'ranking':'float64 squared Euclidean; cross-key only; competition rank=1+strictly closer count; all literal ties at k=3 included; union either route/direction',
'extras':'exact canonical boundary-coordinate+triangle hash matches and original 30 exposed candidates; same-key pairs excluded because already same side',
'candidate_order':'minimum four direction ranks then stable a,b IDs; count above 4000 reports before any registration',
'workers':8,'per_pair_wall_seconds':1800,'per_worker_rss_bytes':1342177280,'aggregate_rss_bytes':20*1024**3,
'worker_cpu_budget_seconds':8*3600,'wall_seconds':8*3600,'disk_bytes':8*1024**3,
'stage_scope':'fingerprints and candidate counting only; no pair registration, no field labels, no training/GPU',
'resources':'preparation capped at 8 CPU-h/8 GiB, separate from the 100 worker CPU-h pair-registration budget; prior E1 and calibration usage retained',
'failure_rate':'greater than 2% at every 100 terminal jobs and final partial batch; no replacement/retry; incomplete corpus cannot freeze candidates'}
save(ROOT/'contract.json',contract)
save(ROOT/'public/preparation.json',{'status':'MISSING_FINGERPRINT_CONTRACT_FROZEN','parts':624,
'reusable_tet_caches':sum(j['tet_cache'] is not None for j in jobs),'missing_tet_prefix_reads':sum(j['tet_cache'] is None for j in jobs),
'development_parts':24,'k_per_route':3,'contract_sha256':sha(ROOT/'contract.json'),'plan_sha256':sha(private/'plan.json'),
'thresholds_sha256':sha(calibration),'legacy_point_fingerprints_not_substituted':True,'registration_started':False})
print((ROOT/'public/preparation.json').read_text())
if __name__=='__main__':main()