Commit ded2aaf
authored
Cache subprocess rbc invocations via RBC_STYXCACHE_DIR (#312)
* Wire styxcache into setup_runner for subprocess rbc invocations
tests/integration/test_all.py spawns `rbc all` via subprocess.run;
that fresh process hits setup_runner() rather than the pytest autouse
fixture, so it was running the full pipeline uncached. Cache diagnose
confirmed 0 new entries during warm runs and revealed `setup` of
those two fixtures took ~81 min combined.
setup_runner now wraps the configured runner with styxcache's
CachingRunner when RBC_STYXCACHE_DIR is set, matching the behavior
we already had in tests/conftest.py. The wrapping logic (attribute
proxy + policy) now lives in rbc.core.niwrap.maybe_wrap_with_cache;
tests/conftest.py imports and reuses it.
styxcache moves from dev to runtime dependency since rbc.core now
imports it unconditionally. Drop the try/except fallback and the
deptry DEP004 ignore.
* Clear RBC_STYXCACHE_DIR for setup_runner isinstance tests, evict corrupt gz cache entries
- tests/unit/test_niwrap.py::TestSetupRunner checks the concrete runner
type; ensure the env var is unset so setup_runner returns the unwrapped
runner.
- Prepare styx cache now runs gzip -t on every .styxcache.stdout.gz and
.styxcache.stderr.gz, evicting any entry with a truncated stream.
Prompted by an EOFError from a half-written gz in an older cache entry
that survived into a warm run.
* Extend corrupt-gz eviction to all .gz files in cache shards
Earlier scan only looked at .styxcache.stdout.gz / .stderr.gz, but nibabel
also reads cached .nii.gz outputs directly from shard paths. A truncated
cached BOLD blew up single_session_qc with the same EOFError signature.
* Move rbc scratch dirs off cache shards via independent scratch root
Two problems with the prior generate_exec_folder pattern:
1. It hijacked the niwrap runner's data_dir + uid + execution_counter,
forcing _CacheProxyingRunner to forward those attributes through to
the base runner on every access.
2. Several rbc sites then wrote sibling files via `input_file.parent /
...`. When input_file was served from a styxcache shard (which is
the norm under caching), those writes landed inside the shard,
racing other workers' reads and silently truncating cached files.
The test_single_session_qc EOFError was a cached .nii.gz truncated
this way.
generate_exec_folder now owns its own root (RBC_SCRATCH_DIR override,
else a process-unique tempfile.mkdtemp). Every touched call site was
migrated off `input_file.parent / ...` to `generate_exec_folder(...) /
...`. Sites audited:
- core/functional/resampling.py:107, 201
- core/functional/nuisance.py:112
- core/longitudinal/transform.py:145
- core/longitudinal/freesurfer.py:142
- core/metrics/reho.py:191
- core/metrics/alff.py:259
- core/metrics/standardization.py:74
- core/metrics/timeseries.py:159
distortion.py's topup.parent is a read-only lookup into the tool's own
output set (no write), left as-is.
Unit tests for generate_exec_folder rewritten for the new semantics:
no more uid/counter-based naming, just unique scratch dirs.
* Unify niwrap data_dir and rbc scratch under a single RBC_WORK_DIR root
Previously generate_exec_folder had its own RBC_SCRATCH_DIR while
niwrap's data_dir defaulted to the system tmp. One knob is cleaner:
RBC_WORK_DIR now parents both (niwrap/, scratch/). CI points it at
JOB_TMP so the per-run cleanup reclaims both trees in one sweep.
* CLI --tmp-dir now parents rbc scratch too, not just niwrap data_dir1 parent 5e35d78 commit ded2aaf
16 files changed
Lines changed: 169 additions & 103 deletions
File tree
- .github/workflows
- src/rbc/core
- functional
- longitudinal
- metrics
- tests
- unit
- core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
53 | 74 | | |
54 | 75 | | |
55 | 76 | | |
| |||
85 | 106 | | |
86 | 107 | | |
87 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
88 | 112 | | |
89 | 113 | | |
90 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 47 | | |
53 | 48 | | |
54 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | 24 | | |
34 | 25 | | |
35 | 26 | | |
| |||
52 | 43 | | |
53 | 44 | | |
54 | 45 | | |
55 | | - | |
| 46 | + | |
56 | 47 | | |
57 | 48 | | |
58 | 49 | | |
59 | | - | |
| 50 | + | |
60 | 51 | | |
61 | 52 | | |
62 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
145 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
259 | | - | |
| 260 | + | |
| 261 | + | |
260 | 262 | | |
261 | 263 | | |
262 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
191 | | - | |
| 192 | + | |
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | | - | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
0 commit comments