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 / train / omega-llm / tools / controller / replay.sh

74 lines · 3509 bytes Raw Blame History
1#!/usr/bin/env bash
2set -euo pipefail
3cd "$(dirname "$0")"
4src=$PWD
5bin=$(realpath "${OUT:-../../../../build/omega-controller}")
6omc=$(realpath "${OMC:-../../../../seed/out/omc}")
7work=$(mktemp -d)
8trap 'rm -rf "$work"' EXIT
9cd "$work"
10# The sampler can end immediately after the final identifier.
11printf 'note multiply the arguments\nfn calc a ulong b ulong to ulong' >boundary-prompt
12printf 'note multiply the arguments\nfn calc x ulong y ulong to ulong' >boundary-normalized
13"$bin/normalize" boundary-prompt | cmp - boundary-normalized
14for newline in no yes; do
15 printf 's = mul x y\nret mul s s\nend' >boundary-body
16 printf 's = mul a b\nret mul s s\nend' >boundary-expected
17 if [[ $newline == yes ]]; then printf '\n' >>boundary-body; printf '\n' >>boundary-expected; fi
18 "$bin/normalize" boundary-prompt boundary-body | cmp - boundary-expected
19done
20# Exercise real policy decisions using saved generator proposals.
21cp "$src/example/prompt.om" prompt
22cp "$src/example/example.om" first
23cp "$src/example/second.om" second
24cp "$src/example/answer.om" good
25printf 'ret 0\nend\n' >wrong
26controller=("$bin/controller" prompt "$omc" unused unused first unused unused "$bin/controller.ck")
27"${controller[@]}" good wrong >answer 2>trace
28cmp good answer
29"${controller[@]}" unavailable unused one good wrong >answer 2>trace
30cmp good answer
31"${controller[@]}" second "$bin/second-augmented.ck" learned good wrong >answer 2>trace
32cmp good answer
33grep -q '^gate [0-7] 2$' trace
34
35printf 'note choose the larger argument\nfn calc a ulong b ulong to ulong\n' >prompt
36printf 'fn main to int\nif ne calc ulong 21 ulong 10 ulong 21\nret 83\nend\nret 77\nend\n' >first
37printf 'fn main to int\nif ne calc ulong 14 ulong 23 ulong 23\nret 83\nend\nret 77\nend\n' >second
38printf 'ret a\nend\n' >wrong
39for mode in two learned; do
40 rc=0
41 "${controller[@]}" second "$bin/second-augmented.ck" "$mode" wrong wrong >answer 2>trace || rc=$?
42 test "$rc" -eq 3
43 test ! -s answer
44 grep -q '^gate 4 1$' trace
45done
46printf 'bad' >corrupt
47rc=0
48"${controller[@]}" second corrupt learned wrong wrong >answer 2>trace || rc=$?
49test "$rc" -eq 72
50test ! -s answer
51
52for run in run-01 run-02; do
53 data="$src/$run"
54 for check in main first second; do
55 jq -c --arg k "$check" '.checks as $all | [.cases[] | {prompt,reference,main:$all[.checks][$k]}]' "$data/panel.json" >"$run-$check.json"
56 mkdir "$run-$check"
57 (cd "$run-$check" && "$bin/grade" "../$run-$check.json" "$omc" >grades)
58 test "$(awk '$2==2{n++} END{print n}' "$run-$check/grades")" -eq 80
59 done
60 for mode in $(jq -r 'keys[]' "$data/scores.json"); do
61 mkdir "$run-$mode"
62 (cd "$run-$mode"
63 jq -er --arg mode "$mode" '.[$mode] | select(length==80) | .[] | @base64' "$data/answers.json" |
64 { i=0; while IFS= read -r body; do printf '%s' "$body" | base64 -d >"answer-$i"; i=$((i+1)); done; test "$i" -eq 80; }
65 "$bin/grade" "../$run-main.json" "$omc" cached >actual
66 awk -F '\t' -v mode="$mode" '$1==mode{print $2, 2*$7+$8}' "$data/cases.tsv" >expected
67 cmp expected actual
68 for key in correct wrong abstained calls second_checks; do
69 sum=$(awk -F '\t' -v k="$key" -v m="$mode" 'NR==1{for(i=1;i<=NF;i++)if($i==k)col=i; if(!col)exit 1} $1==m{n+=$col} END{print n+0}' "$data/cases.tsv")
70 test "$sum" -eq "$(jq -er --arg m "$mode" --arg k "$key" '.[$m].all[$k]' "$data/scores.json")"
71 done)
72 done
73done
74echo "PASS: controller interfaces, 160 references on three checks each, and all 560 archived returns and abstentions."