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 / crates / allen-reflex / examples / exam.rs

105 lines · 4154 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//! Run the orchestration exam with ALLEN REFLEX and the two baselines.
17//! usage: cargo run --release -p allen-reflex --example exam -- <split: train|dev|heldout> [modes...]
18//! Writes docs/native/pi5-8/orchestrator-exam/results/allen-reflex.<split>.<mode>.jsonl in
19//! run_exam.sh's record format (raw = the decision JSON only), plus a .why.tsv file with the
20//! explanation of every decision (kept out of the scored JSON). Learning is off while scoring.
21#[path = "common/mod.rs"]
22mod common;
23use allen_reflex::{exam_turns, Config, Mode};
24use common::*;
25use std::io::Write;
26use std::time::Instant;
27
28fn main() {
29 let args: Vec<String> = std::env::args().skip(1).collect();
30 let split = args
31 .first()
32 .map(String::as_str)
33 .unwrap_or("dev")
34 .to_string();
35 let modes: Vec<Mode> = if args.len() > 1 {
36 args[1..]
37 .iter()
38 .map(|m| match m.as_str() {
39 "reflex" => Mode::Reflex,
40 "nearest" => Mode::Nearest,
41 "perceptron" => Mode::Perceptron,
42 _ => panic!("mode {m}"),
43 })
44 .collect()
45 } else {
46 vec![Mode::Reflex, Mode::Nearest, Mode::Perceptron]
47 };
48 let pool = pool();
49 let cases = load(&split);
50 for mode in modes {
51 let refs: Vec<&Case> = pool.iter().collect();
52 let mut core = build(Config::frozen(mode), &refs);
53 core.set_learning(false);
54 let dir = exam_dir().join("results");
55 let f = dir.join(format!("allen-reflex.{split}.{}.jsonl", mode.name()));
56 let w = dir.join(format!("allen-reflex.{split}.{}.why.tsv", mode.name()));
57 let mut out = std::fs::File::create(&f).unwrap();
58 let mut why = std::fs::File::create(&w).unwrap();
59 writeln!(why, "id\tdecision\twhy\ttop\tsecond\tmargin\tbest_sim\tagree\tnearest_label\tnearest_message").unwrap();
60 let (mut a_ok, mut e_ok) = (0, 0);
61 for c in &cases {
62 let t = exam_turns(&c.turns);
63 let t0 = Instant::now();
64 let (d, ex) = core.decide(&t);
65 let us = t0.elapsed().as_micros();
66 let raw = d.json();
67 let (a, e) = judge(c, &d);
68 a_ok += a as usize;
69 e_ok += e as usize;
70 writeln!(
71 out,
72 "{{\"id\":\"{}\",\"split\":\"{}\",\"cat\":\"{}\",\"exp_action\":\"{}\",\"exp_text\":\"{}\",\"ms\":{},\"finish\":\"stop\",\"raw\":\"{}\",\"ptok\":0,\"ctok\":0,\"us\":{}}}",
73 esc(&c.id), esc(&split), esc(&c.cat), c.action.name(), esc(&c.text), us / 1000, esc(&raw), us
74 )
75 .unwrap();
76 let (nl, nm) = ex
77 .nearest
78 .as_ref()
79 .map(|(l, m)| (l.name(), m.as_str()))
80 .unwrap_or(("-", "-"));
81 writeln!(
82 why,
83 "{}\t{}\t{:?}\t{}\t{}\t{:.3}\t{:.3}\t{:.2}\t{}\t{}",
84 c.id,
85 raw,
86 ex.why,
87 ex.top.name(),
88 ex.second.name(),
89 ex.margin,
90 ex.best_sim,
91 ex.agree,
92 nl,
93 nm.replace('\t', " ")
94 )
95 .unwrap();
96 }
97 eprintln!(
98 "allen-reflex {split} {}: action {a_ok}/{n} exact {e_ok}/{n} (memory {} bytes, {} exemplars)",
99 mode.name(),
100 core.memory_bytes(),
101 core.exemplars(),
102 n = cases.len()
103 );
104 }
105}