Singularity on SeaWulf

Singularity

Introduction to Singularity

Singularity is a containerization platform that allows users to run applications in isolated environments, ensuring reproducibility across different computing systems. It is widely used for scientific computing and high-performance computing (HPC) environments like SeaWulf.

Containers are self-contained execution environments that package software, libraries, and dependencies. This allows users to run applications without worrying about compatibility issues with the underlying system. One of the key benefits of Singularity is its ability to ensure reproducibility of research - by encapsulating your entire environment in a container, you can ensure that your research code runs the same way on different systems, regardless of software or hardware differences.

Obtaining Singularity Containers

Building Singularity containers from definition files requires elevated privileges (sudo or --fakeroot) that are not available on SeaWulf. Instead, you should build containers on your local machine or use pre-built container images from repositories.

Important: The singularity build command with definition files is not supported on SeaWulf due to privilege requirements. Build your containers locally before transferring them to SeaWulf.

Option 1: Pull Pre-built Containers

You can pull pre-built containers from online repositories such as Docker Hub or Singularity Library. This is the recommended approach for most users:

# From Docker Hub: singularity pull docker://ubuntu:20.04 singularity pull docker://python:3.9 singularity pull docker://tensorflow/tensorflow:latest-gpu # From Singularity Library: singularity pull library://alpine:latest

The pulled images will be saved as .sif files in your current directory.

Option 2: Build Locally and Transfer

If you need a custom container, build it on your local machine (where you have sudo access) and then transfer the .sif file to SeaWulf:

# On your local machine with sudo: sudo singularity build my_container.sif my_definition.def # Transfer to SeaWulf: scp my_container.sif username@seawulf.stonybrook.edu:~/path/to/directory/

Running a Singularity Container

Once you have a container, you can run it using the singularity run command.

singularity run my_container.sif

This command will execute the default command specified in the container image. To run a custom command inside the container, use the exec option:

singularity exec my_container.sif my_custom_command

Note: Ensure that your container image is properly configured for the task you want to execute. Singularity supports both interactive and non-interactive commands.

Example: Running a Python Script in a Singularity Container

To run a Python script inside your Singularity container, use the following command:

singularity exec my_container.sif python3 my_script.py

This command runs the my_script.py Python script using Python 3 inside the container.