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 / tools / estimation / est4_collect.sh

77 lines · 3551 bytes Raw Blame History
1#!/bin/sh
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# ESTIMATION v4 (docs/estimation/protocols/est-v4.md) data collection under the
18# declared est_load schedule. Same collector as v3 (est3c_collect.sh); only the
19# folder tag, the flag owner text and the est_load process check differ.
20# tools/estimation/est4_collect.sh <fit|heldout|smoke> <seconds> <seed> <raw-root> <est_load-binary>
21# Writes <raw-root>/<UTC>-est4-<role>-silicon/ with machine-state.ndjson (1 Hz),
22# machine-state-marks.txt, schedule.txt, machine-state-start.txt, SHA256SUMS.
23# Coordination: refuses to start while ~/workspace/.spark-quiet exists or any
24# est_load process runs; holds the flag (text "lane15 est v4 load period") for
25# its own run and removes it afterwards. Prints no thermal statistic.
26set -u
27role=${1:?fit, heldout or smoke}
28secs=${2:?seconds}
29seed=${3:?seed}
30root=${4:?raw root}
31load=${5:?est_load binary}
32quiet=$HOME/workspace/.spark-quiet
33if pgrep -x est_load > /dev/null 2>&1; then
34 echo "est4_collect: an est_load process is running; refusing" >&2
35 exit 3
36fi
37# Take the flag atomically (noclobber): refuse if another run owns the machine.
38if ! ( set -C; printf 'owner: lane15 est v4 load period (%s)\nstarted: %s\nexpected end: %s\nplease: no builds or tests until this file is gone\n' \
39 "$role" "$(date -u +%FT%TZ)" "$(date -u -d "+$secs seconds" +%FT%TZ)" > "$quiet" ) 2> /dev/null; then
40 echo "est4_collect: $quiet exists; another run owns the machine" >&2
41 exit 3
42fi
43lpid=
44cleanup() {
45 [ -n "$lpid" ] && kill "$lpid" 2> /dev/null
46 rm -f "$quiet"
47}
48trap cleanup EXIT
49trap 'exit 4' HUP INT TERM
50mkdir -p "$root" || exit 5
51d=$root/$(date -u +%Y%m%dT%H%M%SZ)-est4-$role-silicon
52# Plain mkdir: refuses an existing folder, so a prior collection is never truncated.
53mkdir "$d" || { echo "est4_collect: $d already exists; refusing" >&2; exit 5; }
54date -u +%FT%TZ > "$d/machine-state-start.txt"
55: > "$d/machine-state-marks.txt"
56"$load" "$seed" "$secs" "$d/machine-state-marks.txt" > "$d/schedule.txt" &
57lpid=$!
58end=$(( $(date +%s) + secs ))
59while [ "$(date +%s)" -lt "$end" ]; do
60 t=$(date +%s.%N)
61 th=$(cat /sys/class/thermal/thermal_zone*/temp | tr '\n' ' ')
62 la=$(cut -d' ' -f1-3 /proc/loadavg)
63 cpu=$(head -1 /proc/stat | cut -d' ' -f3-10)
64 printf '{"t":%s,"thermal_mc":"%s","loadavg":"%s","cpu":"%s"}\n' "$t" "$th" "$la" "$cpu" >> "$d/machine-state.ndjson"
65 if ! kill -0 "$lpid" 2> /dev/null && [ "$(( end - $(date +%s) ))" -gt 5 ]; then
66 echo "est4_collect: est_load exited early; collection is INVALID" >&2
67 lpid=; echo INVALID_EARLY_LOAD_EXIT > "$d/INVALID"; exit 6
68 fi
69 sleep 1
70done
71wait "$lpid"; rc=$?; lpid=
72if [ "$rc" -ne 0 ]; then
73 echo "est4_collect: est_load exit status $rc; collection is INVALID" >&2
74 echo "INVALID_LOAD_EXIT $rc" > "$d/INVALID"; exit 6
75fi
76(cd "$d" && sha256sum machine-state.ndjson machine-state-marks.txt machine-state-start.txt schedule.txt > SHA256SUMS)
77echo "$d"