interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / calibration / scripts / freeze_candidate.sh

145 lines · 8946 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# freeze_candidate.sh: hash every EXP-001 candidate model and the profile into
18# calibration/experiments/EXP-001/candidate_manifest.json.
19#
20# sh calibration/scripts/freeze_candidate.sh [--freeze] [CANDIDATE_DIR]
21#
22# CANDIDATE_DIR (default build/turing-exp001-a/candidates) must hold the seven .tym files written by
23# `make turing-exp001-a-candidates` (dev seeds 1-7 only). For each file the manifest records: file SHA-256,
24# model digest SHA-256('turing.ymodel.v0' || 0x00 || bytes), byte size, L(M) from the TYM0 header
25# (104 + 16(K-1) + rows x (keybits + 16(K-1))), and where the frozen bytes live. Small codes are copied into
26# calibration/experiments/EXP-001/candidates/ (committed); the two memorization controls (76 MB and 45 MB)
27# are not committed: a copy goes to ~/aien-data/turing-cal/candidates/ ($TXA_BIG_STORE), their bytes are
28# regenerated deterministically from dev seeds 1-7 by `make turing-exp001-a-candidates`, and they must hash to
29# the recorded SHA-256 before use. runtime_sha256 lists runtime_digest.sh --lines when all binaries are built.
30# Also recorded: profile SHA-256, sidecar content, SHA-256 of every shared-background file, and
31# independent_scorer_source_sha256 (rule below). The manifest names NO commit: the commit that adds the frozen
32# manifest is the freeze commit C_f (two-step freeze, BLINDING_PROTOCOL.md section 2); sealed seeds are derived
33# from C_f, and a later freeze-receipt commit (freeze_receipt.sh C_f) records it.
34# independent_scorer_source_sha256 = SHA-256 of the LF-terminated lines "<sha256> <path>" for every file under
35# tools/turing_verify_indep/, path relative to that directory, sorted by path (LC_ALL=C byte order).
36#
37# Default (draft) mode: writes the manifest with "status": "draft".
38# --freeze: additionally requires a clean worktree, check_profile.sh --freeze passing (no FILL_AT_FREEZE, sidecar
39# matches) and calibration/experiments/EXP-001/preregistration.json at "status": "frozen", and refuses if any sealed data entry exists (EXP-001R: other than the burned EXP-001 root) (sealed data may only exist after C_f).
40# Writes "status": "frozen".
41# Refuses if the candidate directory holds anything other than the seven expected files, or if any sealed
42# path is passed. It never reads sealed data. No Python: POSIX sh, od, sha256sum.
43set -eu
44dir=$(cd "$(dirname "$0")/../.." && pwd)
45. "$dir/calibration/scripts/tc_exp.sh"
46freeze=0
47if [ "${1:-}" = "--freeze" ]; then freeze=1; shift; fi
48cdir="${1:-$dir/build/turing-exp001-a/candidates}"
49out="$dir/$EXP_DIR/candidate_manifest.json"
50store="$dir/$EXP_CAND_STORE"
51toml="$dir/$EXP_PROFILE"
52side="$dir/$EXP_SIDECAR"
53die() { echo "freeze_candidate: REFUSED: $*" >&2; exit 1; }
54
55case "$cdir" in *sealed*|*turing-cal/sealed*) die "candidate directory looks like sealed data: $cdir" ;; esac
56names="B0_uniform B1_order0 B2_order1 B3_heuristic M_candidate M_mem M_mem_seed1"
57for n in $names; do [ -f "$cdir/$n.tym" ] || die "$cdir/$n.tym missing (run make turing-exp001-a-candidates)"; done
58extra=$(ls "$cdir" | grep -v -x -e B0_uniform.tym -e B1_order0.tym -e B2_order1.tym -e B3_heuristic.tym \
59 -e M_candidate.tym -e M_mem.tym -e M_mem_seed1.tym || true)
60[ -z "$extra" ] || die "unexpected files in $cdir: $extra"
61[ -f "$toml" ] || die "profile missing"
62
63
64if [ "$freeze" = 1 ]; then
65 [ -z "$(git -C "$dir" status --porcelain)" ] || die "worktree not clean"
66 sh "$dir/calibration/scripts/check_profile.sh" --freeze || die "check_profile --freeze failed"
67 grep -q "^ \"status\": \"frozen\"," "$dir/$EXP_DIR/preregistration.json" || die "preregistration.json is not status frozen (set it in the same commit, before this step)"
68 sealed="${TC_SEALED_ROOT:-$HOME/aien-data/turing-cal/sealed}"
69 _bad=$(tc_sealed_clear "$sealed") || die "sealed data already exist under $sealed (freeze must come first):$_bad"
70fi
71
72# u(file, byte offset, nbytes) -> unsigned big-endian integer
73u() { od -An -t u1 -j "$2" -N "$3" "$1" | tr -s ' \n' ' ' | awk '{v=0; for(i=1;i<=NF;i++) v=v*256+$i; printf "%.0f", v}'; }
74# awk is used only as a calculator above; no data is interpreted by anything but the header layout.
75
76mkdir -p "$store" "$dir/$EXP_DIR"
77psha=$(sha256sum "$toml" | cut -c1-64)
78sidec=""
79[ -f "$side" ] && sidec=$(cut -c1-64 "$side")
80{
81 printf '{\n "schema": "turing.cal.candidate_manifest.v1",\n'
82 printf ' "experiment": "%s",\n' "$EXP_ID"
83 printf ' "status": "%s",\n' "$([ "$freeze" = 1 ] && echo frozen || echo draft)"
84 [ "$freeze" = 1 ] && printf ' "frozen_at": "%s",\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
85 printf ' "profile_path": "%s",\n' "$EXP_PROFILE"
86 printf ' "profile_sha256": "%s",\n' "$psha"
87 printf ' "profile_sidecar_sha256": "%s",\n' "$sidec"
88 printf ' "profile_sidecar_matches": %s,\n' "$([ "$psha" = "$sidec" ] && echo true || echo false)"
89 printf ' "fit_data": "exp-20260927-rep10 control seeds 1-7, manifest sha256 6efc04b525af60706bd0f3176013fe234d8e8a52e2554cff3add8a4e16171dca",\n'
90 printf ' "candidates": [\n'
91 first=1
92 for n in $names; do
93 f="$cdir/$n.tym"
94 bytes=$(wc -c < "$f" | tr -d ' ')
95 fsha=$(sha256sum "$f" | cut -c1-64)
96 mdig=$({ printf 'turing.ymodel.v0\000'; cat "$f"; } | sha256sum | cut -c1-64)
97 K=$(u "$f" 5 1); kb=$(u "$f" 8 1); rows=$(u "$f" 9 4)
98 lm=$((104 + 16 * (K - 1) + rows * (kb + 16 * (K - 1))))
99 [ $(((lm + 7) / 8)) = "$bytes" ] || die "$n: header implies $lm bits but file has $bytes bytes"
100 if [ "$bytes" -lt 1048576 ]; then
101 if [ -f "$store/$n.tym" ]; then cmp -s "$f" "$store/$n.tym" || die "$n differs from the committed $store/$n.tym (no refit)"; else cp "$f" "$store/$n.tym"; fi
102 loc="git:$EXP_CAND_STORE/$n.tym"
103 else
104 big="${TXA_BIG_STORE:-$HOME/aien-data/turing-cal/candidates}"
105 mkdir -p "$big"
106 cp "$f" "$big/$n.tym.tmp" && mv "$big/$n.tym.tmp" "$big/$n.tym"
107 [ "$(sha256sum "$big/$n.tym" | cut -c1-64)" = "$fsha" ] || die "$n: copy in $big does not hash to $fsha"
108 loc="outside git: copy at ~/aien-data/turing-cal/candidates/$n.tym; regenerate with make turing-exp001-a-candidates (deterministic from dev seeds 1-7); verify file_sha256 before use"
109 fi
110 [ "$first" = 1 ] || printf ',\n'
111 first=0
112 printf ' {"name": "%s", "file": "%s.tym", "bytes": %s, "file_sha256": "%s", "model_digest": "%s", "K": %s, "key_bits": %s, "rows": %s, "lm_bits": %s, "location": "%s"}' \
113 "$n" "$n" "$bytes" "$fsha" "$mdig" "$K" "$kb" "$rows" "$lm" "$loc"
114 done
115 printf '\n ],\n "shared_background_sha256": {\n'
116 first=1
117 for p in src/turing/ty_model.c src/turing/ty_model.h src/turing/ty_ctr1.c src/turing/ty_ctr1.h \
118 src/turing/ty_math.c src/turing/ty_math.h calibration/docs/MODEL_DESCRIPTION_ENCODING.md \
119 calibration/docs/CODER_SPEC.md calibration/docs/UNCERTAINTY_PROTOCOL.md calibration/docs/FAILURE_REPORTING.md \
120 calibration/docs/BLINDING_PROTOCOL.md $EXP_PREREG \
121 $EXP_DIR/preregistration.json $EXP_PROFILE \
122 calibration/scripts/power_simulation.c $EXP_POWER \
123 calibration/docs/EVALUATOR.md calibration/docs/DATA_FORMAT.md \
124 tools/turing_cal_eval.c; do
125 if [ -f "$dir/$p" ]; then h=$(sha256sum "$dir/$p" | cut -c1-64); else h="MISSING"; fi
126 [ "$first" = 1 ] || printf ',\n'
127 first=0
128 printf ' "%s": "%s"' "$p" "$h"
129 done
130 printf '\n },\n "independent_scorer_source_sha256": "%s",\n' "$(sh "$dir/calibration/scripts/indep_source_digest.sh")"
131 printf ' "runtime_sha256": {\n'
132 rl=$(sh "$dir/calibration/scripts/runtime_digest.sh" --lines 2>/dev/null || true)
133 if [ -n "$rl" ]; then
134 printf '%s\n' "$rl" | sed 's/^\([0-9a-f]*\) \(.*\)$/ "\2": "\1",/'
135 printf ' "runtime_digest": "%s"' "$(printf '%s\n' "$rl" | sha256sum | cut -c1-64)"
136 else
137 printf ' "runtime_digest": "not computed (build all seven runtime binaries; see runtime_digest.sh)"'
138 fi
139 printf '\n }\n}\n'
140} > "$out.tmp"
141mv "$out.tmp" "$out"
142if [ "$freeze" = 1 ]; then
143 [ -z "$(grep MISSING "$out" || true)" ] || die "a shared-background file is missing; manifest left at $out for inspection"
144fi
145echo "freeze_candidate: wrote $out ($([ "$freeze" = 1 ] && echo frozen || echo draft))"