Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-mv/blob/main/tools/reservoir/qualify_reservoir.sh
# 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
Sign in to star 1 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`omega-mv / tools / reservoir / qualify_reservoir.sh`
230 lines ยท 10884 bytes Raw Blame History
1 #!/bin/bash
2 # SPDX-License-Identifier: Apache-2.0
3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # qualify_reservoir.sh -- omega#440 Gate 2 receipt for the ionic-droplet reservoir
18 # (docs/reservoir/RESERVOIR_REFERENCE.md sections 7, 7.1, 8, 10, 10.1).
19 #
20 # RES_ARCHIVE=
[RES_V2_RESULTS=] tools/reservoir/qualify_reservoir.sh [out-dir]
21 # make qualify-reservoir RES_ARCHIVE= [RES_V2_RESULTS=]
22 #
23 # RES_ARCHIVE is the unpacked project-zenodo-ready_with-paper/ directory of Zenodo
24 # 10.5281/zenodo.`17296788` (every file used is sha256-pinned by the tool); RES_V2_RESULTS
25 # the version 2 HyperParameterOptimizationVariablesToPlot.mat (sha256-pinned; without it
26 # case N1b-v2 is NOT_RUN). The archive is data: read and hashed, never executed.
27 #
28 # On the committed tree only: make test-reservoir (wrapped in `flock $BENCH_LOCK`), then
29 # res_qualify: pins; G2-N1 cases N1a, N1b, N1b-v2 and control NC-N; G2-L1 on 13, 25 and
30 # 43 nodes and control NC-L; the NARMA and Lorenz benchmarks; and, when the quiet flag
31 # is clear, the timing run (under the lock). The receipt is a NEW file named by the
32 # SHA-256 of its own bytes; nothing under evidence/ is rewritten. Its status is FAIL
33 # (with reasons) when the tree is dirty or changes during the run, a pin mismatches,
34 # the build or tests fail, or a command errors. A comparison case that FAILs is a
35 # recorded result, not a receipt failure. Shell and coreutils only (git, sha256sum,
36 # grep, sed, awk, make, flock; jq only to check the JSON when present). No Python.
37 set -u
38
39 HERE=$(cd "$(dirname "$0")/../.." && pwd)
40 cd "$HERE" || exit 2
41 ARCHIVE=${RES_ARCHIVE:-}
42 V2=${RES_V2_RESULTS:-}
43 OUTDIR=${1:-evidence/RESERVOIR}
44 BENCH_LOCK=${BENCH_LOCK:-$HOME/workspace/.argus-bench.lock}
45 LANES=${LANES:-$HOME/.claude/skills/orchestrate-lanes/lanes.sh}
46 Q=build/resq
47 REASONS=()
48 if [ -z "$ARCHIVE" ] || [ ! -d "$ARCHIVE" ]; then
49 echo "qualify_reservoir: RES_ARCHIVE must name the unpacked archive directory" >&2
50 exit 2
51 fi
52 mkdir -p "$(dirname "$BENCH_LOCK")" || exit 2
53
54 head0=$(git rev-parse HEAD)
55 tree0=$(git rev-parse 'HEAD^{tree}')
56 dirty0=$(git status --porcelain)
57 [ -z "$dirty0" ] || REASONS+=("tree dirty at start")
58 started=$(date -u +%Y-%m-%dT%H:%M:%SZ)
59 rm -rf "$Q" && mkdir -p "$Q/r"
60
61 json_str() { printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\t/ /g' | awk 'BEGIN{ORS=""} {if (NR>1) print "\\n"; print}'; }
62
63 # ---- build and unit tests ------------------------------------------------------
64 build_rc=0
65 flock "$BENCH_LOCK" make OUT_DIR="$Q/out" PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-reservoir \
66 > "$Q/test-reservoir.log" 2>&1 || build_rc=$?
67 [ "$build_rc" -eq 0 ] || REASONS+=("make test-reservoir failed (rc $build_rc)")
68 T=$Q/out/tests-reservoir/res_qualify
69 tests_summary=$(grep -E '^test_res(ervoir|_mat): [0-9]+ checks' "$Q/test-reservoir.log" | tr '\n' ';')
70
71 run() { # run : stdout JSON, stderr and exit code kept
72 local name=$1
73 shift
74 "$T" "$@" > "$Q/r/$name.json" 2> "$Q/r/$name.err"
75 echo $? > "$Q/r/$name.rc"
76 }
77
78 CASES="g2-narma-N1a g2-narma-N1b g2-narma-N1b-v2 g2-narma-NC-N g2-lorenz-13 g2-lorenz-25 g2-lorenz-43 g2-lorenz-13-NC-L"
79 if [ "$build_rc" -eq 0 ]; then
80 run pins pins "$ARCHIVE"
81 [ "$(cat "$Q/r/pins.rc")" = 0 ] || REASONS+=("archive pin mismatch (see results.pins)")
82 # the comparisons are independent processes and untimed: run them side by side
83 run g2-narma-N1a g2-narma "$ARCHIVE" N1a &
84 run g2-narma-N1b g2-narma "$ARCHIVE" N1b &
85 run g2-narma-NC-N g2-narma "$ARCHIVE" NC-N &
86 if [ -n "$V2" ]; then run g2-narma-N1b-v2 g2-narma "$ARCHIVE" N1b-v2 "$V2" & fi
87 run g2-lorenz-13 g2-lorenz "$ARCHIVE" 13 &
88 run g2-lorenz-25 g2-lorenz "$ARCHIVE" 25 &
89 run g2-lorenz-43 g2-lorenz "$ARCHIVE" 43 &
90 run g2-lorenz-13-NC-L g2-lorenz "$ARCHIVE" 13 NC-L &
91 wait
92 run bench-narma bench-narma
93 run bench-lorenz bench-lorenz
94 fi
95
96 # ---- timing (task e): only on a quiet machine ------------------------------------
97 quiet="not checked (no lanes.sh on this host)"
98 perf_state=NOT_RUN
99 perf_reason="build failed"
100 if [ "$build_rc" -eq 0 ]; then
101 idle=1
102 if [ -x "$LANES" ]; then
103 nurse=$("$LANES" nurse 2>&1)
104 quiet=$(printf '%s\n' "$nurse" | grep -m1 -i 'quiet flag' | sed 's/^ *//')
105 quiet="$quiet; $(printf '%s\n' "$nurse" | grep -m1 -i 'forge:' | sed 's/^ *//')"
106 printf '%s\n' "$nurse" | grep -qi 'quiet flag: *clear' || idle=0
107 printf '%s\n' "$nurse" | grep -i 'forge:' | grep -qi 'not running' || idle=0
108 fi
109 if [ "$idle" -eq 0 ]; then
110 perf_reason="machine not quiet (a GB10 job or the quiet flag): $quiet"
111 else
112 loadavg_before=$(cut -d' ' -f1-3 /proc/loadavg 2>/dev/null)
113 flock "$BENCH_LOCK" "$T" perf > "$Q/r/perf.json" 2> "$Q/r/perf.err"
114 echo $? > "$Q/r/perf.rc"
115 perf_state=RUN
116 perf_reason="load average before: ${loadavg_before:-unknown}"
117 fi
118 fi
119
120 # ---- collect --------------------------------------------------------------------
121 verdict_of() { grep -o '"verdict": "[A-Z_]*"' "$1" 2>/dev/null | tail -1 | sed 's/.*: "\(.*\)"/\1/'; }
122 results=""
123 summary=""
124 for name in pins $CASES bench-narma bench-lorenz perf; do
125 f=$Q/r/$name.json
126 if [ ! -f "$Q/r/$name.rc" ]; then
127 why="not run"
128 [ "$name" = g2-narma-N1b-v2 ] && [ -z "$V2" ] && why="NOT_RUN: RES_V2_RESULTS not given"
129 [ "$name" = perf ] && why="NOT_RUN: $perf_reason"
130 results+="${results:+,}
131 \"$name\": {\"status\": \"$(json_str "$why")\"}"
132 summary+="${summary:+, }\"$name\": \"$(json_str "$why")\""
133 continue
134 fi
135 rc=$(cat "$Q/r/$name.rc")
136 [ "$rc" -le 1 ] || REASONS+=("$name exited $rc: $(head -c 300 "$Q/r/$name.err")")
137 if [ "$rc" -le 1 ] && [ -s "$f" ]; then
138 results+="${results:+,}
139 \"$name\": $(cat "$f")"
140 else
141 results+="${results:+,}
142 \"$name\": {\"status\": \"ERROR\", \"rc\": $rc, \"stderr\": \"$(json_str "$(head -c 2000 "$Q/r/$name.err")")\"}"
143 fi
144 v=$(verdict_of "$f")
145 [ -n "$v" ] || { [ "$rc" = 0 ] && v=RAN || v="ERROR rc $rc"; }
146 summary+="${summary:+, }\"$name\": \"$v\""
147 done
148 # negative controls must fail; a passing control means the contract cannot see that error
149 for c in g2-narma-NC-N g2-lorenz-13-NC-L; do
150 v=$(verdict_of "$Q/r/$c.json")
151 [ -z "$v" ] || [ "$v" = FAIL ] || REASONS+=("negative control $c did not fail ($v)")
152 done
153
154 head1=$(git rev-parse HEAD)
155 dirty1=$(git status --porcelain)
156 stable=true
157 { [ "$head1" = "$head0" ] && [ "$dirty1" = "$dirty0" ]; } || { stable=false; REASONS+=("tree changed during the run"); }
158 tree_dirty=false
159 [ -z "$dirty0" ] || tree_dirty=true
160 status=RECORDED
161 [ "${#REASONS[@]}" -eq 0 ] || status=FAIL
162 reasons_json=""
163 for r in "${REASONS[@]}"; do reasons_json+="${reasons_json:+, }\"$(json_str "$r")\""; done
164
165 body=$(cat </dev/null)")"},
178 "compiler": "$(json_str "$(${CC:-cc} --version 2>/dev/null | head -1)")",
179 "unit_tests": "$(json_str "$tests_summary")",
180 "unit_tests_log_sha256": "$(sha256sum "$Q/test-reservoir.log" | awk '{print $1}')",
181 "archive": {"record": "10.5281/zenodo.`17296788`", "license": "CC-BY-4.0", "pins": "results.pins", "v2_results_file_given": $([ -n "$V2" ] && echo true || echo false)},
182 "quiet_flag": "$(json_str "$quiet")",
183 "timing": {"state": "$perf_state", "note": "$(json_str "$perf_reason")"},
184 "hardware_scope": "CPU only; no GPU opened, no silicon, no energy or power measurement",
185 "summary": {$summary},
186 "blocked": [
187 "63 of the 64 archived NARMA grid cells: their input masks come from MATLAB's rng/randi stream, which is not reimplemented (no MATLAB or Octave here)",
188 "state-trace comparison against the authors' code: the version 1 archive holds no state trajectories",
189 "whether the archived outputs came from the archived code (discrepancy 15): needs MATLAB",
190 "the paper's parallel reservoir (S5): a different, voltage-clamped model, not implemented"
191 ],
192 "not_run": [
193 "energy and power: not instrumented, no efficiency claim",
194 "AIEN telemetry workload: no real telemetry with a time-ordered train/validation/test split exists (section 11)",
195 "RC with squared states on the 50-node NARMA chain: 295 features, above the readout bound of 256"
196 ],
197 "proves": [
198 "For the cases whose verdict is PASS: numerical agreement, under the tolerances declared before the runs, between Omega's binary32 simulator with its binary64 readout and the outputs the authors archived from their MATLAB code (targets, predictions and NRMSE), on the archived inputs.",
199 "For the cases whose verdict is FAIL: that Omega does not meet the declared criteria there, with the diagnostics recorded in the case.",
200 "The benchmark and timing numbers below, for this commit, compiler and host."
201 ],
202 "does_not_prove": [
203 "physical validity of the droplet model, or anything about real droplets or devices",
204 "agreement on the BLOCKED cases, or with the authors' code beyond its archived outputs",
205 "GPU qualification of any kind (CPU only)",
206 "energy, power or efficiency (NOT_RUN)",
207 "production readiness"
208 ],
209 "status": "$status",
210 "status_reasons": [$reasons_json],
211 "results": {$results
212 }
213 }
214 EOF
215 )
216 mkdir -p "$OUTDIR"
217 tmp=$(mktemp "$OUTDIR/.tmp-XXXXXX")
218 printf '%s\n' "$body" > "$tmp"
219 if command -v jq > /dev/null 2>&1 && ! jq -e . "$tmp" > /dev/null 2>&1; then
220 echo "qualify_reservoir: receipt is not valid JSON; kept at $tmp" >&2
221 exit 2
222 fi
223 digest=$(sha256sum "$tmp" | awk '{print $1}')
224 final=$OUTDIR/$digest.json
225 if [ -e "$final" ]; then rm -f "$tmp"; else mv "$tmp" "$final"; fi
226 chmod 0644 "$final"
227 echo "SUMMARY {$summary}"
228 echo "RECEIPT $final"
229 echo "STATUS $status"
230 [ "$status" = RECORDED ]