Skip to content

Instantly share code, notes, and snippets.

@TimotheeMathieu
Last active March 2, 2022 10:38
Show Gist options
  • Save TimotheeMathieu/7b0e60761a4440a0abaf5d91857ab9dd to your computer and use it in GitHub Desktop.
Save TimotheeMathieu/7b0e60761a4440a0abaf5d91857ab9dd to your computer and use it in GitHub Desktop.

Basic usage

Suppose you have a script my_script.py depending on rlberry that you want to execute in a container.

Pull the container with

$ singularity pull --arch amd64 library://tmath/rlberry/rlberry:test

This will download a 3.2GiB sif image with pre-installed rlberry.

Then, get a shell in the container with,

$ singularity shell rlberry_test.sif

Now, the container is mounted and you can use python, rlberry, ffmpeg, torch...

Singularity> python my_script.py

And its done ! The container also contain jupyter notebooks which can be launched with the command jupyter notebook. It does not contain any ide.

You can install new python libraries as user but to install new packages you need admin access

$ singularity overlay create --size 1024 rlberry.sif # create a 1GiB overlay that will be used to stock new installed packages
$ sudo singularity shell rlberry.sif
Singularity> apt update 
Singularity> apt install htop

Then, the new container rlberry.sif (now of size 4.2 GiB) will contain the package (here htop) the next time you use singularity shell rlberry.sif. An example of application of this is to construct an ad-hoc image that you will then upload on a HPC server to do the computation.

Image creation

The image in the singularity library was constructed from pytorch docker image using the following def file:

Bootstrap: docker
From: pytorch/pytorch

%post
    apt-get -y update
    apt-get -y install python python3-pip git vim 
    pip3 install -U pip
    pip3 install notebook
    pip3 install git+https://github.com/rlberry-py/rlberry

%environment
    export LC_ALL=C

%runscript
    jupyter notebook

%labels
    Author berries_eater

and the build command

sudo singularity build rlberry.sif rlberry.def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment