109 lines
5.9 KiB
Python
109 lines
5.9 KiB
Python
"""Build the independent Track A contract using JSON metadata only. Never launch."""
|
|
import ast
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
|
|
from phase2_h1_worker_v2 import checked, save, sha
|
|
from track_a_h2_common import read, validate_roles
|
|
|
|
BASE = Path(__file__).resolve().parents[1]
|
|
ENTRY = BASE / 'artifacts/track-a-existing-input-audit-2026-11-18/reuse-entry.json'
|
|
ENTRY_SHA = '8f0f3c1088d899b85aa3f578b7552f04cb409fd7a5dcfca3e17eaa3d7e25d0d6'
|
|
RULING = '1794975093.432709'
|
|
|
|
|
|
def local_code_closure(paths):
|
|
found = set()
|
|
pending = list(paths)
|
|
while pending:
|
|
p = Path(pending.pop()).resolve()
|
|
if p in found:
|
|
continue
|
|
found.add(p)
|
|
for node in ast.walk(ast.parse(p.read_text())):
|
|
names = ([node.module] if isinstance(node, ast.ImportFrom) and node.module else
|
|
[a.name for a in node.names] if isinstance(node, ast.Import) else [])
|
|
for name in names:
|
|
q = BASE / 'tools' / (name.split('.')[0] + '.py')
|
|
if q.exists():
|
|
pending.append(q)
|
|
return {str(p): sha(p) for p in sorted(found)}
|
|
|
|
|
|
def prepare(root):
|
|
cpu = time.process_time()
|
|
entry = read(checked(ENTRY, ENTRY_SHA))
|
|
sources = {str(ENTRY): ENTRY_SHA}
|
|
for key in ('A_models_freeze', 'A_predictions_freeze', 'split_manifest',
|
|
'preparation_manifest', 'geometry_manifest', 'source_h2_recipe'):
|
|
ref = entry[key]
|
|
checked(ref['path'], ref['sha256'])
|
|
sources[ref['path']] = ref['sha256']
|
|
pilot = read(entry['source_h2_recipe']['path'])
|
|
h1root = BASE / 'artifacts/phase2-h1-labelled-recovery-2026-11-17'
|
|
h1models = read(h1root / 'models-terminal.json')['models']
|
|
sources[str(h1root / 'models-terminal.json')] = sha(h1root / 'models-terminal.json')
|
|
parts = {}
|
|
geometry = {}
|
|
for case, row in entry['H2_inputs'].items():
|
|
f = row['features_and_targets']
|
|
parts[case] = dict(case=case, output=f['output'], nodes=f['nodes'],
|
|
t_set=f['t_scale_seconds'], output_sha256=f['output_sha256'])
|
|
geometry[case] = row['geometry']
|
|
if geometry[case]['protocol'] != 'v4_random' or geometry[case]['nodes'] != f['nodes']:
|
|
raise ValueError('Native v4 geometry metadata mismatch')
|
|
jobs = []
|
|
gpus = ['GPU-b8c11c01-c91f-aa0b-abf6-dad35085cc76', 'GPU-8b71b032-1b75-2891-935c-ce106a53034a']
|
|
for original in entry['jobs']:
|
|
i = original['split']
|
|
model = next(m for m in h1models if m['index'] == original['existing_H1_v4_job'])
|
|
if model['status'] != 'PASS':
|
|
raise ValueError('Original H1 clock unavailable')
|
|
clock = read(checked(model['clock_path'], model['clock_sha256']))
|
|
sources[model['clock_path']] = model['clock_sha256']
|
|
jobs.append(dict(id=i, split_seed=original['split_seed'], fold=i,
|
|
learning=original['learning'], test=original['test'], validation=[],
|
|
missing_train=original['missing_train'], missing_test=original['missing_test'],
|
|
clock_path=model['clock_path'], clock_sha256=model['clock_sha256'], c=clock['c'],
|
|
learning_nodes=sum(parts[x]['nodes'] for x in original['learning']),
|
|
learning_parts=len(original['learning']), validation_nodes=0,
|
|
target_steps=200 * len(original['learning']), gpu_uuid=gpus[i % 2],
|
|
worker_cpus=[8 + 2 * (i % 2)], guard_cpus=[28 + (i % 2)],
|
|
gpu_seconds=30960, setup_gpu_seconds=60, cpu_seconds=61920,
|
|
vram_bytes=15 * 2**30, rss_bytes=16 * 2**30, disk_bytes=8 * 2**30))
|
|
code = local_code_closure([*[BASE / 'tools' / ('track_a_h2_' + name + '.py')
|
|
for name in ('common', 'worker', 'guard', 'queue', 'prepare')],
|
|
BASE / 'tools/test_track_a_h2_entry.py'])
|
|
# Pin original scientific functions against the already frozen H2 recipe.
|
|
for name in ('phase2_h2_data.py', 'phase2_h2_model.py', 'phase2_h2_pilot_worker.py', 'phase2_residual_math.py'):
|
|
p = BASE / 'tools' / name
|
|
pin = next(h for path, h in pilot['code_sha256'].items() if Path(path).name == name)
|
|
checked(p, pin)
|
|
c = dict(version='track-a-h2-v1', approval='1794973932.596749', protocol_ruling=RULING,
|
|
reuse_entry=str(ENTRY), comparison_contract=str(ENTRY), comparison_contract_sha256=ENTRY_SHA,
|
|
new_fits=5, A_refit=False, seed=0, epochs=200, no_retry=True, new_decodes=0,
|
|
model=pilot['model'], versions=pilot['versions'], parts=parts, geometry=geometry, jobs=jobs,
|
|
original_failed=entry['original_failed'], source_sha256=sources, code_sha256=code,
|
|
gpu_cap=162000, train_gpu_cap=154800, postfit_gpu_reserve=7200,
|
|
coordinator_cpus=[30, 31], aggregate_rss_bytes=40 * 2**30, aggregate_disk_bytes=48 * 2**30,
|
|
normalization='Per-split learning-only original 19 columns, FP64 population mean/std; separate FP64 Vf skip',
|
|
validation='None; no checkpoint selection; no test access in this training entry',
|
|
selection='Last epoch 200 only', clock_policy='Reuse frozen v4 H1 equal successful train-part clock',
|
|
postfit='Separate exact Assist review required before any test access; training never starts postfit',
|
|
metric=entry['metric'], expected_pairing_counts_provisional=[304, 311, 308, 309, 305])
|
|
validate_roles(c, entry)
|
|
root.mkdir(parents=True, exist_ok=False)
|
|
save(root / 'contract.json', c)
|
|
save(root / 'preparation-receipt.json', dict(status='ENTRY_PREPARED_NOT_EXECUTED',
|
|
contract_sha256=sha(root / 'contract.json'), code_files=len(code),
|
|
clock_values_recomputed=False, scientific_arrays_read=False, new_fits_started=False,
|
|
prior_A_audit_rerun=False, learning_counts=[len(j['learning']) for j in jobs],
|
|
cpu_seconds=time.process_time() - cpu, protocol_ruling=RULING))
|
|
print(json.dumps(read(root / 'preparation-receipt.json')))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
prepare(Path(sys.argv[1]).resolve())
|