Skip to content

Commit f662be8

Browse files
committed
✨ Add memory optimization to C-PAC bootstrap script & set version to 1.8.4 release
1 parent 405d3c4 commit f662be8

File tree

1 file changed

+79
-26
lines changed

1 file changed

+79
-26
lines changed

scripts/cubic/bootstrap-c-pac.sh

100644100755
Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
## NOTE ##
22
# This workflow is derived from the Datalad Handbook
33

4+
# In addition to the positional arguments described in https://pennlinc.github.io/docs/TheWay/RunningDataLadPipelines/#preparing-the-analysis-dataset ,
5+
# this bootstrap script also takes a /full/path/to/callback.log i.e.,
6+
# `bash bootstrap-c-pac.sh /full/path/to/BIDS /full/path/to/cpac-container /full/path/to/callback.log`
7+
# for optimizing memory (see https://fcp-indi.github.io/docs/nightly/user/tutorials/observed_usage for C-PAC optimization tutorial, and see
8+
# sections marked "C-PAC-specific memory optimization" in this script for details).
9+
410
## Ensure the environment is ready to bootstrap the analysis workspace
511
# Check that we have conda installed
612
#conda activate
@@ -23,7 +29,7 @@ set -e -u
2329

2430

2531
## Set up the directory that will contain the necessary directories
26-
PROJECTROOT=${PWD}/c-pac-1.8.3
32+
PROJECTROOT=${PWD}/c-pac-1.8.4
2733
if [[ -d ${PROJECTROOT} ]]
2834
then
2935
echo ${PROJECTROOT} already exists
@@ -37,7 +43,11 @@ then
3743
fi
3844

3945

40-
## Check the BIDS input
46+
# C-PAC-specific memory optimization
47+
CALLBACK_LOG=$3
48+
# ----------------------------------
49+
50+
4151
BIDSINPUT=$1
4252
if [[ -z ${BIDSINPUT} ]]
4353
then
@@ -109,6 +119,14 @@ fi
109119
cd ${PROJECTROOT}/analysis
110120
datalad install -d . --source ${PROJECTROOT}/pennlinc-containers
111121

122+
123+
# C-PAC-specific memory optimization ---------
124+
if [[ ! -z "${CALLBACK_LOG}" ]]; then
125+
ln $CALLBACK_LOG code/runtime_callback.log
126+
fi
127+
# --------------------------------------------
128+
129+
112130
## the actual compute job specification
113131
cat > code/participant_job.sh << "EOT"
114132
#!/bin/bash
@@ -173,16 +191,31 @@ datalad get -n "inputs/data/${subid}"
173191
# ------------------------------------------------------------------------------
174192
# Do the run!
175193
176-
datalad run \
177-
-i code/c-pac_zip.sh \
178-
-i code/RBC_pipeline.yml \
179-
-i inputs/data/${subid} \
180-
-i inputs/data/*json \
181-
-i pennlinc-containers/.datalad/environments/cpac-1-8-3/image \
182-
--explicit \
183-
-o ${subid}_c-pac-1.8.3.zip \
184-
-m "C-PAC:1.8.3 ${subid}" \
185-
"bash ./code/c-pac_zip.sh ${subid}"
194+
# C-PAC-specific memory optimization --------------------------------
195+
if [[ -f code/runtime_callback.log ]]
196+
then
197+
datalad run \
198+
-i code/c-pac_zip.sh \
199+
-i code/runtime_callback.log \
200+
-i inputs/data/${subid} \
201+
-i inputs/data/*json \
202+
-i pennlinc-containers/.datalad/environments/cpac-1-8-4/image \
203+
--explicit \
204+
-o ${subid}_c-pac-1.8.4.zip \
205+
-m "C-PAC:1.8.4-dev ${subid}" \
206+
"bash ./code/c-pac_zip.sh ${subid}"
207+
# -------------------------------------------------------------------
208+
else
209+
datalad run \
210+
-i code/c-pac_zip.sh \
211+
-i inputs/data/${subid} \
212+
-i inputs/data/*json \
213+
-i pennlinc-containers/.datalad/environments/cpac-1-8-4/image \
214+
--explicit \
215+
-o ${subid}_c-pac-1.8.4.zip \
216+
-m "C-PAC:1.8.4-dev ${subid}" \
217+
"bash ./code/c-pac_zip.sh ${subid}"
218+
fi
186219
187220
# file content first -- does not need a lock, no interaction with Git
188221
datalad push --to output-storage
@@ -210,20 +243,40 @@ set -e -u -x
210243
211244
subid="$1"
212245
mkdir -p ${subid}_outputs
213-
singularity run --cleanenv \
214-
-B ${PWD} \
215-
-B ${PWD}/${subid}_outputs:/outputs \
216-
pennlinc-containers/.datalad/environments/cpac-1-8-3/image \
217-
inputs/data \
218-
/outputs \
219-
participant \
220-
--preconfig rbc-options \
221-
--skip_bids_validator \
222-
--n_cpus 4 \
223-
--mem_gb 32 \
224-
--participant_label "$subid"
225-
226-
7z a ${subid}_c-pac-1.8.3.zip ${subid}_outputs
246+
# C-PAC-specific memory optimization -----------------------------
247+
if [[ -f code/runtime_callback.log ]]
248+
then
249+
singularity run --cleanenv \
250+
-B ${PWD} \
251+
-B ${PWD}/${subid}_outputs:/outputs \
252+
pennlinc-containers/.datalad/environments/cpac-1-8-4/image \
253+
inputs/data \
254+
/outputs \
255+
participant \
256+
--preconfig rbc-options \
257+
--skip_bids_validator \
258+
--n_cpus 4 \
259+
--mem_gb 32 \
260+
--participant_label "$subid" \
261+
--runtime_usage=code/runtime_callback.log \
262+
--runtime_buffer=30
263+
# ----------------------------------------------------------------
264+
else
265+
singularity run --cleanenv \
266+
-B ${PWD} \
267+
-B ${PWD}/${subid}_outputs:/outputs \
268+
pennlinc-containers/.datalad/environments/cpac-1-8-4/image \
269+
inputs/data \
270+
/outputs \
271+
participant \
272+
--preconfig rbc-options \
273+
--skip_bids_validator \
274+
--n_cpus 4 \
275+
--mem_gb 32 \
276+
--participant_label "$subid"
277+
fi
278+
279+
7z a ${subid}_c-pac-1.8.4.zip ${subid}_outputs
227280
rm -rf ${subid}_outputs
228281
229282
EOT

0 commit comments

Comments
 (0)