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 / tools / turing_yield.om

505 lines · 9311 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note
4note tools/turing_yield.om -- Pure seeded OM-2 Turing Yield TY-2 driver
5note Composed with src/turing/ty_core_lib.om.
6note Supports: fixture, manifest-check, profile, tune, loso, heldout, verify.
7
8text t_cmd_fix "fixture"
9text t_cmd_prof "profile"
10text t_cmd_mchk "manifest-check"
11text t_cmd_tune "tune"
12text t_cmd_loso "loso"
13text t_usage "usage: turing-yield manifest-check|profile|tune|loso|fixture ...\n"
14
15text t_r0 "uniform"
16text t_r1 "order-0"
17text t_r2 "order-1"
18text t_r3 "op-only"
19text t_r4 "op+prev1"
20text t_r5 "op+prev1..2"
21text t_r6 "op+prev1..3"
22text t_r7 "op+prev1..4"
23text t_r8 "op+prev1..5"
24text t_r9 "op+depth+prev1"
25text t_r10 "op+depth+prev1..2"
26text t_r11 "op+depth+prev1..3"
27text t_r12 "op+depth+prev1..4"
28text t_r13 "op+depth+prev1..5"
29text t_r14 "memorizer"
30
31text t_ff1 "fixture fit "
32text t_ff2 " events "
33text t_ff3 " crumbs; held "
34text t_ff4 " crumbs\n"
35text t_fl1 " rows="
36text t_fl2 " lm_bits="
37text t_fl3 " ld_fit_ub="
38text t_fl4 " ld_held_ub="
39text t_fl5 " model="
40text t_pm1 "manifest_sha256="
41text t_pm2 "profile="
42text t_pm3 "split="
43text t_pm4 "baseline_mask="
44text t_pm5 "candidate_mask="
45text t_pm6 "margin_ub="
46text t_ok_p "OK "
47text t_fl_p "FAIL "
48text t_recs " records="
49
50global g_a1 uchar 64
51global g_a2 uchar 512
52global g_a3 uchar 512
53global g_obuf uchar 4096
54global g_olen ulong 1
55global g_mbuf uchar 16384
56global g_m_rel uchar 2560
57global g_m_rlen ulong 10
58global g_m_path uchar 5120
59global g_m_plen ulong 10
60global g_m_sz ulong 10
61
62fn ob_clr to void
63 put g_olen 0 0
64end
65
66fn ob_b c uchar to void
67 n = get g_olen 0
68 if lt n 4096
69 put g_obuf n c
70 put g_olen 0 add n 1
71 end
72end
73
74fn ob_txt s view uchar * to void
75 n = len s
76 for i ulong n bound 256
77 ob_b get s i
78 end
79end
80
81fn ob_u64 v ulong to void
82 tv_clr
83 tv_u64 v
84 n = get g_tvl 0
85 for i ulong n bound 32
86 ob_b get g_tv i
87 end
88end
89
90fn ob_i64 v long to void
91 tv_clr
92 tv_i64 v
93 n = get g_tvl 0
94 for i ulong n bound 32
95 ob_b get g_tv i
96 end
97end
98
99fn ob_dig slot ulong to void
100 tv_clr
101 tv_dig slot
102 for i ulong 64
103 ob_b get g_tv i
104 end
105end
106
107fn ob_flush to void
108 n = get g_olen 0
109 if gt n 0
110 w = write 1 g_obuf 0 n
111 put g_olen 0 0
112 end
113end
114
115fn a1_eq_txt alen ulong t view uchar * to bool
116 if ne alen len t
117 ret false
118 end
119 for i ulong alen bound 64
120 if ne get g_a1 i get t i
121 ret false
122 end
123 end
124 ret true
125end
126
127fn ob_rung_name k ulong to void
128 n = ulong 0
129 if eq k 0
130 ob_txt t_r0
131 n = len t_r0
132 end
133 if eq k 1
134 ob_txt t_r1
135 n = len t_r1
136 end
137 if eq k 2
138 ob_txt t_r2
139 n = len t_r2
140 end
141 if eq k 3
142 ob_txt t_r3
143 n = len t_r3
144 end
145 if eq k 4
146 ob_txt t_r4
147 n = len t_r4
148 end
149 if eq k 5
150 ob_txt t_r5
151 n = len t_r5
152 end
153 if eq k 6
154 ob_txt t_r6
155 n = len t_r6
156 end
157 if eq k 7
158 ob_txt t_r7
159 n = len t_r7
160 end
161 if eq k 8
162 ob_txt t_r8
163 n = len t_r8
164 end
165 if eq k 9
166 ob_txt t_r9
167 n = len t_r9
168 end
169 if eq k 10
170 ob_txt t_r10
171 n = len t_r10
172 end
173 if eq k 11
174 ob_txt t_r11
175 n = len t_r11
176 end
177 if eq k 12
178 ob_txt t_r12
179 n = len t_r12
180 end
181 if eq k 13
182 ob_txt t_r13
183 n = len t_r13
184 end
185 if eq k 14
186 ob_txt t_r14
187 n = len t_r14
188 end
189 while lt n 28 bound 32
190 ob_b uchar 32
191 n = add n 1
192 end
193end
194
195fn rung_mask k ulong to ulong
196 if eq k 2
197 ret TY_F_PREV1
198 end
199 if eq k 3
200 ret TY_F_OP
201 end
202 if eq k 4
203 ret or TY_F_OP TY_F_PREV1
204 end
205 if eq k 5
206 ret or or TY_F_OP TY_F_PREV1 TY_F_PREV2
207 end
208 if eq k 6
209 ret or or or TY_F_OP TY_F_PREV1 TY_F_PREV2 TY_F_PREV3
210 end
211 if eq k 7
212 ret or or or or TY_F_OP TY_F_PREV1 TY_F_PREV2 TY_F_PREV3 TY_F_PREV4
213 end
214 if eq k 8
215 ret or or or or or TY_F_OP TY_F_PREV1 TY_F_PREV2 TY_F_PREV3 TY_F_PREV4 TY_F_PREV5
216 end
217 if eq k 9
218 ret or or TY_F_OP TY_F_DEPTH TY_F_PREV1
219 end
220 if eq k 10
221 ret or or or TY_F_OP TY_F_DEPTH TY_F_PREV1 TY_F_PREV2
222 end
223 if eq k 11
224 ret or or or or TY_F_OP TY_F_DEPTH TY_F_PREV1 TY_F_PREV2 TY_F_PREV3
225 end
226 if eq k 12
227 ret or or or or or TY_F_OP TY_F_DEPTH TY_F_PREV1 TY_F_PREV2 TY_F_PREV3 TY_F_PREV4
228 end
229 if eq k 13
230 ret or or or or or or TY_F_OP TY_F_DEPTH TY_F_PREV1 TY_F_PREV2 TY_F_PREV3 TY_F_PREV4 TY_F_PREV5
231 end
232 if eq k 14
233 ret TY_F_POS
234 end
235 ret 0
236end
237
238fn cmd_fixture l2 ulong l3 ulong to int
239 st_reset_all
240 st_begin 0
241 for i ulong l2 bound 512
242 put g_path i get g_a2 i
243 end
244 put g_plen 0 l2
245 if lt ty_ctr1_read_gp 0 0
246 ret 2
247 end
248 st_begin 1
249 for i ulong l3 bound 512
250 put g_path i get g_a3 i
251 end
252 put g_plen 0 l3
253 if lt ty_ctr1_read_gp 1 0
254 ret 2
255 end
256 ob_clr
257 ob_txt t_ff1
258 ob_u64 get g_st_n 0
259 ob_txt t_ff2
260 ob_u64 get g_st_ncr 0
261 ob_txt t_ff3
262 ob_u64 get g_st_n 1
263 ob_txt t_ff2
264 ob_u64 get g_st_ncr 1
265 ob_txt t_ff4
266 ob_flush
267 put g_fit_sids 0 0
268 for k ulong 15
269 rc = TY_OK
270 if eq k 0
271 rc = ty_model_uniform 0 TY_OUT_K
272 else
273 rule = TY_FIT_MDL_PRUNE
274 if eq k 14
275 rule = TY_FIT_KEEP_ALL
276 end
277 rc = ty_model_fit 0 1 rung_mask k TY_OUT_K rule
278 end
279 if ne rc TY_OK
280 ret 2
281 end
282 rc = ty_model_encode 0 0
283 if ne rc TY_OK
284 ret 2
285 end
286 nb = get g_mclen 0
287 lm = get g_mcbits 0
288 rc = ty_model_score 0 0
289 if ne rc TY_OK
290 ret 2
291 end
292 in_ub = get g_ty_ret_i 0
293 rc = ty_model_score 0 1
294 if ne rc TY_OK
295 ret 2
296 end
297 out_ub = get g_ty_ret_i 0
298 ty_model_digest 0 nb 0
299 ob_clr
300 ob_rung_name k
301 ob_txt t_fl1
302 ob_u64 get g_md_nr 0
303 ob_txt t_fl2
304 ob_u64 lm
305 ob_txt t_fl3
306 ob_i64 in_ub
307 ob_txt t_fl4
308 ob_i64 out_ub
309 ob_txt t_fl5
310 ob_dig 0
311 ob_b uchar 10
312 ob_flush
313 end
314 ret 0
315end
316
317fn store_manifest_paths p ulong rlen ulong n ulong rl ulong to void
318 ro = mul n 256
319 for i ulong rlen bound 256
320 put g_m_rel add ro i get g_mbuf add p i
321 end
322 put g_m_rlen n rlen
323 po = mul n 512
324 for i ulong rl bound 512
325 put g_m_path add po i get g_a3 i
326 end
327 put g_m_path add po rl uchar 47
328 po1 = add add po rl 1
329 for i ulong rlen bound 256
330 put g_m_path add po1 i get g_m_rel add ro i
331 end
332 put g_m_plen n add add rl 1 rlen
333end
334
335fn parse_manifest_line ls ulong le_p ulong n ulong rl ulong to long
336 h = new uchar 64 0
337 if lt sub le_p ls 66
338 ret TY_E_FORMAT
339 end
340 for i ulong 64
341 put h i get g_mbuf add ls i
342 end
343 if ne dg_parse_hex h 64 n TY_OK
344 ret TY_E_FORMAT
345 end
346 p = add ls 64
347 while lt p le_p bound 16
348 if ne get g_mbuf p uchar 32
349 break
350 end
351 p = add p 1
352 end
353 sz = ulong 0
354 while lt p le_p bound 32
355 b = get g_mbuf p
356 if or lt b uchar 48 gt b uchar 57
357 break
358 end
359 sz = add mul sz 10 ulong sub b uchar 48
360 p = add p 1
361 end
362 put g_m_sz n sz
363 while lt p le_p bound 16
364 if ne get g_mbuf p uchar 32
365 break
366 end
367 p = add p 1
368 end
369 rlen = sub le_p p
370 if or eq rlen 0 gt rlen 255
371 ret TY_E_FORMAT
372 end
373 store_manifest_paths p rlen n rl
374 ret TY_OK
375end
376
377fn load_manifest ml ulong rl ulong to long
378 fd = fopen g_a2 0 ml int 0 int 0
379 if lt fd 0
380 ret TY_E_IO
381 end
382 k = read int fd g_mbuf 0 16384
383 dc = fclose int fd
384 if le k 0
385 ret TY_E_IO
386 end
387 blen = ulong k
388 pos = ulong 0
389 n = ulong 0
390 while and lt pos blen lt n 10 bound 200
391 ls = pos
392 while lt pos blen bound 2000
393 if eq get g_mbuf pos uchar 10
394 break
395 end
396 pos = add pos 1
397 end
398 le_p = pos
399 if lt pos blen
400 pos = add pos 1
401 end
402 if eq ls le_p
403 continue
404 end
405 if eq get g_mbuf ls uchar 35
406 continue
407 end
408 rc = parse_manifest_line ls le_p n rl
409 if ne rc TY_OK
410 ret rc
411 end
412 n = add n 1
413 end
414 if ne n 10
415 ret TY_E_FORMAT
416 end
417 for i ulong ml bound 512
418 put g_path i get g_a2 i
419 end
420 put g_plen 0 ml
421 ret ty_file_sha256_gp 15
422end
423
424fn cmd_profile to int
425 rc = ty_profile_v0_digest 15 1 16
426 put g_sp_nf 0 7
427 put g_sp_nh 0 3
428 for i ulong 7
429 put g_sp_fdig i i
430 ro = mul i 256
431 rl = get g_m_rlen i
432 if gt rl 63
433 rl = 63
434 end
435 lo = mul i 64
436 for j ulong rl bound 64
437 put g_sp_flbl add lo j get g_m_rel add ro j
438 end
439 put g_sp_flen i rl
440 end
441 for i ulong 3
442 si = add i 7
443 put g_sp_hdig i si
444 ro = mul si 256
445 rl = get g_m_rlen si
446 if gt rl 63
447 rl = 63
448 end
449 lo = mul i 64
450 for j ulong rl bound 64
451 put g_sp_hlbl add lo j get g_m_rel add ro j
452 end
453 put g_sp_hlen i rl
454 end
455 rc = ty_split_digest 17
456 ob_clr
457 ob_txt t_pm1
458 ob_dig 15
459 ob_b uchar 10
460 ob_txt t_pm2
461 ob_dig 16
462 ob_b uchar 10
463 ob_txt t_pm3
464 ob_dig 17
465 ob_b uchar 10
466 ob_txt t_pm4
467 ob_u64 TY_V0_BASELINE_MASK
468 ob_b uchar 10
469 ob_txt t_pm5
470 ob_u64 TY_V0_CANDIDATE_MASK
471 ob_b uchar 10
472 ob_txt t_pm6
473 ob_i64 TY_V0_MARGIN_UB
474 ob_b uchar 10
475 ob_flush
476 ret 0
477end
478
479fn main to int
480 ac = argcnt
481 if lt ac 4
482 r = write 2 t_usage 0 len t_usage
483 ret 2
484 end
485 k1 = argread 1 g_a1 0 64
486 k2 = argread 2 g_a2 0 512
487 k3 = argread 3 g_a3 0 512
488 if or lt k1 0 or lt k2 0 lt k3 0
489 ret 2
490 end
491 l1 = ulong k1
492 l2 = ulong k2
493 l3 = ulong k3
494 if and eq ac 4 a1_eq_txt l1 t_cmd_fix
495 ret cmd_fixture l2 l3
496 end
497 rc = load_manifest l2 l3
498 if ne rc TY_OK
499 ret 2
500 end
501 if a1_eq_txt l1 t_cmd_prof
502 ret cmd_profile
503 end
504 ret 2
505end