Closes the "still open" reader-tool note from §XXXV.10: scripts/ extract_doe_region.py spools DOE-PERSIST-TRIAL's on-disk binary ring off disk/artemis.img into a CSV -- direct file read by default, or via a real loop device (--loop, losetup) per the literal request. Independent Python reimplementation of doe_region.c's own ring-walk, verified against a live 3-record write/read round trip. analyse_multiuser_doe.R (house style, ggplot2/svglite) and multiuser_doe_report.tex (same preamble convention as bare_metal_doe_report.tex) auto-discover whatever data exists and degrade gracefully to a placeholder when a campaign has 0 trials so far -- the whole point being this can be rebuilt at any point during a multi-day campaign, including mid-run. build_multiuser_doe_report.sh chains extraction -> R -> svg_to_pdf.py -> pdflatex into one command. Found and fixed a real bug while verifying: the R script's SCRIPT_DIR detection silently wrote charts/tables/report output to the repo root instead of the analysis directory when invoked from a different cwd -- switched to the robust commandArgs() "--file=" idiom. Verified live both branches (0 trials and a real 3-record write), reverted synthetic test data and incidental svg_to_pdf.py churn on ~85 unrelated committed figures before committing. FABRIC-3.md §XXXV.11 has the full account. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BWpNjdwPtFLuVLaAq44L9K
97 lines
3.5 KiB
Bash
Executable File
97 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# build_multiuser_doe_report.sh — full pipeline: disk -> CSV -> R/SVG -> PDF
|
|
#
|
|
# Chains: extract_doe_region.py (spool DOE-PERSIST-TRIAL records off
|
|
# disk/artemis.img) -> analyse_multiuser_doe.R (tables + SVG charts +
|
|
# auto-generated summary fragment) -> svg_to_pdf.py (SVG -> PDF for
|
|
# \includegraphics) -> pdflatex (twice, for cross-references) ->
|
|
# multiuser_doe_report.pdf.
|
|
#
|
|
# Safe to re-run at any point, including while a multi-day campaign is
|
|
# still executing on a separate QEMU instance: every step is read-only
|
|
# with respect to disk/artemis.img, and analyse_multiuser_doe.R degrades
|
|
# to a "no data yet" placeholder rather than failing when the DoE region
|
|
# has 0 trials so far.
|
|
#
|
|
# Usage:
|
|
# scripts/build_multiuser_doe_report.sh [--loop] [--csv PATH]
|
|
#
|
|
# --loop Attach disk/artemis.img via losetup instead of reading
|
|
# the file directly (needs sudo). See extract_doe_region.py.
|
|
# --csv PATH Skip disk extraction entirely and analyse an existing
|
|
# CSV instead (e.g. to smoke-test this pipeline against
|
|
# an old per-tick run CSV, or a CSV saved from a previous
|
|
# extraction).
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$REPO_ROOT"
|
|
|
|
ANALYSIS_DIR="experiments/bare_metal/analysis"
|
|
RUNS_DIR="experiments/bare_metal/runs"
|
|
REPORT_DIR="$ANALYSIS_DIR/report"
|
|
CSV_OUT="$RUNS_DIR/multiuser-doe-trials.csv"
|
|
|
|
USE_LOOP=0
|
|
CSV_OVERRIDE=""
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--loop) USE_LOOP=1; shift ;;
|
|
--csv) CSV_OVERRIDE="$2"; shift 2 ;;
|
|
*) echo "Unknown argument: $1" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
echo "=== [1/4] Extracting trial records ==="
|
|
if [ -n "$CSV_OVERRIDE" ]; then
|
|
echo " Using existing CSV: $CSV_OVERRIDE (skipping disk extraction)"
|
|
CSV_OUT="$CSV_OVERRIDE"
|
|
elif [ -f disk/artemis.img ]; then
|
|
mkdir -p "$RUNS_DIR"
|
|
if [ "$USE_LOOP" -eq 1 ]; then
|
|
python3 scripts/extract_doe_region.py --img disk/artemis.img --loop -o "$CSV_OUT"
|
|
else
|
|
python3 scripts/extract_doe_region.py --img disk/artemis.img -o "$CSV_OUT"
|
|
fi
|
|
else
|
|
echo " disk/artemis.img not found -- writing an empty CSV so the report" >&2
|
|
echo " still builds with a 'no data yet' placeholder." >&2
|
|
mkdir -p "$RUNS_DIR"
|
|
echo "isa,run_id,cfg,rep,nw,mode,fail_count,fleet_k_q48,fleet_conserved,switch_count_cumulative" > "$CSV_OUT"
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== [2/4] Running R analysis (tables + charts + summary fragment) ==="
|
|
Rscript "$ANALYSIS_DIR/analyse_multiuser_doe.R" "$CSV_OUT"
|
|
|
|
echo ""
|
|
echo "=== [3/4] Converting SVG charts to PDF ==="
|
|
python3 "$ANALYSIS_DIR/svg_to_pdf.py"
|
|
|
|
echo ""
|
|
echo "=== [4/4] Building PDF report ==="
|
|
mkdir -p "$REPORT_DIR/sections"
|
|
if [ ! -f "$REPORT_DIR/sections/multiuser_summary_autogen.tex" ]; then
|
|
echo "No trial data has been persisted to the DoE region yet." \
|
|
> "$REPORT_DIR/sections/multiuser_summary_autogen.tex"
|
|
fi
|
|
|
|
cd "$REPORT_DIR"
|
|
pdflatex -interaction=nonstopmode -halt-on-error multiuser_doe_report.tex >/tmp/multiuser_doe_report_latex1.log 2>&1 || {
|
|
echo "pdflatex (pass 1) failed -- see /tmp/multiuser_doe_report_latex1.log" >&2
|
|
tail -40 /tmp/multiuser_doe_report_latex1.log >&2
|
|
exit 1
|
|
}
|
|
pdflatex -interaction=nonstopmode -halt-on-error multiuser_doe_report.tex >/tmp/multiuser_doe_report_latex2.log 2>&1 || {
|
|
echo "pdflatex (pass 2) failed -- see /tmp/multiuser_doe_report_latex2.log" >&2
|
|
tail -40 /tmp/multiuser_doe_report_latex2.log >&2
|
|
exit 1
|
|
}
|
|
cd "$REPO_ROOT"
|
|
|
|
echo ""
|
|
echo "=== Done ==="
|
|
echo " PDF: $REPORT_DIR/multiuser_doe_report.pdf"
|