Dakota
Contents
Dakota#
The Dakota project provides software for optimisation and uncertainty quantification.
Dakota can be used for a broad range of computational tasks as it enables design exploration, risk analysis, model calibration, and quantification of margins and uncertainty with computational models.
The intended use of Dakota is to aid computational methods developed to better understand the complex physical systems they simulate. In many cases these simulations are used to find the optimal design of a system, or to make prediction for systems that can not be directly tested.
The use of these computational simulations can lead to better system designs and improved overall performance. Furthermore, a reduced dependence on physical testing can reduce development costs and quicken the design process.
In this notebook, it will be presented how the Dakota library is used to automatize the parameter space investigated in a given computational model using python programming language.
Installation#
Dakota can be downloaded from Sandia National Laboratories website. For the latest release, download and extract a distribution file onto your computer. This tutorial will rely on the source code distribution (tar.gv files). The extracted directory will act as your Dakota installation directory.
To extract the tar.gv file navigate to the file and type the following:
tar xvzf file.tar.gz
Once the file has been extracted, navigate to the unzipped Dakota source code and find the first folder containing a CMakeList.txt file. Once there type the following to access cmake:
mkdir build
cd build
ccmake ..
On the window which appears, press the c key to run configure once. Once configured scroll to CMAKE-INSTALL-PREFIX and edit the variable to something memorable (e.g /home/name/dakota). Press the c key again to configure and then the g key to exit back to the terminal.
Once back in the terminal type the following to install Dakota:
make -j4
make install
Python template for Dakota#
To automatize the parameter space in your model using Dakota, you first need to have a Python script in which Dakota can adjust the parameters in the model simulations. To do this create a .py file with an editor of choice:
gedit file.py
Any parameter that is meant to be changed by Dakota, needs to be put in ‘{ }’ brackets. Dakota will evaluate changes in the response functions - print statements. In this case the print statement will involve Parameter 1 and Parameter 2. This is implemented by the following:
Parameter1 = {par1}
Parameter2 = {par2}
print(Parameter1*Parameter2)
Note
Dakota can automatize more parameters for more complex studies. It only allows one print statement in the Python file used as a template. You can still save plots or other useful when running the code. However, make sure to use, for example sys library to print outputs to the terminal that are not to be recognised as response functions by Dakota.
Dakota bash file#
The purpose of the bash file is to allow Dakota to investigate the selected parameters in the python file. In this case the bash file, e.g file.sh, creates a copy of the python file (the template file) and using Dakota executable ‘dprepro’, changes the values of parameters in curly brackets in the code. It then runs the Python script and returns the results.
In the following bash file ‘file.py’, we use previously created Python file and ‘file_temp.in’ which is the template file (described in the next section).
#!/bin/sh
# $1 is params.in FROM Dakota
# $2 is results.out returned to Dakota
#--------------
#PRE-PROCESSING
#--------------
echo entered shell script
dprepro $1 file.py file_temp.in
echo dprepro finished
# --------
# ANALYSIS
# --------
python file_temp.in > results.tmp
# ---------------
# POST-PROCESSING
# ---------------
mv results.tmp $2
Dakota input file#
The Dakota input file must consist of the following blocks: environment, method, model, variables, interface and responses. Details on these blocks can be found in the Reference Manual and User’s Manual.
As an example, in this simple case Dakota puts values ranging between 1 and 2 instead of Parameter1 ‘par1’, and values ranging between 3 and 4 instead of Parameter2 ‘par2’ from the template. According to the code above, Dakota will then calculate the product of Parameter1 and Parameter2 and grab the print statement into the tabular file ‘file.dat’. In this example, Dakota will use the efficient global optimisation algorithm that will guess subsequent ‘par1’ and ‘par2’ values to maximise the output, i.e. the print statement from the template file.
environment
tabular_data
tabular_data_file = ’file.dat’
method
efficient_global
max_iterations 50
convergence_tolerance 1e-3
x_conv_tol 1e-3
gaussian_process
surfpack
export_approx_points_file ’file_surrogate.dat’ #interpolates results for points within the
#parameter space that have not been calculated
variables
continuous_design = 2 #number of parameters
initial_point 1.5 3.5
lower_bounds 1 3
upper_bounds 2 4
descriptors ’par1’ ’par2’
model
single
interface
fork
analysis_driver = ’file.sh’ # bash file that connects Dakota and Python files
deactivate evaluation_cache restart_file
failure_capture continuation
responses
objective_functions = 1
sense ’maximize’
descriptors ’max_power’ #prints the average power with the aim of finding the max average power
no_gradients
no_hessians
Once the Python, bash and input files have been created, you can run the simulation with dakota using the following command line:
dakota -i file.in -o file.out