Background
What is Singularity?*
"Singularity enables users to have full control of their environment. Singularity containers can be used to package entire scientific workflows, software and libraries, and even data. This means that you dont have to ask your cluster admin to install anything for you - you can put it in a Singularity container and run."
There are numerous good tutorials on how to install and run Singularity on Linux, OS X, or Windows so we won't go into much detail on that process here. In this tutorial you will learn how to run Singularity on Comet. First we will review how to access a compute node on Comet and provide a simple example to help get you started. There are numerous tutorial on how to get started with Singularity, but there are some details specific to running Singularity on Comet which are not covered in those tutorials. This tutorial assumes you already have an account on Comet. You will also need access to a basic set of example files to get started. SDSC hosts a Github repository containing a Hello world! example which you may clone with the following command:
> git clone https://github.com/hpcdevops/singularity-hello-world.git
Below is a typical list of commands you would need to issue in order to implement a functional Python installation for scientific research:
COMMAND=apt-get -y install libx11-dev COMMAND=apt-get install build-essential python-libdev COMMAND=apt-get install build-essential openmpi-dev COMMAND=apt-get install cmakeCOMMAND=apt-get install g++ COMMAND=apt-get install git-lfs COMMAND=apt-get install libXss.so.1COMMAND=apt-get install libgdal1-dev libproj-dev COMMAND=apt-get install libjsoncpp-dev libjsoncpp0 COMMAND=apt-get install libmpich-dev --userCOMMAND=apt-get install libpthread-stubs0 libpthread-stubs0-dev libx11-dev libx11-d COMMAND=apt-get install libudev0:i386COMMAND=apt-get install numpy COMMAND=apt-get install python-matplotlib COMMAND=apt-get install python3
Singularity allows you to avoid this time-consuming series of steps by packaging these commands in a re-usable and editable script, allowing you to quickly, easily, and repeatedly implement a custom container designed specifically for your analytical needs.
The diagram below compares a VM vs. Docker vs. Singularity.
Next, let's get some hands-on experience with Singularity. The following tutorial includes links to asciinema video tutorials created by SDSC HPC Systems Manager, Trevor Cooper (Thanks, Trevor!) which allow you to see the console interactivity and output in detail. Look for the video icon like the one shown to the right corresponding to the task you are currently working on.
First we download and upack the source using the following commands (assuming your user name is 'test_user' and you are working on your local computer with super user privileges):
[test_user@localhost ~]$ wget https://github.com/singularityware/singularity/releases/download/2.5.1/singularity-2.5.1.tar.gz tar -zxf singularity-2.5.1.tar.gz
If the file is successfully extracted, you should be able to view the results:
Next we configure and build the package. To configure, enter the following command (we'll leave out the command prompts):
To build, issue the following command:
This may take several seconds depending on your computer.
To complete the installation enter:
You should be prompted to enter your admin password.
Once the installation is completed, you can check to see if it succeeded in a few different ways:
You can also run a selftest with the following command:
The output should look something like:
The process of building a Singularity container consists of a few distinct steps as follows.
We will go through each of these steps in detail.
We recommend building containers using the same version of Singularity, 2.5.1, as exists on Comet. This is a 2 step process.
Step 1: run the script below to remove your existing Singularity:
#!/bin/bash## A cleanup script to remove Singularity
sudo rm -rf /usr/local/libexec/singularitysudo rm -rf /usr/local/etc/singularitysudo rm -rf /usr/local/include/singularitysudo rm -rf /usr/local/lib/singularitysudo rm -rf /usr/local/var/lib/singularity/sudo rm /usr/local/bin/singularitysudo rm /usr/local/bin/run-singularitysudo rm /usr/local/etc/bash_completion.d/singularitysudo rm /usr/local/man/man1/singularity.1
Step 2: run the following script to install Singularity 2.5.1:
#!/bin/bash## A build script for Singularity (http://singularity.lbl.gov/)
declare -r SINGULARITY_NAME='singularity'declare -r SINGULARITY_VERSION='2.5.1'declare -r SINGULARITY_PREFIX='/usr/local'declare -r SINGULARITY_CONFIG_DIR='/etc'
sudo apt updatesudo apt install python dh-autoreconf build-essential debootstrap
cd ../tar -xzvf "${PWD}/tarballs/${SINGULARITY_NAME}-${SINGULARITY_VERSION}.tar.gz"cd "${SINGULARITY_NAME}-${SINGULARITY_VERSION}"./configure --prefix="${SINGULARITY_PREFIX}" --sysconfdir="${SINGULARITY_CONFIG_DIR}"makesudo make install
To create an empty Singularity container, you simply issue the following command:
This will create a CentOS 7 container with a default size of ~805 Mb. Depending on what additional configurations you plan to make to the container, this size may or may not be big enough. To specify a particular size, such as ~4 Gb, include the -s parameter, as shown in the following command:
To view the resulting image in a directory listing, enter the following:
Next, we will import a Docker image into our empty Singularity container:
Once the container actually contains a CentOS 7 installation, you can shell into it with the following:
Once you enter the container you should see a different command prompt. At this new prompt, try typing:
Your user id should be identical to your user id outside the container. However, the operating system will probably be different. Try issuing the following command from inside the container to see what the OS version is:
Next, lets trying writing into the container (as root):
You should be prompted for your password, and then you should see something like the following:
Next, lets create a script within the container so we can use it to test the ability of the container to execute shell scripts:
The above command assumes you know the vi editor. Enter the following text into the script, save it, and quit the vi editor:
You may need to change the permissions on the script so it can be executable:
Try running the script manually:
The output should be:
Bootstrapping a Singularity container allows you to use what is called a definitions file so you can reproduce the resulting container configurations on demand.
Lets say you want to create a container with Ubuntu, but you may want to create variations on the configurations without having to repeat a long list of commands manually. First, we need our definitions file. Below is the contents of a definitions file which should suffice for our purposes.
%runscriptexec echo The runscript is the containers default runtime command!
%files/home/testuser/ubuntu.def /data/ubuntu.def
%labelsAUTHOR testuser@sdsc.edu
%postapt-get update && apt-get -y install python3 git wgetmkdir /dataecho The post section is where you can install and configure your container.
To bootstrap your container, first we need to create an empty container.
Now, we simply need to issue the following command to configure our container with Ubuntu:
This may take a while to complete. In principle, you can accomplish the same result by manually issuing each of the commands contained in the script file, but why do that when you can use bootstrapping to save time and avoid errors.
If all goes according to plan, you should then be able to shell into your new Ubuntu container.
Of course, the purpose of this tutorial is to enable you to use the San Diego Supercomputer Centers Comet supercomputer to run your jobs. This assumes you have an account on Comet already. If you do not have an account on Comet and you feel you can justify the need for such an account (i.e. your research is limited by the limited compute power you have in your government-funded research lab), you can request a Startup Allocation through the XSEDE User Portal:
https://portal.xsede.org/allocations-overview#types-trial
You may create a free account on the XUP if you do not already have one and then proceed to submit an allocation request at the above link.
[NOTE: SDSC provides a Comet User Guide ( http://www.sdsc.edu/support/user_guides/comet.html ) to help get you started with Comet. Learn more about The San Diego Supercomputer Center at http://www.sdsc.edu .]
This tutorial walks you through the following four steps towards running your first Singularity container on Comet:
Once you have created your container on your local system, you will need to transfer it to Comet. There are multiple ways to do this and it can take a varying amount of time depending on its size and your network connection speeds.
To do this, we will use scp (secure copy). If you have a Globus account and your containers are more than 4 Gb you will probably want to use that file transfer method instead of scp.
Browse to the directory containing the container. Copy the container to your scratch directory on Comet. By issuing the following command:
The container is ~805 Mb so it should not take too long, hopefully.
Once the file is transferred, login to Comet (assuming your Comet user is named 'test_user'):
Navigate to your scratch directory on Comet, which should be something like:
Next, you should submit a request for an interactive session on one of Comets compute, debug, or shared nodes.
Once your request is approved your command prompt should reflect the new node id.
Before you can run your container you will need to load the Singularity module (if you are unfamiliar with modules on Comet, you may want to review the Comet User Guide). The command to load Singularity on Comet is:
You may issue the above command from any directory on Comet. Recall that we added a hello_world.sh script to our centos7.img container. Lets try executing that script with the following command:
If all goes well, you should see Hello, World! in the console output. You might also see some warnings pertaining to non-existent bind points. You can resolve this by adding some additional lines to your definitions file before you build your container. We did not do that for this tutorial, but you would use a command like the following in your definitions file:
You will find additional examples located in the following locations on Comet:
and
It is best to avoid working on Comets login nodes since they can become a performance bottleneck not only for you but for all other users. You should rather allocate resources specific for computationally-intensive jobs. To allocate a compute node for your user on Comet, issue the following command:
This allocation requests a single node (-N 1) for a total time of 10 minutes (-t 00:10:00). Once your request has been approved, your computer node name should be displayed, e.g. comet-17-12.
Now you may login to this node:
Notice that the command prompt has now changed to reflect the fact that you are on a compute node and not a login node.
Next, load the Singularity module, shell into the container, and execute the hello_world.sh script:
If all goes well, you should see Hello, World! in the console output.
Of course, most users simply want to submit their jobs to the Comet queue and let it run to completion and go on to other things while waiting. Slurm is the job manager for Comet.
Below is a job script (which we will name singularity_mvapich2_hellow.run) which will submit your Singularity container to the Comet queue and run a program, hellow.c (written in C using MPI and provided as part of the examples with the mvapich2 default installation).
#!/bin/bash #SBATCH --job-name="singularity_mvapich2_hellow" #SBATCH --output="singularity_mvapich2_hellow.%j.out" #SBATCH --error="singularity_mvapich2_hellow.%j.err" #SBATCH --nodes=2 #SBATCH --ntasks-per-node=24 #SBATCH --time=00:10:00 #SBATCH --export=all module load mvapich2_ib singularity
CONTAINER=/oasis/scratch/comet/$USER/temp_project/singularity/centos7-mvapich2.img
mpirun singularity exec ${CONTAINER} /usr/bin/hellow
The above script requests 2 nodes and 24 tasks per node with a wall time of 10 minutes. Notice that two modules are loaded (see the line beginning with module), one for Singularity and one for MPI. An environment variable CONTAINER is also defined to make it a little easier to manage long reusable text strings such as file paths.
You may need to add a line specifying with allocation to be used for this job. When you are ready to submit the job to the Comet queue, issue the following command:
To view the status of your job in the Comet queue, issue the following:
When the job is complete, view the output which should be written to the output file singularity_mvapich2_hellow.%j.out where %j is the job ID (lets say the job ID is 1000001):
See the original post:
- Singularity University - Solving Humanity's Grand Challenges [Last Updated On: June 10th, 2016] [Originally Added On: June 10th, 2016]
- Singularity Viewer [Last Updated On: June 12th, 2016] [Originally Added On: June 12th, 2016]
- Technological singularity - Wikipedia, the free encyclopedia [Last Updated On: June 14th, 2016] [Originally Added On: June 14th, 2016]
- Singularity HUB - News and Insights on Technology, Science ... [Last Updated On: June 16th, 2016] [Originally Added On: June 16th, 2016]
- Singularity on Steam [Last Updated On: June 22nd, 2016] [Originally Added On: June 22nd, 2016]
- The Best Definition of Singularity [Last Updated On: June 22nd, 2016] [Originally Added On: June 22nd, 2016]
- Amazon.com: Singularity - Xbox 360: Video Games [Last Updated On: June 22nd, 2016] [Originally Added On: June 22nd, 2016]
- Singularity - Microsoft Research [Last Updated On: June 22nd, 2016] [Originally Added On: June 22nd, 2016]
- Singularity - GameSpot [Last Updated On: June 22nd, 2016] [Originally Added On: June 22nd, 2016]
- Singularity Q&A | KurzweilAI [Last Updated On: June 27th, 2016] [Originally Added On: June 27th, 2016]
- Singularity - RationalWiki [Last Updated On: July 18th, 2016] [Originally Added On: July 18th, 2016]
- Amazon.com: Singularity [Online Game Code]: Video Games [Last Updated On: August 25th, 2016] [Originally Added On: August 25th, 2016]
- Singularity - Mass Effect Wiki - Wikia [Last Updated On: August 25th, 2016] [Originally Added On: August 25th, 2016]
- Downloads - Singularity Viewer [Last Updated On: August 25th, 2016] [Originally Added On: August 25th, 2016]
- Singularity | Singularity [Last Updated On: October 31st, 2016] [Originally Added On: October 31st, 2016]
- What is Singularity (the)? - Definition from WhatIs.com [Last Updated On: October 31st, 2016] [Originally Added On: October 31st, 2016]
- Singularity University - Wikipedia [Last Updated On: November 29th, 2016] [Originally Added On: November 29th, 2016]
- Technological singularity - Wikipedia [Last Updated On: December 15th, 2016] [Originally Added On: December 15th, 2016]
- The Singularity Is Near - Wikipedia [Last Updated On: January 22nd, 2017] [Originally Added On: January 22nd, 2017]
- Singularity Art Show Tonight In San Francisco! [Last Updated On: January 23rd, 2017] [Originally Added On: January 23rd, 2017]
- When Electronic Witnesses Are Everywhere, No Secret's Safe - Singularity Hub [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- GEMS Education and Singularity University organises 1st annual Global Innovation Challenge - Al-Bawaba [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Do you believe in the Singularity? - Patheos (blog) [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Report: AMD Ryzen Performance in Ashes of the Singularity Benchmark - PC Perspective [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Donald Trump Is the Singularity - Bloomberg View - Bloomberg.com - Bloomberg [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Editorial Note From the Singularity Hub Team - Singularity Hub [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- Discover the Most Advanced Industrial Technologies at Exponential Manufacturing - Singularity Hub [Last Updated On: February 6th, 2017] [Originally Added On: February 6th, 2017]
- 10th Letter looks at nature in the time of the Singularity - Creative Loafing Atlanta [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- Wearable Devices Can Actually Tell When You're About to Get Sick - Singularity Hub [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- Video: Singularity Containers for Science, Reproducibility, and HPC - insideHPC [Last Updated On: February 7th, 2017] [Originally Added On: February 7th, 2017]
- Robot Cars Can Teach Themselves How to Drive in Virtual Worlds - Singularity Hub [Last Updated On: February 9th, 2017] [Originally Added On: February 9th, 2017]
- Rowe FTC robotics team RSF Singularity takes top honors at Championship - Rancho Santa Fe Review [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- Physicists Unveil Blueprint for a Quantum Computer the Size of a ... - Singularity Hub [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- Singularity Containers for Science, Reproducibility, and HPC - Linux.com (blog) [Last Updated On: February 10th, 2017] [Originally Added On: February 10th, 2017]
- How Robots Helped Create 100,000 Jobs at Amazon - Singularity Hub - Singularity Hub [Last Updated On: February 11th, 2017] [Originally Added On: February 11th, 2017]
- Ready to Change the World? Apply Now for Singularity University's 2017 Global Solutions Program - Singularity Hub [Last Updated On: February 11th, 2017] [Originally Added On: February 11th, 2017]
- Families Finally Hear From Completely Paralyzed Patients Via New Mind-Reading Device - Singularity Hub [Last Updated On: February 13th, 2017] [Originally Added On: February 13th, 2017]
- The fear of a technological singularity - ETtech.com [Last Updated On: February 13th, 2017] [Originally Added On: February 13th, 2017]
- Holograms Aren't The Stuff of Science Fiction Anymore - Singularity Hub [Last Updated On: February 15th, 2017] [Originally Added On: February 15th, 2017]
- How the World Has Changed From 1917 to 2017 - Singularity Hub [Last Updated On: February 15th, 2017] [Originally Added On: February 15th, 2017]
- Preparing for the Singularity - Inverse [Last Updated On: February 15th, 2017] [Originally Added On: February 15th, 2017]
- Ashes of the Singularity merges with standalone expansion Escalation, no upgrade fee - PCGamesN [Last Updated On: February 18th, 2017] [Originally Added On: February 18th, 2017]
- Just Stand Inside this Room and it Will Wirelessly Charge Your Phone - Singularity Hub [Last Updated On: February 18th, 2017] [Originally Added On: February 18th, 2017]
- Ashes of the Singularity: Escalation being merged with the original game - PC Invasion (blog) [Last Updated On: February 18th, 2017] [Originally Added On: February 18th, 2017]
- Europe's TREASURE Will Be the King of All GPSs - Singularity Hub [Last Updated On: February 18th, 2017] [Originally Added On: February 18th, 2017]
- AMD bundles Ashes of the Singularity with FX processors ahead of Ryzen's launch - PCWorld [Last Updated On: February 18th, 2017] [Originally Added On: February 18th, 2017]
- The roots of technological singularity can be traced backed to the Stone Age - Wired.co.uk [Last Updated On: February 20th, 2017] [Originally Added On: February 20th, 2017]
- Jide's new OS is like an Android version of Windows 10's Continuum - The Verge [Last Updated On: February 22nd, 2017] [Originally Added On: February 22nd, 2017]
- Jide's Remix Singularity OS will turn your Android phone into a PC - Android Authority (blog) [Last Updated On: February 22nd, 2017] [Originally Added On: February 22nd, 2017]
- Remix tries its hand at the mobile-desktop hybrid OS with Singularity - Android Police [Last Updated On: February 23rd, 2017] [Originally Added On: February 23rd, 2017]
- Financial Leaders: Make Your Mark on the Future at Exponential Finance - Singularity Hub [Last Updated On: February 23rd, 2017] [Originally Added On: February 23rd, 2017]
- After Man? From Singularity to Specificity - Peace Research Institute Oslo (PRIO) (press release) (blog) [Last Updated On: February 23rd, 2017] [Originally Added On: February 23rd, 2017]
- Ashes of Singularity: Escalation Gets an Update - CGMagazine [Last Updated On: February 24th, 2017] [Originally Added On: February 24th, 2017]
- One Android company wants to use smartphones to make PCs truly ... - BGR [Last Updated On: February 24th, 2017] [Originally Added On: February 24th, 2017]
- Jide Announces Remix Singularity: The Continuum Alternative for Android - XDA Developers (blog) [Last Updated On: February 24th, 2017] [Originally Added On: February 24th, 2017]
- Why the Potential of Augmented Reality Is Greater Than You Think - Singularity Hub [Last Updated On: February 24th, 2017] [Originally Added On: February 24th, 2017]
- Damon Wayans Jr. Will Star in Seth Rogen's AI Comedy 'Singularity' for FX - /FILM [Last Updated On: February 24th, 2017] [Originally Added On: February 24th, 2017]
- Google Updates: Scuba, Singularity, SMS and suing - The INQUIRER [Last Updated On: February 24th, 2017] [Originally Added On: February 24th, 2017]
- Damon Wayans Jr. Joins FX Sci-Fi Comedy Singularity - Den of Geek US [Last Updated On: February 28th, 2017] [Originally Added On: February 28th, 2017]
- This Neural Probe Is So Thin, The Brain Doesn't Know It's There - Singularity Hub [Last Updated On: February 28th, 2017] [Originally Added On: February 28th, 2017]
- Video: AI Is Getting Smarter, Says Singularity University's Neil Jacobstein - Wall Street Journal (subscription) (blog) [Last Updated On: February 28th, 2017] [Originally Added On: February 28th, 2017]
- Jami Attenberg's funny-sad 'All Grown Up' all about the singularity - Milwaukee Journal Sentinel [Last Updated On: February 28th, 2017] [Originally Added On: February 28th, 2017]
- Citizen Science Means Anyone Could Discover Planet NineEven You - Singularity Hub [Last Updated On: February 28th, 2017] [Originally Added On: February 28th, 2017]
- Does Zapping Your Brain Actually Help You Learn Faster? - Singularity Hub [Last Updated On: March 1st, 2017] [Originally Added On: March 1st, 2017]
- What You Need to Know About Elon Musk's Plan to Fly People to the Moon - Singularity Hub [Last Updated On: March 1st, 2017] [Originally Added On: March 1st, 2017]
- Singularity University opening organisation in Denmark The Post - The Copenhagen Post - Danish news in english [Last Updated On: March 1st, 2017] [Originally Added On: March 1st, 2017]
- Singularity: Explain It to Me Like I'm 5-Years-Old - Futurism - Futurism [Last Updated On: March 4th, 2017] [Originally Added On: March 4th, 2017]
- See How This House Was 3D Printed in Just 24 Hours - Singularity Hub [Last Updated On: March 5th, 2017] [Originally Added On: March 5th, 2017]
- NYC's Metrograph theater is running a sci-fi film series featuring Blade Runner, Ex Machina, and Metropolis - The Verge [Last Updated On: March 7th, 2017] [Originally Added On: March 7th, 2017]
- 3 Exciting Biotech Trends to Watch Closely in 2017 - Singularity Hub - Singularity Hub [Last Updated On: March 9th, 2017] [Originally Added On: March 9th, 2017]
- New Burger Robot Will Take Command of the Grill in 50 Fast Food Restaurants - Singularity Hub [Last Updated On: March 9th, 2017] [Originally Added On: March 9th, 2017]
- Are These Giant Neurons the Seat Of Consciousness in the Brain? - Singularity Hub [Last Updated On: March 10th, 2017] [Originally Added On: March 10th, 2017]
- How Fully Synthetic Complex Life Just Got a Lot Closer - Singularity Hub [Last Updated On: March 12th, 2017] [Originally Added On: March 12th, 2017]
- The Singularity is Coming in 2029 and Will Make Humans 'Sexier' - Inverse [Last Updated On: March 17th, 2017] [Originally Added On: March 17th, 2017]
- NYC Weekend Watch: 'Taipei Story,' the Singularity, 'The Last Movie' & More - The Film Stage (blog) [Last Updated On: March 17th, 2017] [Originally Added On: March 17th, 2017]
- The Singularity: US Navy calls on gamers to help it plan for the rise ... - International Business Times UK [Last Updated On: March 17th, 2017] [Originally Added On: March 17th, 2017]
- Have a big idea to tackle climate change? Singularity U's Global Impact Challenge wants you - Miami Herald [Last Updated On: March 17th, 2017] [Originally Added On: March 17th, 2017]
- The singularity: AI will make humans sexier and funnier, says ... - The Independent [Last Updated On: March 17th, 2017] [Originally Added On: March 17th, 2017]
- Silicon Valley's top brains try to sort out the singularity - TechEye [Last Updated On: March 21st, 2017] [Originally Added On: March 21st, 2017]
- World Order's 'Singularity' raises profile of singular girls group - Japan Today [Last Updated On: March 27th, 2017] [Originally Added On: March 27th, 2017]