junidude14 commited on
Commit
660f012
·
verified ·
1 Parent(s): 7eae50c

Archive 4 checkpoints (1-4)

Browse files
paper-releases/pbisc-diffusion/updates/20261003T103040Z-crosscohort-k1000-saturation/diffusion/dataset/server_1/model8/plans/paired_crosscohort_20261002/tools/pause_scsemi_for_loco.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # User decision 2026-10-03 00:40 KST: LOCO first. Pause the scSemiProfiler CV / budget queue (scsemi-queue-cvb-s1) at a
3
+ # clean point and restart it, with its original settings, once both LOCO queues have finished.
4
+ # 1. wait until no scSemiProfiler GPU step (mljob running run_scsemi_*) and no scsemi-* CPU step is running
5
+ # 2. stop scsemi-queue-cvb-s1 (it resumes split by split from its receipts, see scsemi/README.md)
6
+ # 3. wait until loco-queue-s1 (server_1) and loco-queue-s2 (server_2) are both inactive
7
+ # 4. start scsemi-queue-cvb-s1 again with QUEUE / MAX_WAIT_H / MIN_FREE_GIB as originally launched (2026-10-02 09:28)
8
+ set -uo pipefail
9
+ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
10
+ S=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/paired_finetune_intradataset_20260927/scsemi
11
+ log() { echo "$(date -Is) $*"; }
12
+ busy() {
13
+ local u
14
+ for u in $(systemctl --user list-units --type=service --state=running --no-legend | awk '{print $1}'); do
15
+ case $u in
16
+ mljob*) systemctl --user show "$u" -p ExecStart --value | grep -q 'run_scsemi' && return 0 ;;
17
+ scsemi-queue*) ;;
18
+ scsemi-*) return 0 ;;
19
+ esac
20
+ done
21
+ return 1
22
+ }
23
+ log "waiting for the current scSemiProfiler step to end"
24
+ while busy; do sleep 5; done
25
+ systemctl --user stop scsemi-queue-cvb-s1
26
+ log "scsemi-queue-cvb-s1 stopped (paused for LOCO); last queue log lines:"
27
+ grep -v '^unit' "$(ls -t "$S"/logs/queue_server1_cv_budget*.log | head -1)" | tail -2
28
+ while systemctl --user is-active --quiet loco-queue-s1 \
29
+ || ssh -n spark-0110 'XDG_RUNTIME_DIR=/run/user/$(id -u) systemctl --user is-active loco-queue-s2' 2>/dev/null | grep -q '^active'; do
30
+ sleep 300
31
+ done
32
+ systemctl --user reset-failed scsemi-queue-cvb-s1 2>/dev/null
33
+ systemd-run --user --unit=scsemi-queue-cvb-s1 --setenv=QUEUE="$S/queues/server1_cv_budget_20261002.txt" \
34
+ --setenv=MAX_WAIT_H=480 --setenv=MIN_FREE_GIB=80 /bin/bash "$S/tools/run_queue_scsemi.sh"
35
+ log "LOCO queues finished; scsemi-queue-cvb-s1 restarted"
paper-releases/pbisc-diffusion/updates/20261003T103040Z-crosscohort-k1000-saturation/diffusion/dataset/server_1/model8/plans/paired_crosscohort_20261002/tools/run_loco_queue.sh ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Cross-cohort (LOCO) queue: the same queue file runs on server_1 and server_2; each line is one unit that a host
3
+ # claims before it starts (atomic mkdir in claims/ on server_1, so a unit never runs on both hosts).
4
+ # zs|COHORT|K base model on data/<cohort>/test_raw_K<K>.npz -> generated/<cohort>/zs_K<K>.npz
5
+ # xcal|SPLIT|K base model on splits/<split>/test_xcal_K<K>.npz -> generated/<held>/<split>/xcal_K<K>.npz
6
+ # loco|SPLIT|K|TAG|MODE|LR[|extra] fine-tune (ft_sdd_multi.py) -> runs/<split>/K<K>/<TAG>/, then sample the held-out
7
+ # cohort's test_raw_K<K>.npz -> generated/<held>/<split>/K<K>_<TAG>.npz; with --block
8
+ # (step saturation) every milestone checkpoint -> .../K<K>_<TAG>_s<step>.npz
9
+ # Every GPU step goes through ml-run (ml.slice, shared GPU lock) after the thermal gate and gpu_usable.sh (shared with
10
+ # the scSemiProfiler queue: when only this user's ml.slice job holds the GPU, ml-run waits on the lock, so the two
11
+ # queues alternate and never overlap). Sampling: the sampler call of utility_studies sample_queue.sh (DDIM 50,
12
+ # Bernoulli read-out, seed 20260927, 1,500 cells per bulk), behind this queue's gate.
13
+ # On server_2 every finished unit is copied back to the same absolute paths on server_1 (sha-checked).
14
+ # A host claims a unit only after its GPU gate passes. A failed unit is marked FAILED in its claim and not retried;
15
+ # two failures in a row stop the queue.
16
+ # env: QUEUE (required), REVERSE (0; 1 = walk the queue from the end), MAX_WAIT_H (480)
17
+ set -uo pipefail
18
+ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
19
+ export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=$XDG_RUNTIME_DIR/bus}"
20
+ M8=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion
21
+ P=$M8/plans/paired_crosscohort_20261002
22
+ SQ=$M8/plans/utility_studies_final6k_20260925/tools/sample_queue.sh
23
+ BASE_CKPT=$M8/runs/f01_6k_1x_seed20260627/checkpoint_epoch_016.pt
24
+ BASE_SHA=8c7cd0e83e2bc19fe03dfcbc084919a1e2f61be8cc8bc12f4caf543dfda91633
25
+ SEED=20260927
26
+ COORD=spark-fa6b
27
+ case "$(hostname -s)" in
28
+ spark-fa6b) HOST=server_1; PY=/home/sj_server_1/miniforge3/envs/b2sc-cu130/bin/python ;;
29
+ spark-0110) HOST=server_2; PY=/home/sj_server_2/miniforge3/envs/b2sc-infer/bin/python ;;
30
+ *) echo "unknown host" >&2; exit 2 ;;
31
+ esac
32
+ QUEUE="${QUEUE:?QUEUE}"; REVERSE="${REVERSE:-0}"; MAX_WAIT_H="${MAX_WAIT_H:-480}"
33
+ mkdir -p "$P/logs"
34
+ LOG=$P/logs/loco_queue_$(basename "$QUEUE" .txt)_${HOST}_$(date +%Y%m%dT%H%M%S).log
35
+ log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
36
+ start=$(date +%s)
37
+
38
+ on_coord() { if [[ $HOST == server_1 ]]; then bash -c "$1"; else ssh -n "$COORD" "$1"; fi; }
39
+ claim() { # claim KEY -> 0 if this host now owns the unit
40
+ on_coord "mkdir -p '$P/claims' && mkdir '$P/claims/$1' 2>/dev/null && echo '$HOST $(date -Is)' > '$P/claims/$1/OWNER'"
41
+ }
42
+ mark() { on_coord "echo '$HOST $(date -Is) ${3:-}' > '$P/claims/$1/$2'"; }
43
+ usable_or_own() {
44
+ # gpu_usable.sh (free GPU, or a foreign process idle at <= 5 %), or else: every compute process on the GPU is this
45
+ # user's own job inside ml.slice (the scSemiProfiler queue holding the shared lock). In that case ml-run below blocks
46
+ # on the shared lock and the two queues take turns, never overlapping. Anything else (another user's process at
47
+ # work, memory below 32 GiB, guard inactive) waits.
48
+ local r; r=$(bash "$M8/plans/arch_ablation_6k_20260913/tools/gpu_usable.sh" 2>/dev/null) && { echo "$r"; return 0; }
49
+ systemctl --user is-active --quiet ml-memory-guard.service || return 1
50
+ local avail; avail=$(awk '/MemAvailable/ {print int($2/1048576)}' /proc/meminfo); (( avail >= 32 )) || return 1
51
+ local pids p; pids=$(nvidia-smi --query-compute-apps=pid --format=csv,noheader | tr -d ' ')
52
+ [[ -n $pids ]] || return 1
53
+ for p in $pids; do
54
+ [[ "$(stat -c %U "/proc/$p" 2>/dev/null)" == "$(id -un)" ]] && grep -q '/ml.slice/' "/proc/$p/cgroup" 2>/dev/null || return 1
55
+ done
56
+ echo "own ml.slice job on the GPU; waiting on the shared lock"
57
+ }
58
+ gate() {
59
+ until verdict=$(bash "$M8/plans/floor01_campaign_20260923/tools/thermal_guard.sh") && usable=$(usable_or_own); do
60
+ (( $(date +%s) - start > MAX_WAIT_H * 3600 )) && { log "ABORT: no usable GPU within ${MAX_WAIT_H} h"; exit 1; }
61
+ sleep 60
62
+ done
63
+ echo "$verdict; GPU $usable"
64
+ }
65
+ copy_back() { # server_2 -> server_1, same absolute paths; NPZ checked against its receipt's sha256
66
+ [[ $HOST == server_1 ]] && return 0
67
+ local f
68
+ for f in "$@"; do
69
+ [[ -e $f ]] || continue
70
+ ssh -n "$COORD" "mkdir -p '$(dirname "$f")'" && rsync -a "$f" "$COORD:$(dirname "$f")/" || return 1
71
+ done
72
+ return 0
73
+ }
74
+ yield_gpu() { # after each GPU step: if another of this user's GPU queues is active, pause longer than its 120 s gate
75
+ # poll so that it gets the next turn on the shared lock (the queues alternate instead of one starving the other)
76
+ local u
77
+ for u in $(systemctl --user list-units --type=service --state=active --no-legend 2>/dev/null | awk '{print $1}' \
78
+ | grep -E '^scsemi-queue'); do
79
+ log "yield: $u is active; pausing 150 s"; sleep 150; return 0
80
+ done
81
+ }
82
+ sample() { # sample TAG CKPT CKPT_SHA COND OUT -- the sampler call of sample_queue.sh ($SQ), with this queue's gate
83
+ local tag=$1 ck=$2 sha=$3 cond=$4 out=$5 rec=${5%.npz}.log err=${5%.npz}.err
84
+ if [[ -s $rec && -s $out ]]; then log "$tag already sampled; skipped"; return 0; fi
85
+ [[ -s $cond ]] || { log "WARN: $tag condition missing: $cond"; return 1; }
86
+ [[ "$(sha256sum "$ck" | cut -d' ' -f1)" == "$sha" ]] || { log "WARN: $tag checkpoint sha differs"; return 1; }
87
+ mkdir -p "$(dirname "$out")"
88
+ log "--- sample $tag seed=$SEED ($(gate))"
89
+ if "$HOME/.local/bin/ml-run" /usr/bin/env CUDA_VISIBLE_DEVICES=0 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
90
+ PYTHONPATH="$M8/src" OMP_NUM_THREADS=4 "$PY" -u "$M8/scripts/sample_sdd_standalone.py" \
91
+ --checkpoint "$ck" --condition-npz "$cond" --output "$out" --weights ema --batch-size 256 \
92
+ --steps 50 --seed "$SEED" --device cuda --conditioner-source embedded \
93
+ --active-logit-threshold 0.0 --support-readout bernoulli > "$rec" 2> "$err"; then
94
+ log "$tag sampled: $(python3 -c "import json;d=json.load(open('$rec'));print('zero_frac %.4f' % d.get('generated_zero_fraction',-1), d.get('output_sha256','')[:12])" 2>/dev/null)"
95
+ else
96
+ log "WARN: $tag sampling failed (see $err)"; rm -f "$rec"; yield_gpu; return 1
97
+ fi
98
+ yield_gpu
99
+ [[ -s $rec && -s $out ]]
100
+ }
101
+ held_of() { python3 -c "import json;print(json.load(open('$P/splits/$1.json'))['held_out'])"; }
102
+
103
+ mapfile -t LINES < <(grep -v -e '^\s*$' -e '^#' "$QUEUE")
104
+ [[ $REVERSE == 1 ]] && mapfile -t LINES < <(printf '%s\n' "${LINES[@]}" | tac)
105
+ log "queue=$QUEUE host=$HOST units=${#LINES[@]} reverse=$REVERSE py=$PY"
106
+ fails=0; n_done=0
107
+ for line in "${LINES[@]}"; do
108
+ IFS='|' read -r kind a1 a2 a3 a4 a5 extra <<< "$line"
109
+ case $kind in
110
+ zs) key="zs_${a1}_K${a2}" ;;
111
+ xcal) key="xcal_${a1}_K${a2}" ;;
112
+ loco) key="loco_${a1}_K${a2}_${a3}" ;;
113
+ *) log "WARN: unknown line: $line"; continue ;;
114
+ esac
115
+ # wait for a usable GPU before claiming, so a host that cannot run now never holds a unit the other host could run
116
+ on_coord "test -d '$P/claims/$key'" && continue
117
+ gate > /dev/null
118
+ claim "$key" || continue
119
+ unit_t0=$(date +%s)
120
+ log "=== $key claimed"
121
+ ok=0
122
+ if [[ $kind == zs ]]; then
123
+ out=$P/generated/$a1/zs_K$a2.npz
124
+ sample "$key" "$BASE_CKPT" "$BASE_SHA" "$P/data/$a1/test_raw_K$a2.npz" "$out" && ok=1
125
+ files=("$out" "${out%.npz}.log" "${out%.npz}.err")
126
+ elif [[ $kind == xcal ]]; then
127
+ held=$(held_of "$a1"); out=$P/generated/$held/$a1/xcal_K$a2.npz
128
+ sample "$key" "$BASE_CKPT" "$BASE_SHA" "$P/splits/$a1/test_xcal_K$a2.npz" "$out" && ok=1
129
+ files=("$out" "${out%.npz}.log" "${out%.npz}.err")
130
+ else
131
+ split=$a1 K=$a2 tag=$a3 mode=$a4 lr=$a5
132
+ held=$(held_of "$split"); run=$P/runs/$split/K$K/$tag; out=$P/generated/$held/$split/K${K}_$tag.npz
133
+ mkdir -p "$run"
134
+ if [[ ! -s $run/RUN.json ]]; then
135
+ log "--- train $split K=$K $tag mode=$mode lr=$lr ($(gate))"
136
+ # shellcheck disable=SC2086
137
+ "$HOME/.local/bin/ml-run" /usr/bin/env CUDA_VISIBLE_DEVICES=0 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
138
+ OMP_NUM_THREADS=4 PYTHONUNBUFFERED=1 "$PY" -u "$P/tools/ft_sdd_multi.py" --checkpoint "$BASE_CKPT" \
139
+ --checkpoint-sha "$BASE_SHA" --split "$P/splits/$split.json" --k "$K" --mode "$mode" --lr "$lr" \
140
+ --out-dir "$run" ${extra//|/ } >> "$run/train.log" 2>&1
141
+ yield_gpu
142
+ fi
143
+ files=("$run/RUN.json" "$run/history.json" "$run/train.log" "$run/checkpoint_ft.pt")
144
+ if [[ -s $run/RUN.json ]]; then
145
+ sha=$(python3 -c "import json;print(json.load(open('$run/RUN.json'))['checkpoint_sha256'])")
146
+ log "train $key: $(python3 -c "import json;d=json.load(open('$run/RUN.json'));print('selected step',d['selected_step'],'of',d['steps_run'],'stop',d.get('stop_reason'),'inner-val %.5f (pre %.5f)'%(d['selected_inner_val_loss'],d['pretrained_inner_val_loss']),'%.0f s'%d['wall_seconds'])")"
147
+ ms=$(python3 -c "import json;d=json.load(open('$run/RUN.json'));print(' '.join('%d:%s' % (m['milestone_step'], m['checkpoint_sha256']) for m in d.get('milestones') or []))")
148
+ if [[ -n $ms ]]; then
149
+ # step-saturation runs: sample every milestone checkpoint (best-so-far at each block end) -> K<K>_<tag>_s<step>
150
+ ok=1; files+=("$run/milestones.json")
151
+ for x in $ms; do
152
+ st=${x%%:*}; msha=${x#*:}; out=$P/generated/$held/$split/K${K}_${tag}_s${st}.npz
153
+ sample "${key}_s${st}" "$run/checkpoint_ft_s${st}.pt" "$msha" "$P/data/$held/test_raw_K$K.npz" "$out" || ok=0
154
+ files+=("$run/checkpoint_ft_s${st}.pt" "$out" "${out%.npz}.log" "${out%.npz}.err")
155
+ done
156
+ else
157
+ sample "$key" "$run/checkpoint_ft.pt" "$sha" "$P/data/$held/test_raw_K$K.npz" "$out" && ok=1
158
+ files+=("$out" "${out%.npz}.log" "${out%.npz}.err")
159
+ fi
160
+ else
161
+ log "WARN: train $key failed (see $run/train.log)"
162
+ fi
163
+ fi
164
+ if (( ok )); then
165
+ copy_back "${files[@]}" || { log "WARN: $key copy to server_1 failed; outputs kept on $HOST"; ok=0; }
166
+ fi
167
+ if (( ok )); then
168
+ mark "$key" DONE "$(python3 -c "import json;print(json.load(open('${out%.npz}.log'))['output_sha256'])")"
169
+ log "=== $key done"; fails=0; n_done=$((n_done+1))
170
+ else
171
+ mark "$key" FAILED; log "=== $key FAILED"; fails=$((fails+1))
172
+ # host policy: after a memory-guard stop, inspect before any further GPU work -> never move on to the next unit
173
+ if journalctl -t ml-memory-guard --since "@$unit_t0" --no-pager 2>/dev/null | grep -q "stopping ml.slice"; then
174
+ log "ABORT: the memory guard stopped ml.slice during $key; queue stopped for inspection (no further units)"
175
+ exit 1
176
+ fi
177
+ (( fails >= 2 )) && { log "ABORT: two failed units in a row"; exit 1; }
178
+ fi
179
+ done
180
+ log "queue finished on $HOST: units done here=$n_done"
paper-releases/pbisc-diffusion/updates/20261003T103040Z-crosscohort-k1000-saturation/diffusion/dataset/server_1/model8/plans/paired_crosscohort_20261002/tools/score_pending.sh ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Score every finished LOCO arm on server_1 (CPU), one arm per score_ft.py call, as soon as it exists.
3
+ # Each call scores the held-out cohort's usable samples (data/<cohort>/usable_samples.txt) against the cohort's frozen
4
+ # reference (scoring_cache of the within-cohort benchmark), so calls are comparable with each other and with that
5
+ # benchmark's pooled 5-fold call (same donors, same reference; checked by aggregate_loco.py).
6
+ # arms: zs_K1000 (the within-cohort benchmark's zero-shot on all usable rows; same model, sampler, seed and bulk
7
+ # arrays as zs_K2000 apart from K), zs_K2000, xcal_K<K>, loco_<tag>_K<K>, and with training-only cohorts
8
+ # added to the pool (splits hoL_*) xcalL_K<K>, locoL_<tag>_K<K>
9
+ # out: scores/<cohort>/<arm>/ ; Giroux also scores_nosex/giroux2022/<arm>/ (sex-linked genes excluded from the
10
+ # disease metrics, labels reused), as the deck reports Giroux
11
+ # Runs until both LOCO queues (server_1 loco-queue-s1, server_2 loco-queue-s2) are inactive and nothing is pending.
12
+ set -uo pipefail
13
+ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
14
+ export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=$XDG_RUNTIME_DIR/bus}"
15
+ M8=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion
16
+ P=$M8/plans/paired_crosscohort_20261002
17
+ SRC=$M8/plans/paired_finetune_intradataset_20260927
18
+ PY=/home/sj_server_1/miniforge3/envs/cxg_corpus/bin/python
19
+ SEX=$SRC/data/sex_linked_genes/sex_linked_genes_exclude.csv
20
+ COHORTS=(immicro ye2026_sepsis imperial_eskd giroux2022 ji2025_chili)
21
+ LOG=$P/logs/score_pending_$(date +%Y%m%dT%H%M%S).log
22
+ mkdir -p "$P/logs"
23
+ log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
24
+
25
+ zs1000() { # the within-cohort benchmark's zero-shot NPZ (Imperial's lives on server_2: copied once, sha-checked)
26
+ local c=$1 f=$SRC/generated/$1/fewshot_n5/zs__raw_all.npz
27
+ if [[ -s $f ]]; then echo "$f"; return; fi
28
+ local d=$P/inputs_server2/$c; f=$d/zs__raw_all.npz
29
+ if [[ ! -s $f ]]; then
30
+ mkdir -p "$d" && rsync -a "spark-0110:$SRC/generated/$c/fewshot_n5/zs__raw_all.npz" \
31
+ "spark-0110:$SRC/generated/$c/fewshot_n5/zs__raw_all.log" "$d/" || { rm -f "$f"; return 1; }
32
+ fi
33
+ echo "$f"
34
+ }
35
+ arms_of() { # prints "ARM NPZ" for every arm of cohort $1 whose NPZ and receipt exist
36
+ # split ho_<c>: arms xcal_K<K>, loco_<tag>_K<K>; split hoL_<c> (training pool + training-only cohorts such as
37
+ # Liu 2021, tools/prepare_loco_extra.py): arms xcalL_K<K>, locoL_<tag>_K<K>
38
+ local c=$1 f K tag b s suf
39
+ f=$(zs1000 "$c") && echo "zs_K1000 $f"
40
+ f=$P/generated/$c/zs_K2000.npz
41
+ [[ -s $f && -s ${f%.npz}.log ]] && echo "zs_K2000 $f"
42
+ for s in "ho_$c" "hoL_$c"; do
43
+ suf=""; [[ $s == hoL_* ]] && suf=L
44
+ for f in "$P/generated/$c/$s"/xcal_K*.npz "$P/generated/$c/$s"/K*_*.npz; do
45
+ [[ -s $f && -s ${f%.npz}.log ]] || continue
46
+ b=$(basename "$f" .npz)
47
+ if [[ $b == xcal_K* ]]; then echo "xcal${suf}_${b#xcal_} $f"
48
+ else K=${b%%_*}; tag=${b#*_}; echo "loco${suf}_${tag}_${K} $f"; fi
49
+ done
50
+ done
51
+ }
52
+ score_one() { # cohort arm npz [extra args]
53
+ local c=$1 arm=$2 npz=$3; shift 3
54
+ local name=score-${c}-${arm}-$(date +%H%M%S)
55
+ local avail; avail=$(awk '/MemAvailable/ {print int($2/1048576)}' /proc/meminfo)
56
+ (( avail >= 56 )) || { log "MemAvailable $avail GiB < 56: $c $arm waits"; return 1; }
57
+ read -r -a cargs <<< "$(bash "$SRC/tools/contrast_args.sh" "$c")"
58
+ systemd-run --user --unit="$name" --working-directory="$P" --wait --collect --quiet \
59
+ -p MemoryMax=24G -p MemorySwapMax=0 -p CPUQuota=800% -p Nice=10 \
60
+ -p StandardOutput=append:"$P/logs/$name.log" -p StandardError=append:"$P/logs/$name.log" \
61
+ --setenv=CUDA_VISIBLE_DEVICES= --setenv=PYTHONNOUSERSITE=1 --setenv=PYTHONDONTWRITEBYTECODE=1 \
62
+ --setenv=PYTHONUNBUFFERED=1 --setenv=OMP_NUM_THREADS=8 --setenv=OPENBLAS_NUM_THREADS=8 \
63
+ --setenv=MKL_NUM_THREADS=8 --setenv=NUMBA_NUM_THREADS=8 \
64
+ "$PY" "$SRC/tools/score_ft.py" --dataset "$c" --threads 8 --donors "$P/data/$c/usable_samples.txt" \
65
+ --arm "$arm=$npz" "${cargs[@]}" "$@"
66
+ }
67
+ queues_active() {
68
+ systemctl --user is-active --quiet loco-queue-s1 && return 0
69
+ ssh -n spark-0110 'XDG_RUNTIME_DIR=/run/user/$(id -u) systemctl --user is-active loco-queue-s2' 2>/dev/null | grep -q '^active' && return 0
70
+ return 1
71
+ }
72
+
73
+ log "start"
74
+ while true; do
75
+ active=0; queues_active && active=1
76
+ pending=0
77
+ for c in "${COHORTS[@]}"; do
78
+ while read -r arm npz; do
79
+ [[ -n $arm ]] || continue
80
+ out=$P/scores/$c/$arm
81
+ # a failed call leaves <out>.FAILED and is not retried (inspect logs/score-<cohort>-<arm>-*.log, then remove it)
82
+ if [[ ! -s $out/summary.json && ! -e $out.FAILED ]]; then
83
+ pending=1
84
+ log "score $c $arm"
85
+ if score_one "$c" "$arm" "$npz" --out "$out"; then log "scored $c $arm"
86
+ else log "WARN: scoring $c $arm failed (logs/score-$c-$arm-*.log)"; date -Is > "$out.FAILED"; fi
87
+ fi
88
+ nos=$P/scores_nosex/$c/$arm
89
+ if [[ $c == giroux2022 && -s $out/summary.json && ! -s $nos/summary.json && ! -e $nos.FAILED ]]; then
90
+ pending=1
91
+ mkdir -p "$(dirname "$nos")"
92
+ if score_one "$c" "$arm" "$npz" --out "$nos" --exclude-genes "$SEX" --reuse-labels "$out"; then
93
+ log "scored $c $arm (sex-linked genes excluded)"
94
+ else log "WARN: no-sex rescore $c $arm failed"; date -Is > "$nos.FAILED"; fi
95
+ fi
96
+ done < <(arms_of "$c")
97
+ done
98
+ # fully scored NPZs go to server_2 (same path, sha-checked; an Imperial set is ~6 GB): tools/offload_scored.sh
99
+ (( pending )) && bash "$P/tools/offload_scored.sh" >> "$P/logs/offload_scored.log" 2>&1
100
+ if (( ! active && ! pending )); then log "queues inactive and nothing pending: done"; break; fi
101
+ sleep 60
102
+ done
paper-releases/pbisc-diffusion/updates/20261003T103040Z-crosscohort-k1000-saturation/diffusion/dataset/server_1/model8/plans/paired_crosscohort_20261002/tools/swap_runner_after_unit.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # One-off (2026-10-02): restart the server_1 LOCO runner with the current run_loco_queue.sh as soon as the unit it is
3
+ # running finishes, without losing work: wait for "=== <KEY> done|FAILED" in its log, stop the runner, stop any LOCO GPU
4
+ # job it had already started for the next unit, release that unit's fresh claim (no DONE / FAILED), start the runner.
5
+ # usage: swap_runner_after_unit.sh KEY LOG QUEUE
6
+ set -uo pipefail
7
+ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
8
+ P=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/paired_crosscohort_20261002
9
+ key=$1 log=$2 queue=$3
10
+ until grep -q -E "=== ${key} (done|FAILED)" "$log"; do sleep 2; done
11
+ systemctl --user stop loco-queue-s1
12
+ for u in $(systemctl --user list-units --type=service --state=running --no-legend | awk '{print $1}' | grep '^mljob'); do
13
+ systemctl --user show "$u" -p ExecStart --value | grep -q "paired_crosscohort_20261002" && { echo "stop $u"; systemctl --user stop "$u"; }
14
+ done
15
+ for d in "$P"/claims/*/; do
16
+ [[ -e $d/DONE || -e $d/FAILED || -e $d/STOPPED ]] && continue
17
+ grep -q '^server_1' "$d/OWNER" 2>/dev/null && { echo "release $(basename "$d")"; rm -rf "$d"; }
18
+ done
19
+ systemctl --user reset-failed loco-queue-s1 2>/dev/null
20
+ systemd-run --user --unit=loco-queue-s1 --setenv=QUEUE="$queue" --setenv=MAX_WAIT_H=480 -p MemorySwapMax=0 \
21
+ /bin/bash "$P/tools/run_loco_queue.sh"
22
+ echo "runner restarted $(date -Is)"