interplane.Get Omega
Read in your language

omega-harness

Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories

Brought by drakestapleton

branch main Branches Tags History

omega-harness / coder / eval / compare.sh

80 lines · 4613 bytes Raw Blame History
1#!/bin/sh
2# Compare the two eval arms: refuse unless their manifests are equal in every line but arm and prompt_sha256
3# (same model, seed, compiler, gate, fixtures, both prompt files, guard, error table, runner, tasks and session
4# program) and each arm's prompt_sha256 is its own prompt file's (omega_prompt_sha256, control_prompt_sha256), then
5# print the raw per-task verdicts side by side, an AT_LIMIT line for each row bound by a session limit, the totals
6# and the ledger line.
7# usage: sh compare.sh OMEGA_OUTDIR CONTROL_OUTDIR
8# Exit 0 with the table; 1 when the arms are not comparable: different inputs, an arm given the other arm's
9# prompt, different or incomplete task sets (every task in the task directory must be scored), or a row with an
10# unknown verdict or a session rc other than 0 or 124.
11set -u
12. "$(dirname "$0")/case.sh"
13o=${1:?omega outdir}
14c=${2:?control outdir}
15tab=$(printf '\t')
16for d in "$o" "$c"; do
17 [ -s "$d/manifest.tsv" ] && [ -s "$d/results.tsv" ] || { echo "COMPARE FAIL $d has no manifest.tsv or results.tsv" >&2; exit 1; }
18done
19[ "$(sed -n "s/^arm$tab//p" "$o/manifest.tsv")" = omega ] && [ "$(sed -n "s/^arm$tab//p" "$c/manifest.tsv")" = control ] ||
20 { echo "COMPARE FAIL arms must be omega then control" >&2; exit 1; }
21strip() { grep -v -e "^arm$tab" -e "^prompt_sha256$tab" "$1"; }
22if [ "$(strip "$o/manifest.tsv")" != "$(strip "$c/manifest.tsv")" ]; then
23 echo "COMPARE FAIL the arms were measured with different inputs:" >&2
24 t=$(mktemp -d)
25 strip "$o/manifest.tsv" > "$t/omega"; strip "$c/manifest.tsv" > "$t/control"
26 diff "$t/omega" "$t/control" >&2; rm -rf "$t"
27 exit 1
28fi
29for p in "$o:omega" "$c:control"; do
30 d=${p%:*}
31 a=${p##*:}
32 [ "$(sed -n "s/^prompt_sha256$tab//p" "$d/manifest.tsv")" = "$(sed -n "s/^${a}_prompt_sha256$tab//p" "$d/manifest.tsv")" ] ||
33 { echo "COMPARE FAIL $d was not given the $a prompt" >&2; exit 1; }
34done
35ids_o=$(tail -n +2 "$o/results.tsv" | cut -f1 | LC_ALL=C sort)
36ids_c=$(tail -n +2 "$c/results.tsv" | cut -f1 | LC_ALL=C sort)
37[ -n "$ids_o" ] && [ "$ids_o" = "$ids_c" ] || { echo "COMPARE FAIL the arms scored different task sets" >&2; exit 1; }
38n=$(echo "$ids_o" | wc -l | tr -d ' ')
39want=$(sed -n "s/^tasks_count$tab//p" "$o/manifest.tsv")
40[ "$n" = "$want" ] || { echo "COMPARE FAIL $n tasks scored, the task directory holds $want: finish both arms first" >&2; exit 1; }
41[ "$(echo $ids_o)" = "$(sed -n "s/^task_ids$tab//p" "$o/manifest.tsv")" ] ||
42 { echo "COMPARE FAIL the scored tasks are not the tasks in the task directory" >&2; exit 1; }
43for d in "$o" "$c"; do
44 bad=$(tail -n +2 "$d/results.tsv" | awk -F'\t' -v vs="$VERDICTS" '
45 BEGIN { n = split(vs, a, " "); for (i = 1; i <= n; i++) ok[a[i]] = 1 }
46 !($2 in ok) || ($5 != "0" && $5 != "124") { print $1 }')
47 [ -z "$bad" ] || { echo "COMPARE FAIL $d/results.tsv has rows with an unknown verdict or a session rc other than 0/124:" $bad >&2; exit 1; }
48done
49printf 'id\tomega\tcontrol\n'
50for id in $ids_o; do
51 printf '%s\t%s\t%s\n' "$id" "$(awk -F'\t' -v i="$id" '$1 == i { print $2 }' "$o/results.tsv")" \
52 "$(awk -F'\t' -v i="$id" '$1 == i { print $2 }' "$c/results.tsv")"
53done
54# Rows bound by a session limit (case.sh): the session was stopped by the timeout (rc 124) or the guard let it
55# finish only because it hit the stop limit (its log says "stop allowed after"). Listed so such a verdict is not
56# read as a free answer.
57atlimit() { # atlimit DIR: the AT_LIMIT lines of one arm
58 a=$(sed -n "s/^arm$tab//p" "$1/manifest.tsv")
59 for id in $ids_o; do
60 rc=$(awk -F'\t' -v i="$id" '$1 == i { print $5 }' "$1/results.tsv")
61 if [ "$rc" = 124 ]; then
62 echo "AT_LIMIT $a $id session_rc=124 (timeout)"
63 elif grep -q 'stop allowed after' "$1/$id/guard.log" 2> /dev/null; then
64 echo "AT_LIMIT $a $id stop_limit (finish allowed after $SESSION_STOP_LIMIT refusals)"
65 fi
66 done
67}
68lo=$(atlimit "$o")
69lc=$(atlimit "$c")
70[ -z "$lo" ] || echo "$lo"
71[ -z "$lc" ] || echo "$lc"
72no=$(echo "$lo" | grep -c '^AT_LIMIT')
73nc=$(echo "$lc" | grep -c '^AT_LIMIT')
74po=$(tail -n +2 "$o/results.tsv" | cut -f2 | grep -cx pass)
75pc=$(tail -n +2 "$c/results.tsv" | cut -f2 | grep -cx pass)
76model=$(sed -n "s/^model$tab//p" "$o/manifest.tsv")
77seed=$(sed -n "s/^seed$tab//p" "$o/manifest.tsv")
78omc=$(sed -n "s/^omc_sha256$tab//p" "$o/manifest.tsv" | cut -c1-8)
79echo "TOTAL omega pass=$po/$n control pass=$pc/$n"
80echo "LEDGER OmegaCoder eval: omega $po/$n pass, control $pc/$n pass (pass with feedback from the scoring case: the guard ran the task check at each finish); at a session limit omega $no control $nc; model $model seed $seed omc $omc; per-task results $o/results.tsv $c/results.tsv"