Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "Apptainer" instead of "Singularity" #846

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ For example, ::
pennbbl/qsiprep:latest /data /out/out participant \
-w /out/work/

In order to work directly in the container, use ``--entrypoint=bash``
In order to work directly in the container, use ``--entrypoint=bash``
arguments in a ``docker`` command::

$ docker run --rm -v $HOME/fullds005:/data:ro -v $HOME/dockerout:/out \
-v $HOME/projects/qsiprep/qsiprep:/usr/local/miniconda/lib/python3.10/site-packages/qsiprep:ro --entrypoint=bash \
pennbbl/qsiprep:latest

Patching containers can be achieved in Singularity analogous to ``docker``
Patching containers can be achieved in Apptainer analogous to ``docker``
using the ``--bind`` (``-B``) option: ::

$ singularity run \
$ apptainer run \
-B $HOME/projects/qsiprep/qsiprep:/usr/local/miniconda/lib/python3.10/site-packages/qsiprep \
qsiprep.img \
/scratch/dataset /scratch/out participant -w /out/work/

Or you can patch Singularity containers using the PYTHONPATH variable: ::
Or you can patch Apptainer containers using the PYTHONPATH variable: ::

$ PYTHONPATH="$HOME/projects/qsiprep" singularity run qsiprep.img \
$ PYTHONPATH="$HOME/projects/qsiprep" apptainer run qsiprep.img \
/scratch/dataset /scratch/out participant -w /out/work/


Expand Down
10 changes: 5 additions & 5 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ and how it's built.



Singularity Container
Apptainer Container
=====================

The easiest way to get a Sigularity image is to run::
The easiest way to get an Apptainer (formerly Singularity) image is to run::

$ singularity build qsiprep-<version>.sif docker://pennbbl/qsiprep:<version>
$ apptainer build qsiprep-<version>.sif docker://pennbbl/qsiprep:<version>

Where ``<version>`` should be replaced with the desired version of qsiprep that you want to download.
Do not use ``latest`` or ``unstable`` unless you are performing limited testing.

As with Docker, you will need to bind the Freesurfer license.txt when running Singularity ::
As with Docker, you will need to bind the Freesurfer license.txt when running Apptainer ::

$ singularity run --containall --writable-tmpfs \
$ apptainer run --containall --writable-tmpfs \
-B $HOME/fullds005,$HOME/dockerout,${FREESURFER_HOME}/license.txt:/opt/freesurfer/license.txt \
qsiprep-<version>.sif \
$HOME/fullds005 $HOME/dockerout participant \
Expand Down
6 changes: 3 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Note on using CUDA
The CUDA runtime version 9.1 is included in the QSIPrep docker image.
The CUDA version of eddy is dramatically faster than the openmp version.
Information on running Docker with CUDA enabled can be found on
`dockerhub <https://github.com/NVIDIA/nvidia-docker/wiki/CUDA>`_. If running with singularity,
the call to singularity should include ``--nv``. To enable CUDA, see :ref:`configure_eddy`.
`dockerhub <https://github.com/NVIDIA/nvidia-docker/wiki/CUDA>`_. If running with Apptainer,
the call to Apptainer should include ``--nv``. To enable CUDA, see :ref:`configure_eddy`.

Debugging
=========
Expand All @@ -77,4 +77,4 @@ CUDA Support

As of version 0.6.7 CUDA version 9.1 is supported in the QSIPrep container! To run locally
using docker you will need the nvidia container runtime installed for Docker version 19.0.3
or higher. Singularity images will run with CUDA 9.1 with the ``-nv`` flag.
or higher. Apptainer images will run with CUDA 9.1 with the ``-nv`` flag.
1 change: 1 addition & 0 deletions qsiprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def main():
boiler_file = output_dir / "logs" / "CITATION.md"
if boiler_file.exists():
if config.environment.exec_env in (
"apptainer",
"singularity",
"docker",
):
Expand Down
2 changes: 1 addition & 1 deletion qsiprep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
_docker_ver = None
# special variable set in the container
if os.getenv("IS_DOCKER_8395080871"):
_exec_env = "singularity"
_exec_env = "apptainer"
_cgroup = Path("/proc/1/cgroup")
if _cgroup.exists() and "docker" in _cgroup.read_text():
_exec_env = "docker"
Expand Down
19 changes: 19 additions & 0 deletions qsiprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ def write_derivative_description(bids_dir, deriv_dir):
desc["SingularityContainerMD5"] = _get_shub_version(singularity_url)
except ValueError:
pass
if "QSIPREP_APPTAINER_URL" in os.environ:
apptainer_url = os.environ["QSIPREP_APPTAINER_URL"]
desc["ApptainerContainerURL"] = apptainer_url
try:
desc["ApptainerContainerMD5"] = _get_ahub_version(apptainer_url)
except ValueError:
pass

# Keys deriving from source dataset
fname = os.path.join(bids_dir, "dataset_description.json")
Expand Down Expand Up @@ -366,6 +373,14 @@ def validate_input_dir(exec_env, bids_dir, participant_label):
"all paths are mapped properly (see https://www.sylabs.io/"
"guides/3.0/user-guide/bind_paths_and_mounts.html)"
)
if exec_env == "apptainer":
error_msg += (
" This error can be caused by the input data not being "
"accessible inside the Apptainer container. Please make sure "
"all paths are mapped properly (see https://apptainer.org/",
"docs/user/main/bind_paths_and_mounts.html)",
)

raise RuntimeError(error_msg % ",".join(bad_labels))

ignored_subs = all_subs.difference(selected_subs)
Expand All @@ -385,6 +400,10 @@ def _get_shub_version(singularity_url):
raise ValueError("Not yet implemented")


def _get_ahub_version(apptainer_url):
raise ValueError("Not yet implemented")


def update_metadata_from_nifti_header(metadata, nifti_file):
"""Update a BIDS metadata dictionary with info from a NIfTI header.

Expand Down