Skip to content

Commit a0d0701

Browse files
authored
Merge pull request #1063 from poldracklab/chrisfilo-patch-2
[DOC] Improving documentation on using Singularity
2 parents d5a98fb + 3c62115 commit a0d0701

File tree

1 file changed

+63
-19
lines changed

1 file changed

+63
-19
lines changed

docs/installation.rst

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,35 @@ what is included in the latest Docker images.
6666
Singularity Container
6767
=====================
6868

69-
For security reasons, many HPCs (e.g., TACC) do not allow Docker containers, but do allow `Singularity <https://github.com/singularityware/singularity>`_ containers.
69+
For security reasons, many HPCs (e.g., TACC) do not allow Docker containers, but do
70+
allow `Singularity <https://github.com/singularityware/singularity>`_ containers.
71+
72+
Preparing a Singularity image (Singularity version >= 2.5)
73+
----------------------------------------------------------
74+
If the version of Singularity on your HPC is modern enough you can create Singularity
75+
image directly on the HCP.
76+
This is as simple as: ::
77+
78+
$ singularity build /my_images/fmriprep-<version>.simg docker://poldracklab/mriqc:<version>
79+
80+
Where ``<version>`` should be replaced with the desired version of fMRIPrep that you want to download.
81+
82+
83+
Preparing a Singularity image (Singularity version < 2.5)
84+
---------------------------------------------------------
7085
In this case, start with a machine (e.g., your personal computer) with Docker installed.
71-
Use `docker2singularity <https://github.com/singularityware/docker2singularity>`_ to create a singularity image. You will need an active internet connection and some time. ::
86+
Use `docker2singularity <https://github.com/singularityware/docker2singularity>`_ to
87+
create a singularity image.
88+
You will need an active internet connection and some time. ::
7289

7390
$ docker run --privileged -t --rm \
7491
-v /var/run/docker.sock:/var/run/docker.sock \
7592
-v D:\host\path\where\to\output\singularity\image:/output \
7693
singularityware/docker2singularity \
77-
poldracklab/fmriprep:latest
94+
poldracklab/fmriprep:<version>
7895

96+
Where ``<version>`` should be replaced with the desired version of fMRIPrep that you want
97+
to download.
7998

8099
Beware of the back slashes, expected for Windows systems.
81100
For \*nix users the command translates as follows: ::
@@ -84,46 +103,69 @@ For \*nix users the command translates as follows: ::
84103
-v /var/run/docker.sock:/var/run/docker.sock \
85104
-v /absolute/path/to/output/folder:/output \
86105
singularityware/docker2singularity \
87-
poldracklab/fmriprep:latest
106+
poldracklab/fmriprep:<version>
88107

89108

90109
Transfer the resulting Singularity image to the HPC, for example, using ``scp``. ::
91110

92-
$ scp poldracklab_fmriprep_latest-*.img [email protected]:/path/to/downloads
111+
$ scp poldracklab_fmriprep*.img [email protected]:/my_images
112+
113+
Running a Singularity Image
114+
---------------------------
93115

94116
If the data to be preprocessed is also on the HPC, you are ready to run fmriprep. ::
95117

96-
$ singularity run path/to/singularity/image.img \
118+
$ singularity run --clearenv /my_images/fmriprep-1.1.2.simg \
97119
path/to/data/dir path/to/output/dir \
98120
participant \
99121
--participant-label label
100122

101-
For example: ::
123+
.. note::
102124

103-
$ singularity run ~/poldracklab_fmriprep_latest-2016-12-04-5b74ad9a4c4d.img \
125+
Singularity by default `exposes all environment variables from the host inside
126+
the container <https://github.com/singularityware/singularity/issues/445>`_.
127+
Because of this your host libraries (such as nipype) could be accidentally used
128+
instead of the ones inside the container - if they are included in ``PYTHONPATH``.
129+
To avoid such situation we recommend using the ``--clearenv`` singularity flag
130+
in production use. For example: ::
131+
132+
$ singularity run --clearenv ~/poldracklab_fmriprep_latest-2016-12-04-5b74ad9a4c4d.img \
104133
/work/04168/asdf/lonestar/ $WORK/lonestar/output \
105134
participant \
106135
--participant-label 387 --nthreads 16 -w $WORK/lonestar/work \
107136
--omp-nthreads 16
108137

109-
.. note::
110138

111-
Singularity by default `exposes all environment variables from the host inside the container <https://github.com/singularityware/singularity/issues/445>`_.
112-
Because of this your host libraries (such as nipype) could be accidentally used instead of the ones inside the container - if they are included in PYTHONPATH.
113-
To avoid such situation we recommend unsetting PYTHONPATH in production use. For example: ::
139+
or, unset the ``PYTHONPATH`` variable before running: ::
114140

115-
$ PYTHONPATH="" singularity run ~/poldracklab_fmriprep_latest-2016-12-04-5b74ad9a4c4d.img \
141+
$ unset PYTHONPATH; singularity run ~/poldracklab_fmriprep_latest-2016-12-04-5b74ad9a4c4d.img \
116142
/work/04168/asdf/lonestar/ $WORK/lonestar/output \
117143
participant \
118144
--participant-label 387 --nthreads 16 -w $WORK/lonestar/work \
119145
--omp-nthreads 16
120146

147+
148+
.. note::
149+
150+
Depending on how Singularity is configured on your cluster it might or might not
151+
automatically bind (mount or expose) host folders to the container.
152+
If this is not done automatically you will need to bind the necessary folders using
153+
the ``-B <host_folder>:<container_folder>`` Singularity argument.
154+
For example: ::
155+
156+
$ singularity run --clearenv -B /work:/work ~/poldracklab_fmriprep_latest-2016-12-04-5b74ad9a4c4d.simg \
157+
/work/my_dataset/ /work/my_dataset/derivatives/fmriprep \
158+
participant \
159+
--participant-label 387 --nthreads 16 \
160+
--omp-nthreads 16
161+
121162
Manually Prepared Environment
122163
=============================
123164

124-
.. note::
165+
.. warning::
125166

126-
This method is not recommended! Make sure you would rather do this than use a `Docker Container`_ or a `Singularity Container`_.
167+
This method is not recommended! Make sure you would rather do this than
168+
use a `Docker Container`_ or a `Singularity Container`_.
127169

128170
Make sure all of fmriprep's `External Dependencies`_ are installed.
129171
These tools must be installed and their binaries available in the
@@ -149,9 +191,11 @@ FMRIPREP uses FreeSurfer tools, which require a license to run.
149191
To obtain a FreeSurfer license, simply register for free at
150192
https://surfer.nmr.mgh.harvard.edu/registration.html.
151193

152-
When using manually-prepared environments, FreeSurfer will search for a license key
153-
file first using the ``$FS_LICENSE`` environment variable and then in the default
154-
path to the license key file (``$FREESURFER_HOME/license.txt``).
194+
When using manually-prepared environments or singularity, FreeSurfer will search
195+
for a license key file first using the ``$FS_LICENSE`` environment variable and then
196+
in the default path to the license key file (``$FREESURFER_HOME/license.txt``).
197+
If using the ``--clearenv`` flag and ``$FS_LICENSE`` is set, use ``--fs-license-file $FS_LICENSE``
198+
to pass the license file location to fMRIPrep.
155199

156200
It is possible to run the docker container pointing the image to a local path
157201
where a valid license file is stored.
@@ -193,7 +237,7 @@ would be equivalent to the latest example: ::
193237
External Dependencies
194238
=====================
195239

196-
``fmriprep`` is implemented using nipype_, but it requires some other neuroimaging
240+
FMRIPrep is implemented using nipype_, but it requires some other neuroimaging
197241
software tools:
198242

199243
- FSL_ (version 5.0.9)

0 commit comments

Comments
 (0)