Skip to content

Singularity

Singularity is an optional tool on our cluster that lets you run software inside portable containers without needing root access.

Each container runs under your own account, sees your usual home and scratch directories, and works smoothly with the scheduler.

Use it when you need software versions that aren’t already provided as modules.

Note

In our cluster Singularity is always accessible without need to load it using Lmod.

Running Image

This example downloads and run the image from public library.

singularity --debug run library://lolcow

Searching In Public Library

This example allows you to search in public library for existing images.

singularity search tensorflow

Building Image

First create singularity container definition my_container.def file using standard editor nano or vim.

Example content of my_container.def file:

Bootstrap: docker
From: ubuntu:20.04

%post
    apt-get update && apt-get install -y python3 python3-pip
    pip3 install numpy

%runscript
    echo "This container has Python and NumPy installed!"
    python3

Now you can build the container:

singularity build my_container.sif my_container.def

After successfull build you can run the container:

singularity run my_container.sif

Example output:

This container has Python and NumPy installed!
Python 3.8.10 (default, May  3 2021, 08:55:58)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Example

This PBS Pro job script submits a job to a high-performance computing (HPC) cluster to run a Python script (my_script.py) inside a Singularity container (my_container.sif).

#!/bin/bash
#PBS -N singularity_test
#PBS -l select=1:ncpus=4:mem=8gb
#PBS -l walltime=01:00:00

# Run your Singularity container
singularity exec my_container.sif python3 my_script.py