interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / allen_pi_results.sh

55 lines · 3514 bytes Raw Blame History
1#!/usr/bin/env bash
2# allen_pi_results.sh -- turn the decision lines of a pi5-allen run (kernel.log from the card, or a QEMU serial log) into
3# exam result files for docs/native/pi5-8/orchestrator-exam/score.sh, and compare them with the committed host results.
4#
5# allen_pi_results.sh <kernel.log> [result name, default allen-reflex-pi]
6#
7# Writes results/<name>.<split>.<mode>.jsonl for split train, dev and mode reflex, nearest, perceptron, in the record
8# format of run_exam.sh (id split cat exp_action exp_text ms finish raw ptok ctok us; us = the kernel's own timing of the
9# decision, from its ALLEN_G line). The expected answers come from the host .psv files, joined by case id: the card file
10# never carried them. Then prints score.sh rows for the Pi and for the committed host results (allen-reflex) and checks
11# that every decision ("raw") is identical, case by case. Train and dev only: held-out files are never read.
12set -euo pipefail
13here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14exam="${here}/docs/native/pi5-8/orchestrator-exam"
15log="${1:?kernel.log}"
16name="${2:-allen-reflex-pi}"
17[[ -r "${log}" ]] || { echo "no log ${log}" >&2; exit 2; }
18tmp="$(mktemp -d)"
19trap 'rm -rf "${tmp}"' EXIT
20tr -d '\r' <"${log}" >"${tmp}/log"
21bad=0
22for split in train dev; do
23 psv="${exam}/cases-${split}.psv"
24 for mode in reflex nearest perceptron; do
25 out="${exam}/results/${name}.${split}.${mode}.jsonl"
26 # ALLEN_D <mode> <id> <json> ALLEN_G <mode> <id> <verdict> <verb> ns=<n>
27 awk -v mode="${mode}" -v psv="${psv}" -v sp="${split}" '
28 BEGIN { FS = "|"; while ((getline l < psv) > 0) { if (l ~ /^#/ || l == "") continue; n = split(l, f, "|");
29 cat[f[1]] = f[2]; act[f[1]] = f[3]; txt[f[1]] = f[4]; order[++k] = f[1] } FS = " " }
30 $1 == "ALLEN_D" && $2 == mode && ($3 in cat) { j = $0; sub(/^ALLEN_D [^ ]+ [^ ]+ /, "", j); raw[$3] = j }
31 $1 == "ALLEN_G" && $2 == mode && ($3 in cat) { v = $6; sub(/^ns=/, "", v); ns[$3] = v }
32 END { for (i = 1; i <= k; i++) { id = order[i]; if (!(id in raw) || !(id in ns)) { print "MISSING " id > "/dev/stderr"; continue }
33 printf "%s\t%s\t%s\t%s\t%s\t%s\t%d\n", id, sp, cat[id], act[id], txt[id], raw[id], int(ns[id] / 1000 + 0.5) } }
34 ' "${tmp}/log" >"${tmp}/rows" 2>"${tmp}/missing"
35 if [[ -s "${tmp}/missing" ]]; then
36 echo "FAIL ${split}.${mode}: $(wc -l <"${tmp}/missing") cases have no decision line in the log"; bad=1
37 fi
38 jq -cR 'split("\t") | {id: .[0], split: .[1], cat: .[2], exp_action: .[3], exp_text: .[4], ms: 0, finish: "stop",
39 raw: .[5], ptok: 0, ctok: 0, us: (.[6] | tonumber)}' "${tmp}/rows" >"${out}"
40 host="${exam}/results/allen-reflex.${split}.${mode}.jsonl"
41 if cmp -s <(jq -r '[.id, .raw] | @tsv' "${host}") <(jq -r '[.id, .raw] | @tsv' "${out}"); then
42 echo "identical ${split}.${mode}: $(wc -l <"${out}") decisions equal the committed host results"
43 else
44 echo "DIFFERENT ${split}.${mode}: decisions differ from the committed host results"; bad=1
45 fi
46 done
47done
48"${exam}/score.sh" --header 2>/dev/null || true
49for split in train dev; do
50 for mode in reflex nearest perceptron; do
51 "${exam}/score.sh" "${name}" "${split}" "${mode}"
52 "${exam}/score.sh" allen-reflex "${split}" "${mode}"
53 done
54done
55[[ "${bad}" == 0 ]] && echo "ALLEN_PI_RESULTS: IDENTICAL" || { echo "ALLEN_PI_RESULTS: DIFFERENT"; exit 1; }