import atexit
import os
import shutil
import stat
import docker
Running duqtools with prominence
This Tutorial uses docker to create runs, and prominence to submit runs with duqtools
Getting started
Needed Packages
- The first thing we need is to install duqtools, if you haven't done this yet you can install it via
pip install duqtools
- We will also need access to the source of duqtools, it can be downloaded from https://github.com/duqtools/duqtools, This notebook was created with version
1.5.0
of duqtools - docker
- We also need access to the following images (or equivalent):
jintrac-imas
. which can be found here https://gitlab.eufus.psnc.pl/containerization/jintrac/jintrac-imas-installer
- We also need access to the following images (or equivalent):
- prominence, and we need to be logged in
Some example data
In this tutorial we will use example data, as IMAS is non-free you will have to get your IMAS data through your preferred supplier. We assume that the system is run with JINTRAC (since JINTRAC has a docker container available), and we use a simple JINTRAC template, which you are of course free to substitute for your own
shutil.rmtree('./example', ignore_errors=True)
os.mkdir('example')
# We assume that the duqtools source is available and that we are in the docs/examples folder
shutil.copytree('../../tests/test_data/template_model', 'example/template');
# Some imas data, substitute with your own, as we are not allowed to provide it
shutil.copytree('../../../containerized_runs/imasdb', 'example/imasdb');
# A silly script to support venvs
with open("example/entry.sh", "w") as f:
f.write("""#!/bin/bash
set -e
. /etc/profile.d/modules.sh
module load IMAS
module load fc2k
if [ -d .venv ]; then
. .venv/bin/activate
fi
exec "${@}"
""")
st = os.stat('example/entry.sh')
os.chmod('example/entry.sh', st.st_mode | stat.S_IEXEC)
!chmod +x example/entry.sh
# A simple configuration file for duqtools
with open("example/duqtools.yaml", "w") as f:
f.write("""system:
name: jetto
create:
template: ./template #TODO edit to directory where initial run is stored
template_data:
user: "/example/imasdb"
db: "jet"
shot: 123
run: 1
dimensions:
- operator: multiply
scale_to_error: false
values: [1.1, 1.2, 1.3]
variable: t_e
- operator: multiply
scale_to_error: false
values: [1.1, 1.2, 1.3]
variable: zeff
sampler:
method: latin-hypercube
n_samples: 3
submit:
submit_system: prominence
""")
!tree example #Its okay if this fails if you don't have tree installed
# Get the image and tag it, we could use a imas-only image for prominence
!docker login gitlab.eufus.psnc.pl:5050
!docker pull gitlab.eufus.psnc.pl:5050/containerization/jintrac/jintrac-imas-installer/jintrac-imas:latest
!docker tag gitlab.eufus.psnc.pl:5050/containerization/jintrac/jintrac-imas-installer/jintrac-imas:latest jintrac-imas:pulled
def niceprint(s):
return print(str(s.output, 'utf-8'))
def run_inside(container, cmd):
return container.exec_run(' '.join(['/example/entry.sh', cmd]))
# clean up existing container
try:
container.stop(timeout=0)
except:
pass
client = docker.from_env()
container = client.containers.run('jintrac-imas:latest',
working_dir="/example",
user=os.getuid(),
detach=True,
entrypoint="/example/entry.sh",
command="tail -f /dev/null",
volumes=[os.getcwd() + "/example:/example"],
auto_remove=True)
atexit.register(lambda: container.stop(timeout=0));
run_inside(container, 'python3 -m venv .venv');
niceprint(run_inside(container, 'python3 -m pip install duqtools -q'))
niceprint(run_inside(container, 'duqtools create --force --yes'))
#!cd example && duqtools submit --force --yes