Skip to content

Commit 0d97756

Browse files
committed
TST: Run fMRI notebook on push and print output
Detect CUDA and use GPU if available.
1 parent deeedb4 commit 0d97756

File tree

3 files changed

+556
-1
lines changed

3 files changed

+556
-1
lines changed

.github/workflows/notebooks.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: Run notebooks
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
- maint/*
8+
pull_request:
9+
branches:
10+
- main
11+
- maint/*
412
schedule:
513
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC
614
# Allow job to be triggered manually from GitHub interface
@@ -99,5 +107,41 @@ jobs:
99107
run: |
100108
${{ github.workspace }}/scripts/fetch_fmri_nb_openneuro_data.sh "${TEST_DATA_HOME}"
101109
110+
- name: Install notebook env dependencies from tox
111+
run: |
112+
tox run -e notebooks --notest
113+
114+
115+
- name: Check for nvcc and set HAS_CUDA
116+
id: detect-cuda
117+
run: |
118+
if command -v nvcc &> /dev/null; then
119+
echo "nvcc found: CUDA is available"
120+
echo "HAS_CUDA=true" >> $GITHUB_ENV
121+
else
122+
echo "nvcc not found: CUDA is not available"
123+
echo "HAS_CUDA=false" >> $GITHUB_ENV
124+
fi
125+
102126
- name: Run notebooks with tox
103-
run: tox -e notebooks
127+
# run: tox -e notebooks
128+
run: |
129+
pip install nbconvert jupyter
130+
pip install nbval
131+
pip install nibabel
132+
pip install mriqc_learn
133+
pip install nipreps-synthstrip
134+
pip install dipy
135+
pip install joblib
136+
pip install "nipype>=1.5.1,<2.0"
137+
pip install "nitransforms>=22.0.0,<24"
138+
pip install numpy
139+
pip install nest-asyncio
140+
pip install scikit_learn
141+
pip install scipy
142+
pip install .
143+
# jupyter nbconvert --to notebook --execute ${{ github.workspace }}/docs/notebooks/bold_realignment.ipynb \
144+
# --output executed_bold_realignment.ipynb
145+
# jupyter nbconvert --to python ${{ github.workspace }}/docs/notebooks/bold_realignment.ipnb
146+
python ${{ github.workspace }}/docs/notebooks/bold_realignment.py
147+
# pytest -s --nbval ${{ github.workspace }}/docs/notebooks/bold_realignment.ipynb

docs/notebooks/bold_realignment.ipynb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,27 @@
8181
" if not DATA_PATH.exists() or not DATA_PATH.is_dir():\n",
8282
" raise FileNotFoundError(f\"Directory does not exist: {DATA_PATH}\")\n",
8383
"\n",
84+
" import hashlib\n",
85+
" model_path = DATA_PATH / \"synthstrip.1.pt\"\n",
86+
" md5_hash = hashlib.md5()\n",
87+
" try:\n",
88+
" with open(model_path, \"rb\") as file:\n",
89+
" # Read the file in chunks to handle large files efficiently\n",
90+
" for chunk in iter(lambda: file.read(4096), b\"\"):\n",
91+
" md5_hash.update(chunk)\n",
92+
" except FileNotFoundError:\n",
93+
" raise FileNotFoundError(f\"File not found.\")\n",
94+
"\n",
95+
" md5_value = md5_hash.hexdigest()\n",
96+
" print(f\"The MD5 hash of {model_path} is: {md5_value}\")\n",
97+
"\n",
8498
" if not bmask_path.exists():\n",
99+
" bmsk_results = SynthStrip(\n",
100+
" in_file=str(avg_path),\n",
101+
" use_gpu=True,\n",
102+
" model=model_path,\n",
103+
" ).run(cwd=str(WORKDIR))\n",
104+
"\n",
85105
" ssiface = SynthStrip(\n",
86106
" in_file=str(avg_path),\n",
87107
" use_gpu=True,\n",

0 commit comments

Comments
 (0)