We are exploring the use of running singularity containers via the Skylab workflow for specific tasks. This page contains information on setting up and running containers on remote hosts, mounting directories, and launching at EWOK runtime.

Singularity Documentation: https://docs.sylabs.io/guides/latest/user-guide/

Table of Contents


Initial account setup

  1. Create an account on sylabs (via google/ucar email)
  2. Generate access token - Once logged in, go to the top right in the drop down menu under your user name and click "Access Tokens". Enter a label/alias, ie "Hercules", and click "Create Access Token". You will be prompted for this token when you first create a container using the --remote  option. 

Environment setup

Load the singularity module with: module load singularity

Building a singularity container

Singularity containers can be built using a .def  file. This allows for easy reproducibility and standardization. You can find more information on this file setup in the Singularity Documentation. Below is a simple .def  file used for a bare bones container that is used to run WeatherBenchX.

wb_container.def
Bootstrap: docker
From: ubuntu:22.04

%labels
    Maintainer AGriffin
    Purpose WeatherBenchX

%post
    export DEBIAN_FRONTEND=noninteractive

    # Install dependencies
    apt-get update && apt-get install -y \
        software-properties-common \
        curl \
        wget \
        build-essential \
        git \
        vim \
        libffi-dev \
        libssl-dev \
        libbz2-dev \
        libreadline-dev \
        libsqlite3-dev \
        zlib1g-dev \
        libncursesw5-dev \
        xz-utils \
        tk-dev \
        libxml2-dev \
        libxmlsec1-dev \
        liblzma-dev \
        ca-certificates \
        && apt-get clean

    # Add deadsnakes PPA and install Python 3.11 and venv
    add-apt-repository ppa:deadsnakes/ppa -y
    apt-get update && apt-get install -y \
        python3.11 \
        python3.11-venv \
        python3.11-dev \
        python3.11-distutils \
        && apt-get clean

    # Point python3 to python3.11
    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1

    # Create the virtual environment
    python3 -m venv /venv_wb

    # Install WeatherBenchX and dependencies
    /venv_wb/bin/pip install --upgrade pip setuptools wheel
    git clone https://github.com/google-research/weatherbenchX /weatherbenchX
    cd /weatherbenchX
    /venv_wb/bin/pip install -e .
    /venv_wb/bin/pip install netCDF4

%environment
    # Activate virtual environment at runtime
    source /venv_wb/bin/activate
    export PATH="/venv_wb/bin:$PATH"

%runscript
    echo "Singularity container for WeatherBenchX"
    exec /bin/bash

In order to build a container on a remote host or HPC, you need to use the --remote  flag since we typically do not have admin privileges. An example build command using the definition file above on Hercules is: singularity build --remote wb_container.sif /work2/noaa/jcsda/agriffin/JEDI_WB/wb_container/wb_container.def 


Running a container

Running a container is done by using the singularity exec  command. The singularity exec  command will run a specific command against an instance. An example of how we can use this inside an EWOK task is the line in the runtime file for weather bench scores (src/runtime/wbScoresRun.sh):

Running singularity container
singularity exec -B $WORKDIR:/$WORKDIR -B $JEDI_WORKFLOW:/jedi-workflow -B /work2/noaa/jcsda/cgas/jedi/wb_files:/work2/noaa/jcsda/cgas/jedi/wb_files /work2/noaa/jcsda/agriffin/JEDI_WB/wb_container/wb_container.sif bash -c "cd $WORKDIR && python3 /jedi-workflow/ewok/src/runtime/evaluation_deterministic.py"

Note, -B  will "bind"/mount the directories you need onto the container. 

Note, you can also run singularity shell work2/noaa/jcsda/agriffin/JEDI_WB/wb_container/wb_container.sif  to spawn a new shell within your container.


  • No labels