114 lines
7.4 KiB
Python
114 lines
7.4 KiB
Python
"""Freeze a review package only: no fitting, inference, labels or geometry calculation."""
|
|
import copy
|
|
import json
|
|
from pathlib import Path
|
|
from freeze_g1_components import sha
|
|
from prepare_s2_r2 import build_jobs as old_jobs
|
|
from s2_custody_common import checked, read_json
|
|
from s2_models.features import histgbrt_grid
|
|
from s2_recovery_supervisor import save
|
|
from s3a_data import ARMS, columns
|
|
|
|
ROOT = Path('artifacts/s3a-planning-2026-11-15')
|
|
|
|
|
|
def build_jobs(roster):
|
|
jobs, cells = old_jobs(roster)
|
|
new_jobs, new_cells = [], []
|
|
for cell in cells:
|
|
for arm in ARMS:
|
|
item = copy.deepcopy(cell)
|
|
item.update(index=len(new_cells), arm=arm, hpo_indices=[])
|
|
for i in cell['hpo_indices']:
|
|
job = copy.deepcopy(jobs[i])
|
|
job.update(index=len(new_jobs), cell=item['index'], arm=arm)
|
|
item['hpo_indices'].append(job['index'])
|
|
new_jobs.append(job)
|
|
new_cells.append(item)
|
|
for cell in new_cells:
|
|
original = next(j for j in jobs if j['kind'] == 'FINAL' and j['cell'] == cell['index']//2)
|
|
job = copy.deepcopy(original)
|
|
job.update(index=len(new_jobs), cell=cell['index'], arm=cell['arm'])
|
|
new_jobs.append(job)
|
|
return new_jobs, new_cells
|
|
|
|
|
|
def main():
|
|
if ROOT.exists():
|
|
raise FileExistsError('Never overwrite a frozen S3-A plan')
|
|
s2 = Path('artifacts/s2-custody-evaluation-2026-11-15')
|
|
previous = read_json(s2/'contract.json')
|
|
for p, h in previous['code_sha256'].items():
|
|
checked(p, h)
|
|
r2 = Path('artifacts/s2-r2-main-2026-11-15')
|
|
baseline = read_json(r2/'batch-complete.json')
|
|
finals = baseline['final_fits']
|
|
if len(finals) != 15 or any(f['status'] != 'PASS' for f in finals):
|
|
raise ValueError('Expected all 15 original R2 final fits')
|
|
for f in finals:
|
|
checked(f['model_path'], f['model_sha256'])
|
|
roster = read_json(checked(previous['roster'], previous['roster_sha256']))
|
|
jobs, cells = build_jobs(roster)
|
|
labels = s2/'custody/label-index.json'
|
|
entries = read_json(labels)
|
|
included = {r['case'] for r in roster['parts'] if r['included']}
|
|
if len(entries) != 617 or {r['case'] for r in entries} != included:
|
|
raise ValueError('617 cached label manifest required')
|
|
# Byte hashing is provenance verification, not target decoding or scoring.
|
|
for e in entries:
|
|
checked(e['path'], e['sha256'])
|
|
paths = set(previous['code_sha256'])
|
|
paths.update(str(p) for p in Path('tools').glob('*s3a*.py'))
|
|
sources = [previous['roster'], previous['exposure_membership'], str(s2/'contract.json'),
|
|
str(s2/'custody/part-scores.json'), str(s2/'custody/result.json'), str(labels),
|
|
str(s2/'prediction-index.json'), str(s2/'predictions-complete.json'), str(r2/'batch-complete.json'),
|
|
str(r2/'contract.json'), 'docs/s3a-execution-contract-2026-11-15.md',
|
|
'artifacts/s2-posthoc-diagnostics-2026-11-15/completion.json']
|
|
historical = baseline['worker_cpu_seconds']
|
|
forecast = historical*(24/20+22/20)*1.25
|
|
c = dict(version='S3-A-review-v1', status='AWAITING_ONE_MAIN_REVIEW_NOT_STARTED',
|
|
direction_ruling='1794732043.086139', execution_approved=False,
|
|
root='artifacts/s3a-execution-2026-11-15',
|
|
roster=previous['roster'], roster_sha256=previous['roster_sha256'],
|
|
exposure_membership=previous['exposure_membership'], exposure_membership_sha256=previous['exposure_membership_sha256'],
|
|
label_index=str(labels), label_index_sha256=sha(labels),
|
|
baseline_scores=str(s2/'custody/part-scores.json'), baseline_scores_sha256=sha(s2/'custody/part-scores.json'),
|
|
baseline_prediction_index=str(s2/'prediction-index.json'), baseline_prediction_index_sha256=sha(s2/'prediction-index.json'),
|
|
baseline_fits=finals, baseline_refit=False, baseline_predictions_reused=True,
|
|
jobs=jobs, cells=cells, grid=histgbrt_grid(), sklearn_version='1.7.2',
|
|
feature_columns={a: columns(a) for a in ARMS}, no_scaler_or_imputation=True, target='T/t_set',
|
|
final_refit='same_learning_pool_only', selection_policy='best_finished_config_fixed_grid_tie_order',
|
|
weighting='Original multiplicity / part total / parts in component / component count; sum1, no rescaling',
|
|
worker_cpus=[8, 10, 12, 14], coordinator_cpus=[30, 31],
|
|
limits=dict(workers=4, worker_cpu_seconds=72000, fitting_worker_cpu_seconds=64800,
|
|
postfit_reserved_cpu_seconds=7200, per_fit_cpu_seconds=1800, per_fit_wall_seconds=7200,
|
|
per_fit_tree_rss_bytes=16*2**30, per_fit_disk_bytes=5*2**30, disk_bytes=100*2**30,
|
|
prediction_scoring_wall_seconds=10800, retries=0, gpu_seconds=0),
|
|
budget_estimate=dict(historical_R2_worker_cpu_seconds=historical,
|
|
fit_projection_cpu_seconds=forecast, postfit_reserve_cpu_seconds=7200,
|
|
projected_total_cpu_hours=(forecast+7200)/3600,
|
|
method='Two feature-count-scaled original195-job costs plus25percent reserve; heuristic not guaranteed'),
|
|
first_fit_checkpoint='First E4 and G2 HPO trials sequential, frozen job0/job12, then per-arm query/iteration/leaf projection with25percent reserve; continue4workers only if combined<=18CPUh. Failure or over-cap stops without retry.',
|
|
budget_accounting='Charge all worker loading/fits/failures/inference/scoring; separately report guards/coordinator. Live tree accounting conservative; reserve remaining running caps before dispatch. Sampled overshoot fails and is disclosed.',
|
|
failure_policy='All12 HPO terminal per cell, choose best finite finished validation score, grid-index ties; all12fail or finalfail=>cellNA. No new geometry exclusion or retry. Terminal and checkpoint freeze precede any test prediction.',
|
|
statistics=dict(primary='1-mean_L2(R2_E4)/mean_L2(R2)', primary_pool=100,
|
|
descriptive_arms=['R2_G2'], replicates=2000, seed=2026111408, margin=.1,
|
|
aggregation='Equal parts then components; deterministic single fit, no seed triplication',
|
|
paired_validity='Every part in both arms within a component; no inherited S2 neural NA mask',
|
|
exposure='Original522 membership intersect617 roster intersect each contrast main-valid components; filter parts first',
|
|
inherited_code='tools/s2_custody_statistics.py unchanged; percentile linear; six-region; undefined replicates retained'),
|
|
target_policy='Existing617 custody cache only; reject currentfold test before training IO; final learningonly; no archive decoder',
|
|
scoring_gate='One main-review approval references frozen contract/code Git commit; all30 new final cells terminal (PASS/NA), model hashes frozen; all successful predictions then hash-frozen with exact expected manifest before scoring',
|
|
interpretation='Adaptive post-S2 follow-up on already disclosed test outcomes; not fresh confirmatory holdout. Not-known-exposed remains descriptive.',
|
|
code_sha256={p: sha(p) for p in sorted(paths)}, source_sha256={p: sha(p) for p in sources})
|
|
ROOT.mkdir()
|
|
save(ROOT/'contract.json', c)
|
|
save(ROOT/'prelaunch.json', dict(status=c['status'], contract_sha256=sha(ROOT/'contract.json'),
|
|
HPO_trials=360, new_final_fits=30, baseline_refits=0, labels_decoded=False,
|
|
fits_started=False, predictions_started=False, scientific_computation_started=False))
|
|
print(json.dumps(read_json(ROOT/'prelaunch.json')))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|