Files
ML-Porosity/scripts/run_p3_dev.sh
lamlvh cee2ff0859 P2 diagnosis on dev, P3 dev experiments, lock protocol_p3
- P2: SMC tie posterior (numpy + torch), RML/soft-DTW losses, bank training,
  D2 synthetic generator, scripts 09-13, protocol_p2 (locked) and its outcome
  (G-B failed; H1 not rejected, H3 rejected, H4 not rejected).
- Diagnosis on dev realizations 900/901 only (scripts 14-17, run_p3_dev.sh):
  posterior screen, SMC stability (P = 1024, K = 1), sigma_a misspecification
  stress and training, H3 with the SMC posterior, F3 placement on sigma_post.
- protocol_p3: H2 split into H2a (posterior-mean labels vs point ties) and
  H2b (RML vs posterior mean as a function of sigma_post); H3 descriptive only;
  sigma_a arm; new D2 config d2_synth_p3.yaml; main grid on realizations 8-15.
  Locked by configs/protocol_p3.sha256 and tag protocol-p3.
- runlog: per-run logs and runtime index (logs/index.csv).
- Docs: plan §12 items 10-11, theory, technical overview, report; wording
  aligned with Gunning & Glinsky (2006): the tie posterior is not claimed as new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 06:03:33 +00:00

84 lines
5.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Dev experiments in preparation for protocol_p3 (plan §10): dev realizations 900/901 only; main grid 0–7 is not used.
# scripts/run_p3_dev.sh # all stages in order
# scripts/run_p3_dev.sh stability sigma_a # only the named stages
# screen SMC posterior over SNR {10, 5, 0, −5} dB × anchor density {full, half, topbottom} × c {1, 2} × N {4, 16}
# train training (scripts/15) in the screen cells with σ_post ≥ 1.5 ms (outputs/p2/diag/p3dev/wide_cells.txt,
# written by scripts/17): M2-Sa, B3d-Sa, B3c-R, Oracle… 5 seeds, fixed budgets
# stability 4 independent SMC runs with P = 256 and 2 with P = 1024 (SNR 10, full): warp difference between runs
# stability_m5 as stability at SNR −5 dB, full (the F3-like regime): 2 runs with P = 1024 (the chosen setting)
# b3d_old supplementary: old protocol_p2 B3d (point-tie competitor for H2a) at SNR 10/0/−5, full, same seeds and budgets
# sigma_a registration with σ_a = 3.5 and 14 ms when the data are generated with σ_a = 7 ms (plan §5.5)
# train_sa training on the sigma_a posteriors (c 1 2; every method registered with the misspecified σ_a): does H2a hold?
# f3 SMC posterior on the 4 F3 wells (descriptive only, scripts/16)
# h3 H3 with the SMC posterior: 5-seed ensembles of M2-Sa, B3d-Sa… vs B5 in the protocol_p2 setting (c 1, 2)
# GPU jobs run on cuda:1 (override with DEVICE=...). Re-running after an interruption: scripts 14, 15 skip jobs that already have a CSV.
set -euo pipefail
cd "$(dirname "$0")/.."
PY="${PY:-.venv/bin/python}"
[[ -n "${RUNLOG_DIR:-}" ]] || exec "$PY" -m ml_porosity.runlog -n p3dev -- bash "scripts/$(basename "$0")" "$@"
step() { "$PY" -m ml_porosity.runlog "$@" || echo "step failed: $*" >&2; }
DEVICE="${DEVICE:-cuda:1}"
WORKERS="${WORKERS:-6}"
# The machine environment presets OMP_NUM_THREADS=40 (also MKL, OpenBLAS): unless overridden, each worker opens a 40-thread pool.
THREADS="${THREADS:-2}"
export OMP_NUM_THREADS=$THREADS MKL_NUM_THREADS=$THREADS OPENBLAS_NUM_THREADS=$THREADS NUMEXPR_NUM_THREADS=$THREADS \
NUMBA_NUM_THREADS=$THREADS
OUT=outputs/p2/diag
POST=(scripts/14_diag_posterior.py --rids 900 901 --c 1 2 --n 4 16 --seeds 0 --device "$DEVICE")
TRAIN=(scripts/15_diag_train.py --rids 900 901 --n 4 16 --seeds 0 1 2 3 4 --device "$DEVICE" --variants a 1
--methods Oracle B3b B3c M2 B3c-R B3d-Sa M2-Sa B3d-S1 M2-S1 --budgets-from "$OUT/train/budgets.json" --save-preds)
for stage in ${@:-screen train stability sigma_a f3 h3}; do
case "$stage" in
screen)
for snr in 10 5 0 -5; do
for dens in full half topbottom; do
step -n "stress_snr${snr}_${dens}" -- "$PY" "${POST[@]}" --snr "$snr" --anchor-density "$dens" \
--wavelets estR true --workers "$WORKERS" --out-dir "$OUT/stress/snr${snr}_${dens}"
done
done ;;
train)
CUDA_VISIBLE_DEVICES= "$PY" scripts/17_summarize_p3_dev.py --only screen > /dev/null
while read -r snr dens cs <&3; do
# shellcheck disable=SC2086 # cs is a list of c values and must be word-split
step -n "train_snr${snr}_${dens}" -- "$PY" "${TRAIN[@]}" --snr "$snr" --anchor-density "$dens" --c $cs \
--workers 4 --post-dir "$OUT/stress/snr${snr}_${dens}" --out-dir "$OUT/train_stress/snr${snr}_${dens}"
done 3< "$OUT/p3dev/wide_cells.txt" ;;
stability)
step -n stab_p256 -- "$PY" "${POST[@]}" --smc-seeds 0 1 2 3 --wavelets estR --workers "$WORKERS" \
--out-dir "$OUT/stability/p256"
step -n stab_p1024 -- "$PY" "${POST[@]}" --particles 1024 --smc-seeds 0 1 --wavelets estR --workers 4 \
--gpu-mem-gb 6 --out-dir "$OUT/stability/p1024" ;;
stability_m5)
step -n stab_p1024_snr-5 -- "$PY" "${POST[@]}" --snr -5 --anchor-density full --particles 1024 --smc-seeds 0 1 \
--wavelets estR --workers 4 --gpu-mem-gb 6 --out-dir "$OUT/stability/p1024_snr-5" ;;
b3d_old)
B3D=(scripts/15_diag_train.py --rids 900 901 --n 4 16 --seeds 0 1 2 3 4 --c 1 2 --device "$DEVICE" --variants a
--methods B3d --budgets-from "$OUT/train/budgets.json" --workers 4)
step -n b3d_snr10_full -- "$PY" "${B3D[@]}" --post-dir "$OUT/posterior_gpu" --out-dir "$OUT/train_b3d/snr10_full"
for snr in 0 -5; do
step -n "b3d_snr${snr}_full" -- "$PY" "${B3D[@]}" --snr "$snr" --anchor-density full \
--post-dir "$OUT/stress/snr${snr}_full" --out-dir "$OUT/train_b3d/snr${snr}_full"
done ;;
sigma_a)
for sa in 3.5 14; do
step -n "stress_sa${sa}" -- "$PY" "${POST[@]}" --sigma-a-reg "$sa" --wavelets estR true --workers "$WORKERS" \
--out-dir "$OUT/stress/snr10_full_sa${sa}"
done ;;
train_sa)
for sa in 3.5 14; do
step -n "train_sa${sa}" -- "$PY" scripts/15_diag_train.py --rids 900 901 --n 4 16 --seeds 0 1 2 3 4 --c 1 2 \
--device "$DEVICE" --variants a --methods Oracle B3b B3c B3c-R B3d B3d-Sa M2-Sa --sigma-a-reg "$sa" \
--budgets-from "$OUT/train/budgets.json" --workers 4 --post-dir "$OUT/stress/snr10_full_sa${sa}" \
--out-dir "$OUT/train_sa/sa${sa}"
done ;;
f3)
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 step -n f3_posterior -- "$PY" scripts/16_f3_posterior.py \
--device "$DEVICE" ;;
h3)
step -n h3_smc -- "$PY" "${TRAIN[@]}" --c 1 2 --workers 4 --post-dir "$OUT/posterior_gpu" --out-dir "$OUT/h3_smc" ;;
*) echo "unknown stage: $stage" >&2; exit 2 ;;
esac
done