"""Prepare a grouped two-fold GINO-Greif entry from frozen H2 metadata.""" import argparse import json import math from pathlib import Path import track_b_gino_formal as reference from track_b_gino_shapenet_entry import BASE, checked, read, save, sha ROOT = BASE / 'artifacts/track-b-gino-greif-preparation-2026-11-19' STATUS = 'PREPARED_PENDING_ADAPTER_REVIEW_TIMING_AND_PHASE_PROJECTION' PILOT = BASE / 'artifacts/phase2-h2-pilot-2026-11-17/contract.json' QUERY = Path('/home/frank14f/MeltMind-runs/phase2-h2-s2-postfit-2026-11-17/contract.json') PHASE_TERMINAL = BASE / 'artifacts/phase3-item1b-fold0-labelled-recovery-2026-11-19/complete.json' PINS = { str(PILOT): '9f616974fb01f8f5cab6233273d541b3e53f5975f3632db45ab4676f911fba7b', str(QUERY): '0bd03f42c3b2db5bef26708b2ef873edfe674f724b59bc4b4de8641980d8d330', str(PHASE_TERMINAL): '631a4c679d94466af71ff79e72cb3066c073eaa7d68030805419ff28a74b476e', } ROLES = ('learning', 'validation', 'test') CAP = 200 * 3600 def grouped_folds(pilot, query): included = {row['case']: row for row in query['rows'] if row['included']} fold_records = {} for fold in (0, 1): data = pilot['folds'][fold] if data['fold'] != fold or any(pilot['geometry'][case]['protocol'] != 'grouped' for case in included): raise ValueError('Frozen grouped Greif protocol required') owners = {} sizes = {} for role in ROLES: cases = data[role] if len(set(cases)) != len(cases): raise ValueError('Duplicate grouped role member') for case in cases: row = included[case] family = row['component_id'] assigned = [item['role'] for item in row['assignments'] if item['fold'] == fold] if assigned != [role] or owners.setdefault(family, role) != role: raise ValueError(f'Grouped family or role crossed a boundary in fold {fold}') sizes[role] = len(cases) if set().union(*(set(data[role]) for role in ROLES)) != set(included): raise ValueError(f'Incomplete frozen support for fold {fold}') fold_records[str(fold)] = dict(counts=sizes, clock_coefficient=data['c'], clock_sha256=data['clock_sha256'], parts={role: data[role] for role in ROLES}) return fold_records def project(phase_charged, approvals, epoch_seconds_by_fold, epochs, overhead_gpu_seconds): if set(approvals) != {'gino_shapenet', 'h2_pressure', 'other_unsettled'}: raise ValueError('List all three other phase-3 reservations exactly once') if set(epoch_seconds_by_fold) != {'0', '1'} or type(epochs) is not int or epochs <= 0: raise ValueError('Each frozen fold needs its own measured full epoch') basis = list(epoch_seconds_by_fold.values()) amounts = [phase_charged, overhead_gpu_seconds, *approvals.values()] if (any(not math.isfinite(v) or v < 0 for v in amounts) or any(not math.isfinite(v) or v <= 0 for v in basis)): raise ValueError('Missing or invalid budget terms') greif = math.ceil(1.25 * sum(basis) * 2 * epochs + overhead_gpu_seconds) phase_total = phase_charged + sum(approvals.values()) + greif return dict(greif_projection_gpu_seconds=greif, phase_projection_gpu_seconds=phase_total, phase_cap_gpu_seconds=CAP, within_phase_cap=phase_total <= CAP) def binding(): pilot, query, terminal = (read(checked(path, PINS[str(path)])) for path in (PILOT, QUERY, PHASE_TERMINAL)) folds = grouped_folds(pilot, query) reference_formal = reference.contract() timing = reference_formal['formal']['timing'] prior = terminal['cumulative_phase3_gpu_seconds'] return dict(status=STATUS, handoff='h-539a65e1', working_entry='preparation_only', folds=folds, seeds=[0, 1], jobs=[dict(fold=fold, seed=seed) for fold in (0, 1) for seed in (0, 1)], sources=PINS, reuse_h2=dict(features='original 19 standardized on each fold learning only', geometry='full retained tet nodes', mass='original positive nodal mass', input_clock='original FP64 Vf and frozen learning c', train_target='same normalized residual as H2 candidate', readout='same cF and seconds decode', case_query='original fixed PPS/query multiplicity and raw IDs', target_reads_in_preparation=0), adapter_candidate=dict(status='NEEDS_SCIENTIFIC_REVIEW', method='propose GNO/FNO/GNO with same node features carried into and out of the latent grid', open=['latent grid and feature transport', 'training epochs and learning schedule', 'phase pool and test target access sequencing']), projection=dict(settled_phase3_through_1b_gpu_seconds=prior, gino_measurement_once_gpu_seconds=timing['prior_measurement_gpu_seconds'], gino_shapenet_formal_reserve_gpu_seconds=40000, h2_pressure_unsettled_max_gpu_seconds=40000, phase_cap_gpu_seconds=CAP, measured_greif_epoch_seconds=None, complete_projection=None, status='BLOCKED_PENDING_COMPLETE_PHASE_PROJECTION'), production_guard_limits=reference_formal['limits'], launch_authorized=False, code_sha256={str(path): sha(path) for path in ( Path(__file__).resolve(), reference.SOURCES/'phase2_h2_data.py', reference.SOURCES/'phase2_residual_math.py', reference.SOURCES/'track_b_gino_formal_guard.py')}) if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--write-binding', action='store_true') args = parser.parse_args() c = binding() if args.write_binding: ROOT.mkdir(exist_ok=False) save(ROOT/'preparation-binding.json', c) print(json.dumps({key: c[key] for key in ('status', 'jobs', 'projection', 'launch_authorized')}, indent=2))