Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tools/estimation/est6dev.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tools / estimation / est6dev.c` 1121 lines ยท 60343 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* ESTIMATION v6 pre-freeze development analysis (docs/estimation/protocols/est-v6.md section 9 18 * items 1 and 4; appendix est-v6-appendix-prefreeze.md). NOT the v6 tool, not a result about any 19 * held-out data, and not a protocol tool: it changes no v5 threshold, parameter or receipt. 20 * 21 * est6dev g1pit --raw R --marks M --dyn D --q Q --lam L --nu N --c C [--boot B] [--seed S] [--blocks] 22 * One-step G1 (est_v4.c, the v5 code, unchanged) with the GIVEN parameters on one run folder. 23 * Prints the v5 statistics it must reproduce (n, PIT bin shares, coverage 50/80/95, mean z, 24 * lag-1 z), the lower and upper 2.5 % miss rates separately, and a block bootstrap over load 25 * segments (a block is one marked load segment, or one idle stretch between marked segments) 26 * giving standard errors, percentile intervals and the design effect against independent 27 * steps for every bin share and miss rate. 28 * est6dev sched 29 * The est_load schedule for a seed (same splitmix64 draw order as est_load.c) with per-level 30 * totals and the section 3 balance check (each of idle, L6, L12, L18 within 400..900 s). 31 * 32 * Refuses, before opening anything, any path that names a held-out run (v3, v4, v5 or v6 held-out 33 * tag) or the v5 D2 folder; after loading, refuses an input whose SHA-256 is the v5 D2 raw or marks SHA (committed d2.sha256). */ 34 #include 35 #include 36 #include 37 #include 38 #include 39 #include 40 41 #include "est3c_common.h" 42 #include "est_v4.h" 43 44 /* Allocation failure stops the tool with a message (no partial result is written). */ 45 static void *xalloc(void *p, const char *what) 46 { 47 if (!p) { fprintf(stderr, "est6dev: out of memory (%s)\n", what); exit(2); } 48 return p; 49 } 50 #define XMALLOC(n) xalloc(malloc(n), __func__) 51 #define XCALLOC(n, s) xalloc(calloc((n), (s)), __func__) 52 53 #define D2_DATE_TAG "20261005T112838Z" 54 #define D2_RAW_SHA "`7dda21f664587c4401326c3082f28039e133ba5627c8564678f259e2d7036ff0`" 55 #define D2_MARKS_SHA "`95879ed909b8fec1207695dc1093b24be56f00563cd364c62bd30007b0dc26bb`" 56 57 static uint64_t splitmix64(uint64_t *s) 58 { 59 uint64_t z = (*s += 0x9e3779b97f4a7c15ull); 60 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ull; 61 z = (z ^ (z >> 27)) * 0x94d049bb133111ebull; 62 return z ^ (z >> 31); 63 } 64 65 static int forbidden_path(const char *path) 66 { 67 static const char *tags[] = { "-heldout-", D2_DATE_TAG, "-est5-heldout", "-est4-heldout", "-est3c-heldout", "-est6-heldout", NULL }; 68 char rp[PATH_MAX]; 69 for (int i = 0; tags[i]; i++) { 70 if (strstr(path, tags[i])) return 1; 71 if (realpath(path, rp) && strstr(rp, tags[i])) return 1; 72 } 73 return 0; 74 } 75 76 /* ------------------------------------------------------------ schedule (item 4) */ 77 static int cmd_sched(int argc, char **argv) 78 { 79 if (argc != 2) { fprintf(stderr, "usage: est6dev sched \n"); return 2; } 80 uint64_t seed = strtoull(argv[0], NULL, 0); 81 long total = strtol(argv[1], NULL, 10); 82 if (total <= 0) { fprintf(stderr, "seconds must be > 0\n"); return 2; } 83 static const int levels[4] = { 0, 6, 12, 18 }; 84 long secs_by_level[4] = { 0, 0, 0, 0 }; 85 long acc = 0; int n = 0; 86 uint64_t s = seed; 87 printf("seed %llu seconds %ld\n", (unsigned long long)seed, total); 88 while (acc < total && n < 4096) { 89 int li = (int)(splitmix64(&s) % 4u); 90 long d = 20 + (long)(splitmix64(&s) % 101u); 91 if (acc + d > total) d = total - acc; 92 printf("schedule %d %d %ld\n", n, levels[li], d); 93 secs_by_level[li] += d; acc += d; n++; 94 } 95 int ok = 1; 96 for (int i = 0; i < 4; i++) if (secs_by_level[i] < 400 || secs_by_level[i] > 900) ok = 0; 97 printf("segments %d idle %ld L6 %ld L12 %ld L18 %ld\n", n, secs_by_level[0], secs_by_level[1], secs_by_level[2], secs_by_level[3]); 98 printf("balance %s\n", ok ? "PASS" : "FAIL"); 99 return 0; 100 } 101 102 /* first seed at or after (step +1) whose schedule passes the section 3 balance rule */ 103 static int balance_ok(uint64_t seed, long total, long lv[4], int *nseg) 104 { 105 static const int levels[4] = { 0, 6, 12, 18 }; 106 uint64_t s = seed; long acc = 0; int n = 0, ok = 1; 107 for (int i = 0; i < 4; i++) lv[i] = 0; 108 while (acc < total && n < 4096) { 109 int li = (int)(splitmix64(&s) % 4u); 110 long d = 20 + (long)(splitmix64(&s) % 101u); 111 if (acc + d > total) d = total - acc; 112 lv[li] += d; acc += d; n++; 113 } 114 (void)levels; 115 for (int i = 0; i < 4; i++) if (lv[i] < 400 || lv[i] > 900) ok = 0; 116 *nseg = n; 117 return ok; 118 } 119 120 static int cmd_pick(int argc, char **argv) 121 { 122 if (argc != 2) { fprintf(stderr, "usage: est6dev pick \n"); return 2; } 123 uint64_t seed = strtoull(argv[0], NULL, 0); 124 long total = strtol(argv[1], NULL, 10), lv[4]; int ns; 125 for (int k = 0; k < 100000; k++) { 126 int ok = balance_ok(seed + (uint64_t)k, total, lv, &ns); 127 printf("seed 0x%llx segments %d idle %ld L6 %ld L12 %ld L18 %ld balance %s\n", (unsigned long long)(seed + (uint64_t)k), ns, lv[0], lv[1], lv[2], lv[3], ok ? "PASS" : "FAIL"); 128 if (ok) { printf("picked 0x%llx after %d failures\n", (unsigned long long)(seed + (uint64_t)k), k); return 0; } 129 } 130 printf("none found\n"); 131 return 1; 132 } 133 134 135 /* ------------------------------------------------------------ schedule rule SR-1 (domain separated) 136 * est-v6 section 3 as proposed chains "seed + 1" from each declared seed, which sends H1 (0xD6E6C7) and 137 * H2 (0xD6E6C8) to the same seed 0xD6E6CB (appendix section 3). Rule SR-1 removes that: 138 * base(label, declared) = splitmix64 output of the state declared XOR fnv1a64("est6-sched-v1/" label) 139 * candidate k = base + k (k = 0, 1, 2, ...) 140 * effective seed = first candidate whose est_load schedule passes the balance rule, k <= SR1_MAXK 141 * The label is part of the derivation input, so two labels never share a chain. The balance rule is a 142 * property of the schedule alone (no data); the search is bounded and fails closed. A plan with two 143 * identical schedules (or seeds) is refused, never repaired by further search. */ 144 #define SR1_MAXK 255 145 #define SEGMAX 4096 146 typedef struct { int level[SEGMAX]; long dur[SEGMAX]; int n; long lv[4]; long total; } sched_t; 147 148 static uint64_t fnv1a64(const char *s) 149 { 150 uint64_t h = 0xcbf29ce484222325ull; 151 for (; *s; s++) { h ^= (unsigned char)*s; h *= 0x100000001b3ull; } 152 return h; 153 } 154 155 static void gen_sched(uint64_t seed, long total, sched_t *o) 156 { 157 static const int levels[4] = { 0, 6, 12, 18 }; 158 uint64_t s = seed; long acc = 0; 159 memset(o, 0, sizeof *o); 160 while (acc < total && o->n < SEGMAX) { 161 int li = (int)(splitmix64(&s) % 4u); 162 long d = 20 + (long)(splitmix64(&s) % 101u); 163 if (acc + d > total) d = total - acc; 164 o->level[o->n] = levels[li]; o->dur[o->n] = d; o->lv[li] += d; acc += d; o->n++; 165 } 166 o->total = acc; 167 } 168 169 /* required properties: segments sum to the run length; every segment is 20..120 s except a clipped last 170 * one (1..120); each of idle, L6, L12, L18 totals 400..900 s */ 171 static int sched_props(const sched_t *o, long total, int *balanced) 172 { 173 long sum = 0; int ok = 1; 174 for (int i = 0; i < o->n; i++) { 175 sum += o->dur[i]; 176 if (o->dur[i] > 120 || o->dur[i] < 1) ok = 0; 177 if (o->dur[i] < 20 && i != o->n - 1) ok = 0; 178 } 179 if (sum != total || o->n >= SEGMAX) ok = 0; 180 *balanced = 1; 181 for (int i = 0; i < 4; i++) if (o->lv[i] < 400 || o->lv[i] > 900) *balanced = 0; 182 return ok; 183 } 184 185 static uint64_t sr1_base(const char *label, uint64_t declared) 186 { 187 char buf[128 + 32]; 188 snprintf(buf, sizeof buf, "est6-sched-v1/%.100s", label); 189 uint64_t st = declared ^ fnv1a64(buf); 190 return splitmix64(&st); 191 } 192 193 /* rule 0 = old (v6 proposal: declared + k), rule 1 = SR-1. Returns k or -1. */ 194 static int sr_pick(int rule, const char *label, uint64_t declared, long total, uint64_t *eff, sched_t *o) 195 { 196 uint64_t base = rule ? sr1_base(label, declared) : declared; 197 for (int k = 0; k <= (rule ? SR1_MAXK : 100000); k++) { 198 int bal; 199 gen_sched(base + (uint64_t)k, total, o); 200 if (sched_props(o, total, &bal) && bal) { *eff = base + (uint64_t)k; return k; } 201 } 202 return -1; 203 } 204 205 static int same_sched(const sched_t *a, const sched_t *b) 206 { 207 if (a->n != b->n) return 0; 208 for (int i = 0; i < a->n; i++) if (a->level[i] != b->level[i] || a->dur[i] != b->dur[i]) return 0; 209 return 1; 210 } 211 212 /* est6dev plan6 [--rule old|sr1]