User Tools

Site Tools


singularity

This is an old revision of the document!


Singularity

Singularity http://singularity.lbl.gov/ is a software container system. It allows users to build and run entire scientific workflows, software and libraries using a specific distribution and version of Linux all packaged into a single image file. It is based on the Linux “chroot” command which allows users to switch the environment from the operating system installed on the host node to the one inside the singularity image file.

Many pre-built container images are available for download in the singularity hub https://singularity-hub.org/ and the docker hub https://singularity-hub.org/ repositories.

Local Image Files

Start an interactive job and load the singularity module

razor-l2:pwolinsk:$ qsub -I -q tiny12core -l walltime=1:00:00 -l nodes=1:ppn=12
qsub: waiting for job 3608596.sched to start
qsub: job 3608596.sched ready
compute1144:pwolinsk:$ module load singularity

Open a shell inside a prebuilt container stored locally on Razor in /share/apps/singularity/images/hello-world.simg

compute1144:pwolinsk:$ cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m

compute1144:pwolinsk:$ singularity shell /share/apps/singularity/images/hello-world.simg 
Singularity: Invoking an interactive shell within container...

Singularity hello-world.simg:~> cat /etc/issue
Ubuntu 14.04.5 LTS \n \l

Singularity hello-world.simg:~> exit
exit
compute1144:pwolinsk:$ 

Remote Repository Image Files

Open a shell inside a container stored on singularity hub shub:/ /vsoch/hello-world

compute1144:pwolinsk:$ singularity shell shub://vsoch/hello-world
Progress |===================================| 100.0% 
Singularity: Invoking an interactive shell within container...

Singularity vsoch-hello-world-master.simg:~> cat /etc/issue
Ubuntu 14.04.5 LTS \n \l

Singularity vsoch-hello-world-master.simg:~> 

Open a shell inside a container pulled for the docker repository, and bind /scratch directory on Razor to /mnt directory inside the container

compute1144:pwolinsk:$ ls /scratch |wc -l
5535
compute1144:pwolinsk:$ singularity shell --bind /scratch:/mnt docker://ubuntu
Docker image path: index.docker.io/library/ubuntu:latest
Cache folder set to /gpfs_home/pwolinsk/.singularity/docker
[5/5] |===================================| 100.0% 
Creating container runtime...
Singularity: Invoking an interactive shell within container...

Singularity ubuntu:~> cat /etc/issue
Ubuntu 16.04.3 LTS \n \l

Singularity ubuntu:~> ls /mnt |wc -l
5535
Singularity ubuntu:~> 

By default the container will bind the users $HOME directory /tmp and the current working directory from teh host to the equivalent directories inside the container. You can specify additional directories to bind using –bind <local_dir>:<container_dir> syntax.

Tensorflow Example

Download the example models from git repository

compute1144:pwolinsk:$ git clone https://github.com/tensorflow/models
Initialized empty Git repository in /gpfs_home/pwolinsk/models/.git/
remote: Counting objects: 9158, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 9158 (delta 0), reused 0 (delta 0), pack-reused 9156
Receiving objects: 100% (9158/9158), 293.18 MiB | 32.15 MiB/s, done.
Resolving deltas: 100% (5162/5162), done.
compute1144:pwolinsk:$ cd models/tutorials/image/mnist/

Start a shell in the prebuilt singularity container from within the directory containing the python training script

compute1144:pwolinsk:/models/tutorials/image/mnist$ singularity shell /share/apps/singularity/images/ubuntu-tensorflow-1.4.simg 
Singularity: Invoking an interactive shell within container...

Singularity ubuntu-tensorflow-1.4.simg:~/models/tutorials/image/mnist> python convolutional.py 
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
2017-12-01 15:05:15.992688: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2
Initialized!
Step 0 (epoch 0.00), 2.4 ms
Minibatch loss: 8.334, learning rate: 0.010000
Minibatch error: 85.9%
Validation error: 84.6%
...

Or instead of starting a shell inside the container use the exec command run the command inside the container:

compute1144:pwolinsk:/models/tutorials/image/mnist$ singularity exec /share/apps/singularity/images/ubuntu-tensorflow-1.4.simg python convolutional.py 
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
2017-12-01 15:07:56.905035: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2
Initialized!
Step 0 (epoch 0.00), 2.2 ms
Minibatch loss: 8.334, learning rate: 0.010000
Minibatch error: 85.9%
Validation error: 84.6%
...
singularity.1512162995.txt.gz · Last modified: 2017/12/01 21:16 by pwolinsk