-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun_analysis
More file actions
executable file
·340 lines (300 loc) · 10.7 KB
/
Copy pathrun_analysis
File metadata and controls
executable file
·340 lines (300 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env bash
# ACTL-native entry point for Sampleworks analysis/evaluation preset runs.
#
# The TOML preset is the source of truth. This wrapper mirrors run_experiments
# but targets analyses/*.toml presets and executes scripts/eval jobs through the
# shared Python runner backend.
set -euo pipefail
script_path="${BASH_SOURCE[0]}"
while [[ -L "$script_path" ]]; do
script_dir="$(cd -- "$(dirname -- "$script_path")" && pwd)"
script_target="$(readlink "$script_path")"
if [[ "$script_target" == /* ]]; then
script_path="$script_target"
else
script_path="$script_dir/$script_target"
fi
done
script_dir="$(cd -- "$(dirname -- "$script_path")" && pwd)"
is_sampleworks_root() {
local candidate="$1"
[[ -f "$candidate/pyproject.toml" && -d "$candidate/src/sampleworks" && -d "$candidate/scripts/eval" ]]
}
find_sampleworks_root_upwards() {
local candidate="$1"
while [[ -n "$candidate" && "$candidate" != "/" ]]; do
if is_sampleworks_root "$candidate"; then
printf '%s\n' "$candidate"
return 0
fi
candidate="$(dirname -- "$candidate")"
done
return 1
}
truthy_env() {
local name="$1"
[[ "${!name:-}" =~ ^(1|true|yes)$ ]]
}
require_env_var() {
local name="$1"
local help_text="$2"
if [[ -z "${!name:-}" ]]; then
cat >&2 <<EOF
$name must be set explicitly for run_analysis.
$help_text
EOF
return 2
fi
}
pixi_inputs_match_image() {
local image_root="$1"
local source_root="$2"
[[ -f "$image_root/pyproject.toml" && -f "$image_root/pixi.lock" ]] || return 0
[[ -f "$source_root/pyproject.toml" && -f "$source_root/pixi.lock" ]] || return 0
cmp -s "$image_root/pyproject.toml" "$source_root/pyproject.toml" && \
cmp -s "$image_root/pixi.lock" "$source_root/pixi.lock"
}
resolve_repo_root() {
local source_override="${SAMPLEWORKS_SOURCE_DIR:-}"
if [[ -n "$source_override" ]]; then
if ! is_sampleworks_root "$source_override"; then
cat >&2 <<EOF
SAMPLEWORKS_SOURCE_DIR does not point to a Sampleworks checkout:
$source_override
EOF
return 2
fi
printf '%s\n' "$source_override"
return 0
fi
if is_sampleworks_root "/home/dev/workspace"; then
printf '%s\n' "/home/dev/workspace"
return 0
fi
find_sampleworks_root_upwards "$PWD" && return 0
local app_override="${SAMPLEWORKS_APP_DIR:-}"
if [[ -n "$app_override" ]] && is_sampleworks_root "$app_override"; then
printf '%s\n' "$app_override"
return 0
fi
if is_sampleworks_root "$script_dir"; then
printf '%s\n' "$script_dir"
return 0
fi
cat >&2 <<'EOF'
Could not find the synced Sampleworks checkout.
Expected ACTL to sync the repo to /home/dev/workspace. If you are using a
custom layout, set SAMPLEWORKS_SOURCE_DIR=/path/to/sampleworks before running
run_analysis.
EOF
return 2
}
repo_root="$(resolve_repo_root)"
env_preset="${SAMPLEWORKS_ANALYSIS_PRESET:-}"
default_target="$env_preset"
target=""
explicit_preset=""
explicit_jobs=""
explicit_results_dir=""
expect_value_for=""
for arg in "$@"; do
if [[ -n "$expect_value_for" ]]; then
case "$expect_value_for" in
preset)
explicit_preset="$arg"
;;
results-dir)
explicit_results_dir="$arg"
;;
jobs)
explicit_jobs="$arg"
;;
esac
expect_value_for=""
continue
fi
case "$arg" in
--preset)
expect_value_for="preset"
;;
--preset=*)
explicit_preset="${arg#--preset=}"
;;
--results-dir)
expect_value_for="results-dir"
;;
--results-dir=*)
explicit_results_dir="${arg#--results-dir=}"
;;
--jobs)
expect_value_for="jobs"
;;
--jobs=*)
explicit_jobs="${arg#--jobs=}"
;;
-*)
;;
*)
if [[ -z "$target" ]]; then
target="$arg"
fi
;;
esac
done
needs_run_config=1
for arg in "$@"; do
case "$arg" in
--list|-h|--help)
needs_run_config=0
;;
esac
done
if [[
"$needs_run_config" -eq 1 &&
-z "$target" &&
-z "$explicit_preset" &&
-z "$explicit_jobs" &&
-z "$env_preset"
]]; then
target="analyze_grid_search"
fi
label_source="$default_target"
if [[ -n "$explicit_preset" ]]; then
label_source="$explicit_preset"
elif [[ -n "$explicit_jobs" && ( -z "$target" || "$target" == "all" || "$target" == "grid_search" || "$target" == "analyze_grid_search" ) ]]; then
label_source="$explicit_jobs"
elif [[ -n "$target" ]]; then
label_source="$target"
fi
if [[ "$label_source" == *.toml || "$label_source" == */* ]]; then
if [[ "$label_source" != /* ]]; then
label_source="$repo_root/$label_source"
fi
fi
run_label="${label_source##*/}"
run_label="${run_label%.toml}"
run_label="${run_label//,/_}"
run_name="${SAMPLEWORKS_ACTL_RUN_NAME:-$(hostname -s 2>/dev/null || printf 'sampleworks')}"
default_grid_results_dir="/mnt/diffuse-shared/results/sampleworks/${run_name}/${run_label}"
default_grid_inputs_dir="/mnt/diffuse-shared/raw/sampleworks/initial_dataset_40_occ_sweeps"
if [[ -n "$explicit_results_dir" ]]; then
export GRID_SEARCH_RESULTS_DIR="$explicit_results_dir"
else
export GRID_SEARCH_RESULTS_DIR="${GRID_SEARCH_RESULTS_DIR:-${RESULTS_DIR:-${SAMPLEWORKS_RESULTS_DIR:-$default_grid_results_dir}}}"
fi
export RESULTS_DIR="${RESULTS_DIR:-$GRID_SEARCH_RESULTS_DIR}"
export GRID_SEARCH_INPUTS_DIR="${GRID_SEARCH_INPUTS_DIR:-${DATA_DIR:-${SAMPLEWORKS_DATA_DIR:-$default_grid_inputs_dir}}}"
export ALTLOC_ANALYSIS_DIR="${ALTLOC_ANALYSIS_DIR:-${SAMPLEWORKS_ALTLOC_ANALYSIS_DIR:-$default_grid_results_dir}}"
export ALTLOC_INPUTS_DIR="${ALTLOC_INPUTS_DIR:-${SAMPLEWORKS_ALTLOC_INPUTS_DIR:-$GRID_SEARCH_INPUTS_DIR}}"
export PROTEIN_CONFIGS_CSV="${PROTEIN_CONFIGS_CSV:-${SAMPLEWORKS_PROTEIN_CONFIGS_CSV:-$GRID_SEARCH_INPUTS_DIR/protein_analysis_config.csv}}"
export TARGET_FILENAME="${TARGET_FILENAME:-${SAMPLEWORKS_TARGET_FILENAME:-refined-patched.cif}}"
export N_JOBS="${N_JOBS:-${SAMPLEWORKS_ANALYSIS_N_JOBS:-16}}"
export SAMPLEWORKS_SOURCE_DIR="$repo_root"
export SAMPLEWORKS_ANALYSES_DIR="${SAMPLEWORKS_ANALYSES_DIR:-$repo_root/analyses}"
export SAMPLEWORKS_SCRIPT_ROOT="$repo_root"
export PYTHONPATH="$repo_root/src${PYTHONPATH:+:$PYTHONPATH}"
export PIXI_CACHE_DIR="${PIXI_CACHE_DIR:-/tmp/pixi-cache}"
export UV_CACHE_DIR="${UV_CACHE_DIR:-/tmp/uv-cache}"
if [[ "$needs_run_config" -eq 1 ]]; then
require_env_var GRID_SEARCH_RESULTS_DIR \
"Set GRID_SEARCH_RESULTS_DIR or pass --results-dir to the grid-search output directory you want to evaluate."
require_env_var GRID_SEARCH_INPUTS_DIR \
"Set GRID_SEARCH_INPUTS_DIR (or DATA_DIR) to the directory containing inputs, maps, and protein config CSVs."
fi
runner_env="${SAMPLEWORKS_ANALYSIS_RUNNER_ENV:-analysis}"
if truthy_env RUNTIME_PIXI; then
export SAMPLEWORKS_ALLOW_RUNTIME_PIXI=1
fi
pixi_project_dir="${SAMPLEWORKS_PIXI_PROJECT_DIR:-}"
if [[ -z "$pixi_project_dir" ]]; then
if ! pixi_inputs_match_image /app "$repo_root" && truthy_env SAMPLEWORKS_ALLOW_RUNTIME_PIXI; then
pixi_project_dir="$repo_root"
elif [[ -f /app/pyproject.toml && -d /app/.pixi ]]; then
pixi_project_dir="/app"
else
pixi_project_dir="$repo_root"
fi
fi
export SAMPLEWORKS_PIXI_PROJECT_DIR="$pixi_project_dir"
if ! pixi_inputs_match_image /app "$repo_root"; then
if truthy_env SAMPLEWORKS_ALLOW_RUNTIME_PIXI; then
cat >&2 <<EOF
Synced pyproject.toml or pixi.lock differs from the baked image. Runtime pixi
updates are enabled, so using the synced checkout as the pixi project:
$repo_root
EOF
export SAMPLEWORKS_REQUIRE_PREBUILT_PIXI="${SAMPLEWORKS_REQUIRE_PREBUILT_PIXI:-0}"
export SAMPLEWORKS_SKIP_ENV_PREPARE="${SAMPLEWORKS_SKIP_ENV_PREPARE:-0}"
else
cat >&2 <<EOF
Synced pyproject.toml or pixi.lock differs from the baked pixi-with-checkpoints image.
Rebuild/use an image produced from this checkout, or intentionally update pixi
inside this pod by running with:
RUNTIME_PIXI=1 run_analysis ...
Runtime pixi updates can be slow, so they are disabled by default for
reproducible scientist runs.
EOF
exit 2
fi
else
export SAMPLEWORKS_REQUIRE_PREBUILT_PIXI="${SAMPLEWORKS_REQUIRE_PREBUILT_PIXI:-1}"
export SAMPLEWORKS_SKIP_ENV_PREPARE="${SAMPLEWORKS_SKIP_ENV_PREPARE:-1}"
fi
runner_python="${SAMPLEWORKS_ANALYSIS_RUNNER_PYTHON:-$pixi_project_dir/.pixi/envs/$runner_env/bin/python}"
extra_cli_args=()
if [[ $# -eq 0 && -n "$env_preset" ]]; then
extra_cli_args=(--preset "$env_preset")
fi
display_target="${target:-${explicit_preset:-$default_target}}"
if [[ -n "$explicit_jobs" ]]; then
display_target="$display_target --jobs $explicit_jobs"
fi
cat >&2 <<EOF
Sampleworks analysis run
target: $display_target
grid results: $GRID_SEARCH_RESULTS_DIR
grid inputs: $GRID_SEARCH_INPUTS_DIR
configs CSV: $PROTEIN_CONFIGS_CSV
source: $repo_root
pixi project: $pixi_project_dir
runner env: $runner_env
runner python: $runner_python
EOF
if [[ -x "$runner_python" ]]; then
runner_env_dir="$(cd -- "$(dirname -- "$runner_python")/.." && pwd)"
export PATH="$runner_env_dir/bin${PATH:+:$PATH}"
export CONDA_PREFIX="$runner_env_dir"
export CUDA_HOME="${CUDA_HOME:-$runner_env_dir}"
export PYTHONNOUSERSITE=1
cd "$repo_root"
if [[ "${#extra_cli_args[@]}" -gt 0 ]]; then
exec "$runner_python" -m sampleworks.runs.analysis_cli \
--results-dir "$GRID_SEARCH_RESULTS_DIR" \
"${extra_cli_args[@]}" \
"$@"
fi
exec "$runner_python" -m sampleworks.runs.analysis_cli \
--results-dir "$GRID_SEARCH_RESULTS_DIR" \
"$@"
fi
if ! truthy_env SAMPLEWORKS_ALLOW_RUNTIME_PIXI; then
cat >&2 <<EOF
Prebuilt analysis pixi environment is missing: $runner_python
run_analysis is for the ACTL pixi-with-checkpoints image, which must contain
ready-to-use environments under /app/.pixi. Refusing to run 'pixi run' because
that would install or refresh packages inside the pod.
Recreate the pod with the current pixi-with-checkpoints image. If you are
intentionally debugging runtime pixi setup, set RUNTIME_PIXI=1.
EOF
exit 2
fi
cd "$pixi_project_dir"
if [[ "${#extra_cli_args[@]}" -gt 0 ]]; then
exec pixi run -e "$runner_env" python -m sampleworks.runs.analysis_cli \
--results-dir "$GRID_SEARCH_RESULTS_DIR" \
"${extra_cli_args[@]}" \
"$@"
fi
exec pixi run -e "$runner_env" python -m sampleworks.runs.analysis_cli \
--results-dir "$GRID_SEARCH_RESULTS_DIR" \
"$@"