Docker containers for Monte Carlo generators and Rivet

Last updated on 2024-06-25 | Edit this page

Estimated time: 35 minutes

Overview

Questions

  • What container images are available for MC generators ?

Objectives

  • Download a container image with Pythia and Rivet
  • Learn how to use the container

Overview


You will learn about Rivet during this QCD school. The Rivet project provides container images with Rivet and Monte Carlo generators included. For now, we will download the Rivet container images with Pythia and Sherpa code included.

Rivet containers


The first time you start a container, a docker image file gets downloaded from an image registry. The Rivet image sizes are of order of 3 GB and it may take some time to download, depending on the speed of your internet connection. After the download, a container created from that image starts. The image download needs to be done only once. Afterwards, when starting a container, it will find the downloaded image on your computer, and it will be much faster.

The containers do not have modern editors and it is expected that you mount your working directory from the local computer into the container, and use your normal editor for editing the files. Note that all your compiling and executing still has to be done in the Docker container!

First, before you start up your container, create a local directory where you will be doing your code development. In the examples below, it is called pythia_work or sherpa_work. You may choose a different directory name if you like.

Start the Pythia container


Create the shared directory in your working area:

BASH

mkdir pythia_work
cd pythia_work

Start the container with

BASH

docker run -v $PWD:/host -it --rm hepstore/rivet-pythia

This will share you current working directory ($PWD) into the container’s /host directory.

The flag --rm makes docker delete the local container when you exit and every time you run this command it creates a new container. This means that changes done anywhere else than in the shared /host directory will be deleted.

Note that the --rm flag does not delete the image that you just downloaded.

You will get a container prompt similar this:

OUTPUT

root@3bbca327eda3:/work#

This is a bash shell in the container. Change to the shared /host directory.

BASH

cd /host

You will be doing all your work in this shared directory. You can also set this directory as the working directory with flag -w /host in the docker run... command.

For now, exit from the container:

BASH

exit

List your local Docker images and containers and see that you have the hepstore/rivet-pythia image but no local containers as they were deleted with the --rm flag.

BASH

docker image ls
docker container ls -a

Start the Sherpa container


Move back from the pythia working area with

BASH

cd ..

Create the shared directory in your working area:

BASH

mkdir sherpa_work
cd sherpa_work

Start the container with

BASH

docker run -v $PWD:/host -w /host -it --rm hepstore/rivet-sherpa:3.1.7-2.2.12

This will share you current working directory ($PWD) into the container’s /host directory.

The flag --rm makes docker delete the local container when you exit and every time you run this command it creates a new container. This means that changes done anywhere else than in the shared /host directory will be deleted.

Note that the --rm flag does not delete the image that you just downloaded.

You will get a container prompt similar this:

OUTPUT

root@2560cb95ef24:/host#

The flag -w /host has set /host as the working directory. You will be doing all your work in this shared directory.

For now, exit from the container:

BASH

exit

Test the environment


Challenge 1

Create a file on your local host and make sure that you can see it in the container.

Open the editor in your host system, create a file example.txt and save it to the shared working area in pythia_work.

Start a container in your shared pythia_work directory:

BASH

docker run -v $PWD:/host -w /host -it --rm hepstore/rivet-pythia

In the container prompt, list the files and show the contents of the newly created file:

BASH

ls
cat example.txt

Challenge 2

Create a file in the container and make sure that you can see it on your local area.

If you are not already in the container, start it with

BASH

docker run -v $PWD:/host  -w /host -it --rm hepstore/rivet-pythia

Write some output to a file

BASH

echo "This is from the container" > output.txt

Exit from the container and see that you have the output file on your local area.

BASH

exit
ls
cat output.txt

Challenge 3

Check the Rivet version in the Sherpa container.

Start a container in your shared sherpa_work directory:

BASH

docker run -v $PWD:/host -w /host -it --rm hepstore/rivet-sherpa:3.1.7-2.2.12

In the container prompt, check the Rivet version with

BASH

rivet --version

You should get

OUTPUT

rivet v3.1.7

Challenge 4

In the Pythia container, copy a Pythia example code main01.cc, and Makefile and Makefile.inc from /usr/local/share/Pythia8/examples/ of the container to your shared area. Compile the code with make and run it.

Start the Pythia container in your shared pythia_work directory:

BASH

docker run -v $PWD:/host -w /host -it --rm hepstore/rivet-pythia

Copy the files to your working area with

BASH

cp /usr/local/share/Pythia8/examples/main01.cc .
cp /usr/local/share/Pythia8/examples/Makefile* .

Compile and run

BASH

make main01
./main01

You will get a particle listing and a lovely ASCII histogram of charged multiplicity.

Key Points

  • You have now set up a docker container as a working enviroment Rivet and Pythia.
  • You know how to share a working area between your own computer and the container.