Running EasyVVUQ on HPC resources with QCG-PilotJob

Author: Bartosz Bosak, PSNC (bbosak@man.poznan.pl)

If this is your first Jupyter Notebook - you can execute code cells by selecting them and pressing Shift+Enter. Just have in mind that the order of execution might matter (if later cells depend on things done in earlier ones).

As defined in the VECMA glossary, uncertainty quantification UQ is a “discipline, which seeks to estimate the uncertainty in the model input and output parameters, to analyse the sources of these uncertainties, and to reduce their quantities.” However, this process can quickly become cumbersome because just a few uncertain inputs could require hundreds or even thousands of samples. If a single sample is a demanding simulation, such a number of tasks cannot be performed effectively without (1) adequate computational resources, (2) a dedicated approach and (3) specialised programming solutions.

EasyVVUQ has been designed as a modular software that can benefit from the solutions providing advanced capabilities for execution of demanding operations on computational resources. One of such solutions is QCG-PilotJob, which allows to efficiently run a number of tasks inside a single large allocation on a Slurm cluster.

In this tutorial, based on the scenario presented in the basic tutorial, we demonstrate how EasyVVUQ workflows can be adapted to enable their executions with QCG-PilotJob on HPC machines. As it will be shown the adaptation is quite easy.

Prerequisites

You need to have EasyVVUQ installed in your environment. There is no need to install QCG-PilotJob’s packages separately since they are installed as EasyVVUQ’s dependencies.

[3]:
pip install easyvvuq
Collecting easyvvuq
  Using cached easyvvuq-1.0-py3-none-any.whl (199 kB)
Collecting chaospy==4.3.2
  Using cached chaospy-4.3.2-py3-none-any.whl (247 kB)
Collecting scikit-learn
  Using cached scikit_learn-0.24.2-cp37-cp37m-manylinux2010_x86_64.whl (22.3 MB)
Collecting kubernetes
  Using cached kubernetes-17.17.0-py3-none-any.whl (1.8 MB)
Requirement already satisfied: qcg-pilotjob~=0.12.0 in /opt/conda/lib/python3.7/site-packages (from easyvvuq) (0.12.1+4.g46d0d03)
Collecting numpoly==1.1.3
  Using cached numpoly-1.1.3-py3-none-any.whl (138 kB)
Collecting dill
  Using cached dill-0.3.4-py2.py3-none-any.whl (86 kB)
Collecting dask-jobqueue
  Using cached dask_jobqueue-0.7.2-py2.py3-none-any.whl (39 kB)
Processing /home/jovyan/.cache/pip/wheels/b1/f5/ee/9c072cedde5286a5f4b27e07269ad83a67878ff249794c8c97/pytest_pep8-1.0.6-py3-none-any.whl
Requirement already satisfied: SQLAlchemy in /opt/conda/lib/python3.7/site-packages (from easyvvuq) (1.3.13)
Processing /home/jovyan/.cache/pip/wheels/6c/bd/4b/a3b7dcd0bc718e601a9ba7cba5f7c1d73fd777b6dc48d6eaa0/Cerberus-1.3.4-py3-none-any.whl
Processing /home/jovyan/.cache/pip/wheels/7e/72/eb/c96a0b4b22f42d092914ba8fe7b4c639443ef02b529dbbefcf/pytest_dependency-0.5.1-py3-none-any.whl
Collecting pytest-benchmark
  Using cached pytest_benchmark-3.4.1-py2.py3-none-any.whl (50 kB)
Collecting pandas
  Using cached pandas-1.3.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (10.8 MB)
Collecting autopep8
  Using cached autopep8-1.5.7-py2.py3-none-any.whl (45 kB)
Collecting squarify
  Using cached squarify-0.4.3-py3-none-any.whl (4.3 kB)
Collecting scipy
  Using cached scipy-1.7.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (28.5 MB)
Requirement already satisfied: tqdm in /opt/conda/lib/python3.7/site-packages (from easyvvuq) (4.42.0)
Requirement already satisfied: jinja2 in /opt/conda/lib/python3.7/site-packages (from easyvvuq) (2.11.0)
Collecting qcg-pilotjob-executor-api~=0.12.0
  Using cached qcg_pilotjob_executor_api-0.12.1-py3-none-any.whl (7.0 kB)
Collecting numpy
  Using cached numpy-1.21.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)
Requirement already satisfied: wheel in /opt/conda/lib/python3.7/site-packages (from easyvvuq) (0.34.1)
Collecting dask[complete]
  Using cached dask-2021.7.0-py3-none-any.whl (977 kB)
Collecting pytest
  Using cached pytest-6.2.4-py3-none-any.whl (280 kB)
Collecting cloudpickle
  Using cached cloudpickle-1.6.0-py3-none-any.whl (23 kB)
Processing /home/jovyan/.cache/pip/wheels/24/21/f7/50d0bf40bf7980c92b63c7108d801fdaaef5374de63454f921/SALib-1.4.0.2-py2.py3-none-any.whl
Collecting joblib>=0.11
  Using cached joblib-1.0.1-py3-none-any.whl (303 kB)
Collecting threadpoolctl>=2.0.0
  Using cached threadpoolctl-2.2.0-py3-none-any.whl (12 kB)
Collecting websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0
  Using cached websocket_client-1.1.0-py2.py3-none-any.whl (68 kB)
Requirement already satisfied: setuptools>=21.0.0 in /opt/conda/lib/python3.7/site-packages (from kubernetes->easyvvuq) (45.1.0.post20200119)
Requirement already satisfied: six>=1.9.0 in /opt/conda/lib/python3.7/site-packages (from kubernetes->easyvvuq) (1.14.0)
Requirement already satisfied: certifi>=14.05.14 in /opt/conda/lib/python3.7/site-packages (from kubernetes->easyvvuq) (2019.11.28)
Requirement already satisfied: urllib3>=1.24.2 in /opt/conda/lib/python3.7/site-packages (from kubernetes->easyvvuq) (1.25.7)
Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from kubernetes->easyvvuq) (2.22.0)
Collecting pyyaml>=3.12
  Using cached PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl (636 kB)
Collecting requests-oauthlib
  Using cached requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting google-auth>=1.0.1
  Downloading google_auth-1.33.0-py2.py3-none-any.whl (151 kB)
     |████████████████████████████████| 151 kB 2.8 MB/s eta 0:00:01
Requirement already satisfied: python-dateutil>=2.5.3 in /opt/conda/lib/python3.7/site-packages (from kubernetes->easyvvuq) (2.8.1)
Requirement already satisfied: click in /opt/conda/lib/python3.7/site-packages (from qcg-pilotjob~=0.12.0->easyvvuq) (8.0.1)
Requirement already satisfied: zmq in /opt/conda/lib/python3.7/site-packages (from qcg-pilotjob~=0.12.0->easyvvuq) (0.0.0)
Requirement already satisfied: psutil in /opt/conda/lib/python3.7/site-packages (from qcg-pilotjob~=0.12.0->easyvvuq) (5.8.0)
Collecting distributed>=2.19
  Using cached distributed-2021.7.0-py3-none-any.whl (1.0 MB)
Collecting pep8>=1.3
  Using cached pep8-1.7.1-py2.py3-none-any.whl (41 kB)
Processing /home/jovyan/.cache/pip/wheels/76/fb/36/4304dce3f49d3aecf92d63f079db516641a8061a83a0b5a292/pytest_cache-1.0-py3-none-any.whl
Processing /home/jovyan/.cache/pip/wheels/d2/f1/1f/041add21dc9c4220157f1bd2bd6afe1f1a49524c3396b94401/py_cpuinfo-8.0.0-py3-none-any.whl
Collecting pytz>=2017.3
  Using cached pytz-2021.1-py2.py3-none-any.whl (510 kB)
Collecting pycodestyle>=2.7.0
  Using cached pycodestyle-2.7.0-py2.py3-none-any.whl (41 kB)
Collecting toml
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: MarkupSafe>=0.23 in /opt/conda/lib/python3.7/site-packages (from jinja2->easyvvuq) (1.1.1)
Collecting fsspec>=0.6.0
  Using cached fsspec-2021.7.0-py3-none-any.whl (118 kB)
Collecting partd>=0.3.10
  Using cached partd-1.2.0-py3-none-any.whl (19 kB)
Collecting toolz>=0.8.2
  Using cached toolz-0.11.1-py3-none-any.whl (55 kB)
Processing /home/jovyan/.cache/pip/wheels/57/e3/79/051e58e8a3d9076de99bdd7d68d463289e28c18329933984ff/bokeh-2.3.3-py3-none-any.whl
Requirement already satisfied: attrs>=19.2.0 in /opt/conda/lib/python3.7/site-packages (from pytest->easyvvuq) (19.3.0)
Collecting iniconfig
  Using cached iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)
Collecting pluggy<1.0.0a1,>=0.12
  Using cached pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Requirement already satisfied: importlib-metadata>=0.12; python_version < "3.8" in /opt/conda/lib/python3.7/site-packages (from pytest->easyvvuq) (4.6.1)
Collecting packaging
  Using cached packaging-21.0-py3-none-any.whl (40 kB)
Collecting py>=1.8.2
  Using cached py-1.10.0-py2.py3-none-any.whl (97 kB)
Collecting matplotlib
  Using cached matplotlib-3.4.2-cp37-cp37m-manylinux1_x86_64.whl (10.3 MB)
Collecting pathos
  Using cached pathos-0.2.8-py2.py3-none-any.whl (81 kB)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->kubernetes->easyvvuq) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->kubernetes->easyvvuq) (2.8)
Requirement already satisfied: oauthlib>=3.0.0 in /opt/conda/lib/python3.7/site-packages (from requests-oauthlib->kubernetes->easyvvuq) (3.0.1)
Collecting pyasn1-modules>=0.2.1
  Using cached pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
Collecting cachetools<5.0,>=2.0.0
  Using cached cachetools-4.2.2-py3-none-any.whl (11 kB)
Collecting rsa<5,>=3.1.4; python_version >= "3.6"
  Using cached rsa-4.7.2-py3-none-any.whl (34 kB)
Requirement already satisfied: pyzmq in /opt/conda/lib/python3.7/site-packages (from zmq->qcg-pilotjob~=0.12.0->easyvvuq) (22.1.0)
Requirement already satisfied: tornado>=5; python_version < "3.8" in /opt/conda/lib/python3.7/site-packages (from distributed>=2.19->dask-jobqueue->easyvvuq) (6.0.3)
Collecting zict>=0.1.3
  Using cached zict-2.0.0-py3-none-any.whl (10 kB)
Collecting msgpack>=0.6.0
  Using cached msgpack-1.0.2-cp37-cp37m-manylinux1_x86_64.whl (273 kB)
Collecting sortedcontainers!=2.0.0,!=2.0.1
  Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting tblib>=1.6.0
  Using cached tblib-1.7.0-py2.py3-none-any.whl (12 kB)
Collecting execnet>=1.1.dev1
  Using cached execnet-1.9.0-py2.py3-none-any.whl (39 kB)
Collecting locket
  Using cached locket-0.2.1-py2.py3-none-any.whl (4.1 kB)
Collecting pillow>=7.1.0
  Using cached Pillow-8.3.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (3.0 MB)
Requirement already satisfied: typing-extensions>=3.7.4 in /opt/conda/lib/python3.7/site-packages (from bokeh!=2.0.0,>=1.0.0; extra == "complete"->dask[complete]->easyvvuq) (3.10.0.0)
Requirement already satisfied: zipp>=0.5 in /opt/conda/lib/python3.7/site-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest->easyvvuq) (3.5.0)
Collecting pyparsing>=2.0.2
  Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Collecting cycler>=0.10
  Using cached cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)
Collecting kiwisolver>=1.0.1
  Using cached kiwisolver-1.3.1-cp37-cp37m-manylinux1_x86_64.whl (1.1 MB)
Collecting ppft>=1.6.6.4
  Using cached ppft-1.6.6.4-py3-none-any.whl (65 kB)
Collecting pox>=0.3.0
  Using cached pox-0.3.0-py2.py3-none-any.whl (30 kB)
Collecting multiprocess>=0.70.12
  Using cached multiprocess-0.70.12.2-py37-none-any.whl (112 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Using cached pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
Collecting heapdict
  Using cached HeapDict-1.0.1-py3-none-any.whl (3.9 kB)
Installing collected packages: numpy, scipy, numpoly, chaospy, joblib, threadpoolctl, scikit-learn, websocket-client, pyyaml, requests-oauthlib, pyasn1, pyasn1-modules, cachetools, rsa, google-auth, kubernetes, dill, heapdict, zict, msgpack, sortedcontainers, tblib, toolz, cloudpickle, fsspec, locket, partd, pytz, pandas, pillow, pyparsing, packaging, bokeh, dask, distributed, dask-jobqueue, pep8, iniconfig, pluggy, py, toml, pytest, execnet, pytest-cache, pytest-pep8, cerberus, pytest-dependency, py-cpuinfo, pytest-benchmark, pycodestyle, autopep8, squarify, qcg-pilotjob-executor-api, cycler, kiwisolver, matplotlib, ppft, pox, multiprocess, pathos, SALib, easyvvuq
Successfully installed SALib-1.4.0.2 autopep8-1.5.7 bokeh-2.3.3 cachetools-4.2.2 cerberus-1.3.4 chaospy-4.3.2 cloudpickle-1.6.0 cycler-0.10.0 dask-2021.7.0 dask-jobqueue-0.7.2 dill-0.3.4 distributed-2021.7.0 easyvvuq-1.0 execnet-1.9.0 fsspec-2021.7.0 google-auth-1.33.0 heapdict-1.0.1 iniconfig-1.1.1 joblib-1.0.1 kiwisolver-1.3.1 kubernetes-17.17.0 locket-0.2.1 matplotlib-3.4.2 msgpack-1.0.2 multiprocess-0.70.12.2 numpoly-1.1.3 numpy-1.21.0 packaging-21.0 pandas-1.3.0 partd-1.2.0 pathos-0.2.8 pep8-1.7.1 pillow-8.3.1 pluggy-0.13.1 pox-0.3.0 ppft-1.6.6.4 py-1.10.0 py-cpuinfo-8.0.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 pycodestyle-2.7.0 pyparsing-2.4.7 pytest-6.2.4 pytest-benchmark-3.4.1 pytest-cache-1.0 pytest-dependency-0.5.1 pytest-pep8-1.0.6 pytz-2021.1 pyyaml-5.4.1 qcg-pilotjob-executor-api-0.12.1 requests-oauthlib-1.3.0 rsa-4.7.2 scikit-learn-0.24.2 scipy-1.7.0 sortedcontainers-2.4.0 squarify-0.4.3 tblib-1.7.0 threadpoolctl-2.2.0 toml-0.10.2 toolz-0.11.1 websocket-client-1.1.0 zict-2.0.0
Note: you may need to restart the kernel to use updated packages.

Application scenario

Let’s remind the basic use-case. It is a simulation of a vertical deflection of a round metal tube suspended on each end in response to a force applied at certain point a along its length. Our goal is to determine the influence of the input parameters on the vertical deflection at point a.

The usage of the application is:

beam <input_file>

It outputs calculated displacements to a file called output.json. Its content will look like

{'g1': x, 'g2': y, 'g3': y}

In order to produce statistically significant results, EasyVVUQ needs to run a number of model evaluations appropriately selecting input arguments from a given sample parameter space. Once selected, input parameters need to be transformed into a format understandable by the application. Our application takes a single file as an input and the transformation may be based on a single template file, called beam.template, with the following content:

{"outfile": "$outfile", "F": $F, "L": $L, "a": $a, "D": $D, "d": $d, "E": $E}

The template will be used to generate files called input.json that will be the input to each run of beam. All placeholders (signified by the $ delimeter) will be replaced by concrete values from the sample parameter space.

So, for example (commands preceded by an exclamation mark are treated as shell commands):

[3]:
!pwd
!echo "{\"outfile\": \"output.json\", \"F\": 1.0, \"L\": 1.5, \"a\": 1.0, \"D\": 0.8, \"d\": 0.1, \"E\": 200000}" > input.json
/home/jovyan/tutorials/VECMAtk/BEAM
[4]:
!./beam input.json
[5]:
!cat output.json
{"g1": -6.909453505549654e-06, "g2": -1.3818907011099308e-05, "g3": 1.7273633763874136e-05}

In this tutorial, in the similar fashion as in the basic one, we will demonstrate how to use of EasyVVUQ to do variance based sensitivity analysis of beam application using stochastic collocation.

Nevertheless, the way of usage of QCG-PilotJob in EasyVVUQ is generic and will look the same also for other applications and other supported by EasyVVUQ methods.

Campaign

In order to use EasyVVUQ, we need to configure the EasyVVUQ Campaign object. We do this in almost the same way as in case of basic use-case. Firstly we import the same set of libraries as in the original example:

[1]:
import os
import easyvvuq as uq
import chaospy as cp
import matplotlib.pyplot as plt
from easyvvuq.actions import CreateRunDirectory, Encode, Decode, CleanUp, ExecuteLocal, Actions

We only extend this set of imports with a module for the QCG-PilotJob pool:

[2]:
from easyvvuq.actions import QCGPJPool

Then, we can continue the code from the basic workflow. For the validation purposes, we describe a set of parameters used by the application:

[3]:
params = {
    "F": {"type": "float", "default": 1.0},
    "L": {"type": "float", "default": 1.5},
    "a": {"type": "float", "min": 0.7, "max": 1.2, "default": 1.0},
    "D": {"type": "float", "min": 0.75, "max": 0.85, "default": 0.8},
    "d": {"type": "float", "default": 0.1},
    "E": {"type": "float", "default": 200000},
    "outfile": {"type": "string", "default": "output.json"}
}

and, by specification of encoder and decoder, define how EasyVVUQ should convert data between its internal and the application logic:

[4]:
encoder = uq.encoders.GenericEncoder(template_fname='beam.template', delimiter='$', target_filename='input.json')
decoder = uq.decoders.JSONDecoder(target_filename='output.json', output_columns=['g1'])

Hence our application takes and produces very simple data structures, we use build-in Encoder and Decoder classes, but you are able to provide custom implementations of encoders and decoders that will fit your own use-case.

The next step is a definition of an execute action that will be used to run the beam application with a prepared input file.

[5]:
execute = ExecuteLocal('{}/beam input.json'.format(os.getcwd()))

Now we are allowed to push all actions we want to execute for samples into the Actions object:

[6]:
actions = Actions(CreateRunDirectory('/tmp'),
                  Encode(encoder), execute, Decode(decoder))

and finally create EasyVVUQ Campaign:

[7]:
campaign = uq.Campaign(name='beam', params=params, actions=actions)

The remaining steps to configure the campaign object are to define distributions for the input parameters and initialise a sampler. This code is the same regardeless we use or not QCG-PilotJob:

[8]:
vary = {
    "F": cp.Normal(1, 0.1),
    "L": cp.Normal(1.5, 0.01),
    "a": cp.Uniform(0.7, 1.2),
    "D": cp.Triangle(0.75, 0.8, 0.85)
}
campaign.set_sampler(uq.sampling.SCSampler(vary=vary, polynomial_order=1))

QCGPJ-Pool

Now we are able to execute all evaluations. However, in contrast to the basic tutorial, where the code was prepared to be run on a local machine, our target here is to demonstrate how to use QCG-PilotJob to execute evaluations on an HPC cluster.

To this end, we need to create a QCGPJPool object and provide it to the campaign’s execute method. In the most simplistic configuration, we can initialise QCGPjPool within the with statement and don’t provide any arguments to the constructor:

[9]:
with QCGPJPool() as qcgpj:
    campaign.execute(pool=qcgpj).collate()

Empty list of QCGPJPool constructor’s parameter lead to the default settings of the pool and execution of all evaluations with a default task template. This may be sufficient for basic use-cases, but in order to support more advanced execution scenarios, several parameters may need to be provided to the constructor:

  • qcgpj-executor - allows to setup specific parameters of the QCG-PilotJob service by creation of a custom QCGPJExecutor instance. For example, if we skip this parameter, QCG-PilotJob will automatically set up to execute on all available resources, which is perfectly fine if we run the code on HPC resources, since it will take care of proper and efficient scheduling of tasks to the resources available in the allocation. However, if we would like to make some tests on a local machine, it may be more optimal to define virtual resources, and this may be defined with the resources parameter to the QCGPJExecutor constructor.

  • template and template_params - by default the tasks use a predefined template (EasyVVUQBasicTemplate) that leads to execution of QCG-PilotJob’s tasks in a default mode, only on a single core. It could be altered by providing custom task template and template_params.

  • polling_interval - allows to change the default interval between queries asking about the status of tasks to the QCG-PilotJob Manager service.

Let us show how to modify this example to demonstrate usage of these more advanced options.

Parallel Tasks

Firstly, we would change the template and template_params to enable execution of tasks on many resources. Thus, instead of a default template class, we will employ EasyVVUQParallelTemplate that allows us also to set numCores and numNodes parameters.

In order to demonstrate it, we have to have a clean situation and therefore we need to initialise a new campaign:

[10]:
campaign = uq.Campaign(name='beam', params=params, actions=actions)
campaign.set_sampler(uq.sampling.SCSampler(vary=vary, polynomial_order=1))

Now we are able to execute campaign actions once again. This time it looks as follows:

[11]:
from easyvvuq.actions.execute_qcgpj import EasyVVUQParallelTemplate

with QCGPJPool(
        template=EasyVVUQParallelTemplate(),
        template_params={'numCores': 4}) as qcgpj:
    campaign.execute(pool=qcgpj).collate()

We have set numCores to 4, which is one of parameters supported by EasyVVUQParallelTemplate. It results in assigning 4 cores for each task. Please note that this setting is not optimal for our example beam code, which is not parallel - in case of such codes single core tasks are perfectly fine. Nevertheless, possibility to define numCores and numNodes is essential for the proper execution of MPI or OpenMP applications.

Note: In order to run parallel code inside a QCG-PilotJob task, a full command for the paralleled run should be given to the ExecuteLocal action (e.g. mpirun -n 4 NAME_OF_PROGRAM).

Now let’s try to set some larger number of nodes:

[12]:
campaign = uq.Campaign(name='beam', params=params, actions=actions)
campaign.set_sampler(uq.sampling.SCSampler(vary=vary, polynomial_order=1))

try:
    with QCGPJPool(
            template=EasyVVUQParallelTemplate(),
            template_params={'numNodes': 2, 'numCores': 4}) as qcgpj:
        campaign.execute(pool=qcgpj).collate()
except Exception as e:
    print(e)
Request failed - Not enough resources for job 1

If you see that the exception saying that there is not enough resources has been caught, it is not a surprise. Well, we don’t have 2 nodes to use and QCG-PilotJob reports that our task is too big.

Local / virtualised mode of execution

What in a case if we want to prepare and test the workflow on a local machine before it will be transferred to the HPC environment? QCG-PilotJob has a solution for this which is called Local Mode and allows to define virtual resources. Let’s modify our example a bit:

[13]:
campaign = uq.Campaign(name='beam', params=params, actions=actions)
campaign.set_sampler(uq.sampling.SCSampler(vary=vary, polynomial_order=1))

from qcg.pilotjob.executor_api.qcgpj_executor import QCGPJExecutor

with QCGPJPool(
        qcgpj_executor=QCGPJExecutor(resources="node1:4,node2:4"),
        template=EasyVVUQParallelTemplate(),
        template_params={'numNodes': 2, 'numCores': 4}) as qcgpj:
    campaign.execute(pool=qcgpj).collate()

As it can be seen, we added qcpj_executor parameter to the QCGPJPool constructor. The parameter is set to the customised QCGPJExecutor instance, which has been created with parameter resources set to node1:4,node2:4. In this way we have defined two virtual nodes, each with 4 cores. In a result this example can been executed successfully.

Tasks templates

You can get more information about the parameteres available in the templates with the following way:

[14]:
print(EasyVVUQParallelTemplate().template()[0])

            {
                'name': '${name}',
                'execution': {
                    'exec': '${exec}',
                    'args': ${args},
                    'stdout': '${stdout}',
                    'stderr': '${stderr}',
                    'venv': '${venv}',
                    'model': '${model}',
                    'model_opts': ${model_opts}
                },
                'resources': {
                    'numCores': {
                        'exact': ${numCores}
                    },
                    'numNodes': {
                        'exact': ${numNodes}
                    }
                }
            }

You can also easily get information about default values for the keys:

[15]:
EasyVVUQParallelTemplate().template()[1]
[15]:
{'args': [],
 'stdout': 'stdout',
 'stderr': 'stderr',
 'venv': '',
 'model': 'default',
 'model_opts': {},
 'numCores': 1,
 'numNodes': 1}
  • Note 1: If the functionality of built-in templates is not sufficient, you can always create a new one by extensions of existing.

  • Note 2: The keys name, stdout and stderr are necessary for the code to work properly, so newly created templates must define these keys in an analogous way as they are defined in the existing templates. It is also not possible to set these keys to custom values, because they are substituted automatically by the internal software logic.

Analysis

At this moment we should have our evaluations ready and their results collated and stored in the campaing’s database. Since we have used QCGPJPool inside the with statement it has been already cleaned up and we don’t need any other code specific for QCG-PilotJob’s execution. Thus the remaining part of the tutorial can be no different from its basic version. In other words, starting from now, we have all data needed to perform analysis in a typical for EasyVVUQ way.

At the beginning we can display the collattion results:

[16]:
campaign.get_collation_result()
[16]:
run_id iteration F L a D d E outfile g1
0 0 0 0 0 0 0 0 0 0
0 1 0 0.9 1.49 0.805662 0.779588 0.1 200000 output.json -0.000008
1 2 0 0.9 1.49 0.805662 0.820412 0.1 200000 output.json -0.000007
2 3 0 0.9 1.49 1.094338 0.779588 0.1 200000 output.json -0.000005
3 4 0 0.9 1.49 1.094338 0.820412 0.1 200000 output.json -0.000004
4 5 0 0.9 1.51 0.805662 0.779588 0.1 200000 output.json -0.000009
5 6 0 0.9 1.51 0.805662 0.820412 0.1 200000 output.json -0.000007
6 7 0 0.9 1.51 1.094338 0.779588 0.1 200000 output.json -0.000006
7 8 0 0.9 1.51 1.094338 0.820412 0.1 200000 output.json -0.000005
8 9 0 1.1 1.49 0.805662 0.779588 0.1 200000 output.json -0.000010
9 10 0 1.1 1.49 0.805662 0.820412 0.1 200000 output.json -0.000008
10 11 0 1.1 1.49 1.094338 0.779588 0.1 200000 output.json -0.000006
11 12 0 1.1 1.49 1.094338 0.820412 0.1 200000 output.json -0.000005
12 13 0 1.1 1.51 0.805662 0.779588 0.1 200000 output.json -0.000011
13 14 0 1.1 1.51 0.805662 0.820412 0.1 200000 output.json -0.000009
14 15 0 1.1 1.51 1.094338 0.779588 0.1 200000 output.json -0.000007
15 16 0 1.1 1.51 1.094338 0.820412 0.1 200000 output.json -0.000006

We then call the analyse method whose functionality will depend on the sampling method used. It returns an `AnalysisResults <>`__ object which can be used to retrieve numerical values or plot the results. In this case Sobols indices.

[17]:
results = campaign.analyse(qoi_cols=['g1'])

We can plot the results in a treemap format. Each square representing the relative influence of that parameter to the variance of the output variable (vertical displacement at point a). A square labeled higher orders represent the influence of the interactions between the input parameters.

[18]:
results.plot_sobols_treemap('g1', figsize=(10, 10))
plt.axis('off');
/home/wouter/.local/lib/python3.9/site-packages/easyvvuq/analysis/results.py:467: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  fig.show()
../_images/tutorials_basic_tutorial_qcgpj_53_1.png

Alternatively you can get the Sobol index values using the method call below.

[30]:
results.sobols_first('g1')
[30]:
{'F': array([0.13515478]),
 'L': array([0.01220653]),
 'a': array([0.69667914]),
 'D': array([0.13994264])}