UQ with PyTUQ
Time to Complete: 30-60 minutes
- What you will learn:
Install PyTUQ
Run an AMReX+PyTUQ to perform sensitivity analysis
Overview
AMReX simulations deliver high-fidelity, accurate results for complex physics problems, but the effect on simulation results due to uncertain inputs can require hundreds or thousands of simulations, making comprehensive analysis computationally prohibitive.
This tutorial demonstrates how to improve efficiency without sacrificing accuracy by using polynomial chaos expansions to build fast surrogate models that identify which input parameters truly matter.
PyTUQ (Python interface to the UQ Toolkit) provides specialized tools for surrogate construction and global sensitivity analysis, enabling rapid parameter space exploration and dimensionality reduction for scientific applications.
We demonstrate how to integrate PyTUQ with your AMReX application through a practical workflow; the AMReX-based heat equation tutorial is equipped to perform sensitivity analysis.
In these examples we model the heat equation
with initial condition
where r is the distance from the center of the domain, and with uncertain parameters diffusion_coeff (\(D\)), init_amplitude (\(A\)), and init_variance (\(V\)).
The outputs of interest are the maximum temperature, mean temperature, standard deviation of temperature, and the temperature at a specified point.
Located in amrex-tutorials/ExampleCodes/UQ/HeatEquation, this example illustrates a complete forward UQ workflow from parameter sampling randomized input parameters to perform sensitivity analysis.
By understanding this example, you will have a basis for understanding how to adapt this workflow to your own AMReX application.
More specifically, you can directly compare/diff amrex-tutorials/ExampleCodes/UQ/HeatEquation/main.cpp against the original heat equation tutorial amrex-tutorials/GuidedTutorials/HeatEquation_Simple/main.cpp to see exactly what source code changes are made to the AMReX application in this example.
Installation
We now describe the installation and workflow process on a local workstation. First, install pytuq using this script (based on information provided in pytuq/README.md):
#!/bin/bash
# 1. Clone repositories
git clone https://github.com/sandialabs/pytuq.git
# 2. Create a conda environment with python (optional, you can add to an existing env)
conda create --name pytuq
conda activate pytuq
conda install python=3.11
# 3. Install PyTUQ and requirements
cd pytuq
pip install -r requirements.txt
pip install .
conda install dill
# 4. Verify installation
conda list | grep pytuq # Should show pytuq 1.0.0
Examples
C++ AMReX + PyTUQ (BASH driven)
Prerequisites:
AMReX and pytuq cloned at the same directory level as amrex-tutorials
pytuq installation described above
GNU Parallel for task management:
sudo apt-get install parallel(mpiexec option also exists in script)cd /path/to/amrex-tutorials/ExampleCodes/UQ/HeatEquation/ make -j4./workflow_uqpc.x
Understanding GNU Parallel Workflow Pattern
The
workflow_uqpc.xbash script relies on the user augmenting their codes to write outputs of interest to ASCII text files. In this case, themain.cppwas modified from theamrex-tutorials/GuidedTutorials/HeatEquation_Simple/main.cppin the following ways:First, support for parsing
diffusion_coeff,init_amplitude, andinit_variancefrom the input file and command line were added.Second, support for writing outputs of interest to ASCII text files is added. The
datalog_filenameinput parameter is generated by the bash script to give each simulation output a unique identifier. Thedatalog_intparameter gives the user the option to write the outputs of interest at a given time step interval, but in this example, the outputs of interest after the final step are those that matter, and are extracted by the bash script to create a master output file containing a separate set of simulation outputs of interest in each row.The bash script calls PyTUQ scripts that generate an input parameter files for training and testing (
ptrain.txtandptest.txt) based on polynomial chaos settings, and then uses GNU Parallel to run multiple simulations efficiently and collect outputs into results files (ytrain.txtandytest.txt) that PyTUQ can use for surrogate model fitting.
Understanding the Output
Additional Resources
PyTUQ Resources:
eebaill, ksargsyan, & Bert Debusschere. (2025). sandialabs/pytuq: v1.0.0z (v1.0.0z). Zenodo. https://doi.org/10.5281/zenodo.17110054
AMReX Resources:
Uncertainty Quantification Theory:
Ghanem, Roger, David Higdon, and Houman Owhadi, eds. Handbook of Uncertainty Quantification. Vol. 6. New York: Springer, 2017. (For workflow, plotting, and analysis specifics)