Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
singularity_tutorial/exercises/exercises.Rmd
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
97 lines (71 sloc)
2.91 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Exercises" | |
author: "Jonas Hagenberg" | |
date: "15.3.2022" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
``` | |
# Exercise 1 | |
The goal is to start a virtual machine with `singularity` and create a simple | |
container with `R`, `dplyr` and `tidyr`. | |
## Get to know your VM | |
1. Create a folder where you want to store your virtual machine configuration | |
files. (On windows: use the `git bash`): | |
```{bash, eval = FALSE} | |
mkdir vm-singularity && \ | |
cd vm-singularity | |
``` | |
2. Create a new VM. For this, you can use an already prepared image with the latest Singularity version for which an image for the VM is available: | |
```{bash, eval = FALSE} | |
export VM=sylabs/singularity-3.7-ubuntu-bionic64 && \ | |
vagrant init $VM | |
``` | |
3. Start the VM: | |
```{bash, eval = FALSE} | |
vagrant up | |
``` | |
4. Open a shell in the VM (so that you have access): | |
```{bash, eval = FALSE} | |
vagrant ssh | |
``` | |
To exit the shell, type `exit`. To shut down the VM, use `vagrant halt`, to | |
start it again `vagrant up` and for deletion `vagrant destroy`. | |
## Build your first container | |
- create a container definition file that contains `R 4.1.0`, `dplyr` and `tidyr` | |
- include a test in the definition file where you transform the `mtcars` dataset | |
into the long format and print the head of the long data.frame | |
- build the container image | |
You build the container image with the command: | |
```{bash, eval = FALSE} | |
sudo singularity build <container_image_name>.sif <container_definition_name>.def | |
``` | |
HINT: If you want to move a file into the VM, you can use `scp`: | |
```{bash, eval = FALSE} | |
scp -P 2222 /path/to/file/on/host vagrant@127.0.0.1:/home/vagrant | |
``` | |
The password is `vagrant`. | |
# Exercise 2 | |
The goal is to run an `R` script within the container on the cluster. | |
- "download" the container image (the `.sif` file) from your VM to a folder on | |
your computer. You can adapt the `scp` command from above | |
- upload the image to a folder in your home directory on the MPIP cluster | |
(it is also ok to directly upload it into your home directory) | |
- upload the `container_test_r.R` script to a folder in your home directory | |
- execute the `container_test_r.R` script in the container in an `sbatch` job | |
If everything works, you see a `container_testdata.Rds` file in your home directory. | |
HINT: To specify your home directory, you explicitly need to use `/home/<USERNAME>`, | |
`~` does not work. | |
# Exercise 3 | |
*This is a bonus exercise for people who are very fast.* | |
The goal is to mount a folder from the cluster into the container. | |
1. Create the following directory on the cluster: | |
```{bash, eval = FALSE} | |
mkdir ~/container_exercise_3 | |
``` | |
2. Upload the file `testdata_exercise_3.csv` to the folder `container_exercise_3` on the cluster. | |
3. Upload the file `exercise_3.R` to a folder in your home directory that is not | |
`container_exercise_3`. | |
- find a way to use a `singularity` command (together with `sbatch`) that can | |
execute `exercise_3.R` without modifying `exercise_3.R` |