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
omega-mv / calibration / scripts / check_profile.sh
| 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 | # check_profile.sh: the experiment profile (EXP_ID, default EXP-001: Turing-profile-v1.0.toml; EXP-001R: v1.1) must agree with the code it describes. |
| 18 | # |
| 19 | # TXA_CAND=build/turing-exp001-a/turing-cal-candidates sh calibration/scripts/check_profile.sh [--freeze] |
| 20 | # |
| 21 | # Checks (any failure exits 1): |
| 22 | # 1. format: every non-comment, non-blank line is `key = value`; keys unique; no em or en dashes |
| 23 | # 2. every field the brief requires is present (46 names) |
| 24 | # 3. values equal the C constants printed by `turing-cal-candidates consts` (compiled from |
| 25 | # src/turing/ty_math.h, ty_model.h, ty_ctr1.h): K, qbits, 65536, floor, header bits, version, |
| 26 | # digest domain, micro-bit unit, error bound, CTR1 record size, depth clip, SUBMIT op value, |
| 27 | # masks and model digests of B2 / M_candidate |
| 28 | # 4. L(M) fields equal 232 + rows x (keybits + 128) for B3 (16 rows, 4 key bits) |
| 29 | # 5. optional cross-checks when the files exist: candidates printout (TXA_CANDIDATES) L(M) values, |
| 30 | # power simulation output (CHOSEN_SEEDS_PER_GROUP == sealed_seeds_per_group) |
| 31 | # 5b. lanes B and C: coder_spec_sha256 = SHA-256 of CODER_SPEC.md; TPS1 profile digest at offset 28; envelope |
| 32 | # 448 / 64 / 1.0e-3 two-sided as in CODER_SPEC section 9; TCR1 range and TCA1 rANS L = 2^23; 56-byte header; |
| 33 | # crumbs and learner SHA-256 equal the pins in generate_sealed_data.sh; LINEAGE NOTE in profile and prereg; |
| 34 | # blinding states the temporal layer and the same-uid limit; runtime_digest.sh exists |
| 35 | # 6. profile_digest is the literal "SIDECAR"; outside comments, FILL_AT_FREEZE may appear only in runtime_digest |
| 36 | # --freeze also: no FILL_AT_FREEZE marker, the .sha256 sidecar matches the file bytes, and runtime_digest equals |
| 37 | # the output of runtime_digest.sh. |
| 38 | # No Python. POSIX sh + sed + grep + sha256sum. |
| 39 | set -eu |
| 40 | dir=$(cd "$(dirname "$0")/../.." && pwd) |
| 41 | . "$dir/calibration/scripts/tc_exp.sh" |
| 42 | toml="$dir/$EXP_PROFILE" |
| 43 | side="$dir/$EXP_SIDECAR" |
| 44 | cand="${TXA_CAND:-$dir/build/turing-exp001-a/turing-cal-candidates}" |
| 45 | cands="${TXA_CANDIDATES:-$dir/calibration/experiments/EXP-001/candidates_dev.txt}" |
| 46 | power="${TXA_POWER_OUT:-$dir/calibration/experiments/EXP-001/power_simulation_output.txt}" |
| 47 | freeze=0 |
| 48 | [ "${1:-}" = "--freeze" ] && freeze=1 |
| 49 | fails=0 |
| 50 | bad() { echo "check_profile: FAIL: $*"; fails=$((fails + 1)); } |
| 51 | |
| 52 | [ -f "$toml" ] || { echo "check_profile: FAIL: $toml missing"; exit 1; } |
| 53 | [ -x "$cand" ] || { echo "check_profile: FAIL: $cand not built (make turing-exp001-a-build)"; exit 1; } |
| 54 | |
| 55 | # 1. format |
| 56 | nonkv=$(grep -v '^[[:space:]]*#' "$toml" | grep -v '^[[:space:]]*$' | grep -cv '^[a-z][a-z0-9_A-Z]* = ' || true) |
| 57 | [ "$nonkv" = 0 ] || bad "$nonkv lines are not flat 'key = value'" |
| 58 | dups=$(sed -n 's/^\([a-z][a-z0-9_A-Z]*\) = .*/\1/p' "$toml" | sort | uniq -d) |
| 59 | [ -z "$dups" ] || bad "duplicate keys: $dups" |
| 60 | if grep -q "$(printf '\342\200\224')\|$(printf '\342\200\223')" "$toml"; then bad "em or en dash in profile"; fi |
| 61 | |
| 62 | val() { sed -n "s/^$1 = //p" "$toml" | head -1 | sed 's/^"\(.*\)"$/\1/'; } |
| 63 | |
| 64 | # 2. required fields (brief, PROMPT 0) |
| 65 | for k in profile_id profile_version profile_digest task_definition baseline_family baseline_encoding \ |
| 66 | candidate_encoding_rules shared_background_definition model_description_language model_serialization \ |
| 67 | model_cost_method dataset_generator development_split calibration_split sealed_test_split \ |
| 68 | test_generation_seed_commitment holdout_commitment blinding_method probability_representation \ |
| 69 | probability_quantization zero_probability_policy normalization_policy ideal_codelength_method \ |
| 70 | reference_coder_1 reference_coder_2 coder_termination_convention coder_header_accounting \ |
| 71 | coder_metadata_accounting uncertainty_method correlation_handling block_resampling_policy \ |
| 72 | number_of_replicates number_of_trajectories trajectory_length stopping_rule energy_instrumentation \ |
| 73 | idle_baseline_method energy_attribution_method software_versions compiler_versions runtime_digest \ |
| 74 | hardware_identity independent_verification_requirements baseline_sensitivity_plan \ |
| 75 | model_code_sensitivity_plan overlap_audit failure_reporting_policy \ |
| 76 | lm_free_background lm_free_constants lm_charged_constants lm_learned_parameters lm_parameter_precision \ |
| 77 | lm_structural_metadata lm_dependencies lm_lookup_tables lm_embedded_datasets lm_generated_code \ |
| 78 | lm_external_artifacts lm_model_headers lm_version_info sealed_seeds_per_group sealed_groups; do |
| 79 | grep -q "^$k = " "$toml" || bad "required field $k missing" |
| 80 | done |
| 81 | nreq=46 |
| 82 | |
| 83 | # 3. constants |
| 84 | consts=$("$cand" consts) |
| 85 | c() { printf '%s\n' "$consts" | sed -n "s/^$1=//p"; } |
| 86 | eq() { # toml_key const_name |
| 87 | tv=$(val "$1"); cv=$(c "$2") |
| 88 | [ -n "$cv" ] || { bad "no constant $2"; return; } |
| 89 | [ "$tv" = "$cv" ] || bad "$1 = '$tv' but code has $2 = '$cv'" |
| 90 | } |
| 91 | eq alphabet_size_K K |
| 92 | eq probability_qbits qbits |
| 93 | eq probability_total qone |
| 94 | eq probability_floor floor_q |
| 95 | eq model_header_bits model_header_bits |
| 96 | eq model_code_version model_version |
| 97 | eq model_digest_domain model_domain |
| 98 | eq ub_per_bit ub_per_bit |
| 99 | eq qerr_milli_ub_per_symbol qerr_milli_ub_per_symbol |
| 100 | eq ctr1_record_bytes ctr1_record_bytes |
| 101 | eq depth_clip depth_clip |
| 102 | eq op_submit_value op_submit |
| 103 | eq baseline_b2_mask b2_mask |
| 104 | eq candidate_m_candidate_mask m_candidate_mask |
| 105 | eq candidate_m_mem_mask m_mem_mask |
| 106 | eq candidate_b3_mask b3_mask |
| 107 | eq baseline_b2_model_digest b2_digest |
| 108 | eq candidate_m_candidate_model_digest m_candidate_digest |
| 109 | [ "$(val profile_digest)" = "SIDECAR" ] || bad "profile_digest must be the literal SIDECAR" |
| 110 | [ "$(val profile_id)" = "$EXP_PROFILE_ID" ] || bad "profile_id" |
| 111 | |
| 112 | # 4. L(M) formula for B3: 104 + 16(K-1) + 16 rows x (keybits + 16(K-1)) |
| 113 | K=$(c K); hb=$(c model_header_bits); qb=$(c qbits); kb=$(c b3_keybits) |
| 114 | b3=$((hb + qb * (K - 1) + 16 * (kb + qb * (K - 1)))) |
| 115 | [ "$(val candidate_b3_lm_bits)" = "$b3" ] || bad "candidate_b3_lm_bits != $b3" |
| 116 | if ! grep -q "^lm_formula = \"L(M) = $hb + 16(K-1)" "$toml"; then bad "lm_formula header term != $hb"; fi |
| 117 | |
| 118 | # 5. optional cross-checks |
| 119 | if [ -f "$cands" ]; then |
| 120 | lm() { sed -n "s/^$1 .* lm_bits=\([0-9]*\) .*/\1/p" "$cands"; } |
| 121 | [ "$(lm B2_order1)" = "$(val baseline_b2_lm_bits)" ] || bad "B2 L(M) differs from $cands" |
| 122 | [ "$(lm M_candidate)" = "$(val candidate_m_candidate_lm_bits)" ] || bad "M_candidate L(M) differs" |
| 123 | [ "$(lm M_mem)" = "$(val candidate_m_mem_lm_bits)" ] || bad "M_mem L(M) differs" |
| 124 | [ "$(lm M_mem_seed1)" = "$(val candidate_m_mem_seed1_lm_bits)" ] || bad "M_mem_seed1 L(M) differs" |
| 125 | [ "$(lm B3_heuristic)" = "$(val candidate_b3_lm_bits)" ] || bad "B3 L(M) differs" |
| 126 | else |
| 127 | echo "check_profile: note: $cands absent, candidate L(M) cross-check skipped" |
| 128 | fi |
| 129 | if [ -f "$power" ]; then |
| 130 | pn=$(sed -n 's/^CHOSEN_SEEDS_PER_GROUP=\([0-9]*\).*/\1/p' "$power") |
| 131 | [ "$pn" = "$(val sealed_seeds_per_group)" ] || bad "sealed_seeds_per_group != power simulation choice ($pn)" |
| 132 | else |
| 133 | echo "check_profile: note: $power absent, sample-size cross-check skipped" |
| 134 | fi |
| 135 | |
| 136 | |
| 137 | # 5b. lanes B and C, integration fields (EXP-001) |
| 138 | for k in coder_spec_path coder_tool coder_header_bits coder_overhead_definition coder_envelope_center_bits \ |
| 139 | coder_envelope_a_bits coder_envelope_b_ub_per_symbol coder_envelope_units coder_envelope_basis \ |
| 140 | probability_stream_format probability_stream_profile_digest_offset probability_stream_model_digest_rule \ |
| 141 | probability_stream_dataset_digest_rule dataset_generator_command dataset_generator_learner_sha256 \ |
| 142 | dataset_generator_lineage_records_differing_seed1 dataset_generator_lineage_records_seed1 \ |
| 143 | blinding_protocol_path blinding_separate_sealed_user runtime_digest_rule candidate_memorizer_decision \ |
| 144 | candidate_large_artifacts; do |
| 145 | grep -q "^$k = " "$toml" || bad "integration field $k missing" |
| 146 | done |
| 147 | # 5c. calibration protocol field names (docs/turing/protocols calibration protocol lines 155-277), plus the verdict rule |
| 148 | T="$dir/docs/turing/protocols/turing-instrument-calibration-validation-protocol-v1-0.tex" |
| 149 | if [ -f "$T" ]; then |
| 150 | for k in $(awk 'NR>=155 && NR<=277' "$T" | grep -E '^[a-zA-Z_]+$'); do |
| 151 | grep -q "^$k = " "$toml" || bad "protocol field $k missing" |
| 152 | done |
| 153 | else |
| 154 | bad "calibration protocol $T missing" |
| 155 | fi |
| 156 | grep -q "^verdict_inconclusive_trigger = " "$toml" || bad "verdict_inconclusive_trigger missing" |
| 157 | spec="$dir/$(val coder_spec_path)" |
| 158 | if [ -f "$spec" ]; then |
| 159 | [ "$(val coder_spec_sha256)" = "$(sha256sum "$spec" | cut -c1-64)" ] || bad "coder_spec_sha256 != SHA-256 of $spec" |
| 160 | grep -q '^| 28 | 32 | profile_digest |' "$spec" || bad "CODER_SPEC TPS1 profile_digest not at offset 28" |
| 161 | [ "$(val probability_stream_profile_digest_offset)" = 28 ] || bad "probability_stream_profile_digest_offset != 28" |
| 162 | grep -q 'overhead - 448 | <= 64 + 1.0e-3 x N' "$spec" || bad "CODER_SPEC envelope differs from 448 / 64 / 1.0e-3" |
| 163 | grep -q 'Constants: L = 2^23' "$spec" || bad "CODER_SPEC rANS L is not 2^23" |
| 164 | grep -q 'header (56 bytes)' "$spec" || bad "CODER_SPEC coded header is not 56 bytes" |
| 165 | else |
| 166 | bad "coder spec $spec missing" |
| 167 | fi |
| 168 | [ "$(val coder_header_bits)" = 448 ] || bad "coder_header_bits != 448 (56 bytes)" |
| 169 | [ "$(val coder_envelope_center_bits)" = "$(val coder_header_bits)" ] || bad "envelope center != header bits" |
| 170 | [ "$(val coder_envelope_a_bits)" = 64 ] || bad "coder_envelope_a_bits != 64" |
| 171 | [ "$(val coder_envelope_b_ub_per_symbol)" = 1000 ] || bad "coder_envelope_b_ub_per_symbol != 1000 (1.0e-3 bits)" |
| 172 | case "$(val coder_envelope)" in TWO-SIDED*) ;; *) bad "coder_envelope must be TWO-SIDED" ;; esac |
| 173 | case "$(val reference_coder_1)" in "TCR1 v1 range"*) ;; *) bad "reference_coder_1 is not TCR1 v1 range" ;; esac |
| 174 | case "$(val reference_coder_2)" in "TCA1 v1 rANS"*"L = 2^23"*) ;; *) bad "reference_coder_2 is not TCA1 v1 rANS, L = 2^23" ;; esac |
| 175 | gen="$dir/calibration/scripts/generate_sealed_data.sh" |
| 176 | pin() { grep "^$1=" "$gen" | head -1 | grep -o '[0-9a-f]\{64\}'; } |
| 177 | if [ -f "$gen" ]; then |
| 178 | [ "$(val dataset_generator_crumbs_sha256)" = "$(pin CRUMBS_SHA256)" ] || bad "crumbs SHA-256 differs from generate_sealed_data.sh" |
| 179 | [ "$(val dataset_generator_learner_sha256)" = "$(pin LEARNER_SHA256)" ] || bad "learner SHA-256 differs from generate_sealed_data.sh" |
| 180 | grep -q 'sealed_seeds_per_group' "$gen" || bad "generate_sealed_data.sh does not read sealed_seeds_per_group" |
| 181 | else |
| 182 | bad "$gen missing" |
| 183 | fi |
| 184 | [ "$(val dataset_generator_command)" = "crumbs experiment --learner L --seed S --out DIR" ] || bad "dataset_generator_command" |
| 185 | case "$(val dataset_generator)" in *"LINEAGE NOTE"*) ;; *) bad "dataset_generator lacks the LINEAGE NOTE" ;; esac |
| 186 | grep -q 'LINEAGE NOTE' "$dir/$EXP_PREREG" || bad "prereg lacks the LINEAGE NOTE" |
| 187 | [ -f "$dir/$(val blinding_protocol_path)" ] || bad "blinding protocol missing" |
| 188 | [ "$(val blinding_separate_sealed_user)" = no ] || bad "blinding_separate_sealed_user must be no" |
| 189 | case "$(val blinding_method)" in *"temporal"*"same user id"*) ;; *) bad "blinding_method must state the temporal layer and the same-uid limit" ;; esac |
| 190 | [ -f "$dir/calibration/scripts/runtime_digest.sh" ] || bad "runtime_digest.sh missing" |
| 191 | |
| 192 | # 6. freeze mode |
| 193 | nfill=$(grep -v "^[[:space:]]*#" "$toml" | grep -c "FILL_AT_FREEZE" || true) |
| 194 | other=$(grep -v "^[[:space:]]*#" "$toml" | grep "FILL_AT_FREEZE" | grep -v "^runtime_digest = " || true) |
| 195 | [ -z "$other" ] || bad "FILL_AT_FREEZE outside runtime_digest: $(printf "%s" "$other" | cut -c1-60)" |
| 196 | if [ "$freeze" = 1 ]; then |
| 197 | [ "$nfill" = 0 ] || bad "$nfill FILL_AT_FREEZE markers remain" |
| 198 | [ -f "$side" ] || bad "sidecar $side missing" |
| 199 | if [ -f "$side" ]; then |
| 200 | want=$(cut -c1-64 "$side"); got=$(sha256sum "$toml" | cut -c1-64) |
| 201 | [ "$want" = "$got" ] || bad "sidecar $want != sha256 of profile bytes $got" |
| 202 | fi |
| 203 | rd=$(sh "$dir/calibration/scripts/runtime_digest.sh" 2>&1) || bad "runtime_digest.sh: $rd" |
| 204 | [ "$(val runtime_digest)" = "$rd" ] || bad "runtime_digest != runtime_digest.sh output $rd" |
| 205 | fi |
| 206 | |
| 207 | if [ "$fails" -ne 0 ]; then |
| 208 | echo "check_profile: $fails failure(s)" |
| 209 | exit 1 |
| 210 | fi |
| 211 | echo "check_profile: OK ($nreq required fields + L(M) fields present, constants match code, $nfill FILL_AT_FREEZE markers$([ "$freeze" = 1 ] && echo ', freeze mode, sidecar matches'))" |