In this tutorial you will learn how to run a GW simulation using Yambo on a HPC machine.
You will compute the quasiparticle corrections to the band structure of a free-standing single layer of MoS while learning about convergence studies, parallel strategies, and GPU calculations.
In the end, you will obtain a quasiparticle band structure based on the simulations, the first step towards the reproduction of an ARPES spectrum. Beware: we won't use fully converged parameters, so the final result should not be considered very accurate.
MoS monolayer (top and side views). Gray: Mo atoms, yellow: S atoms.
We want to describe the electronic energy levels using a better description of electron-electron interactions than DFT is capable of.
Essentially, we want to solve the non-linear quasiparticle equation at first order in the GW self-energy :
Here and are the Kohn-Sham energies and wavefunctions, respectively, while is the DFT exchange-correlation potential.
For each electronic state , the self-energy can be separated into two components: a static, gap-opening term called the exchange self-energy (), and an energy-dependent, usually gap-closing term called the correlation self-energy (). These contributions are tackled separately by the code:
The energy-dependent dynamical electronic screening is included in and must therefore be calculated as well.
In this way, we can compute the "quasiparticle" corrections to the single-particle Kohn-Sham eigenvalues .
The typical workflow for a GW calculation is:
Go to your user work directory and download the materials for the tutorial (1.2GB, it may take a couple of minutes):
You can now enter the tutorial directory
SAVE
folderFirst of all, we need to convert some of the data produced in a previous non-self-consistent DFT calculation (using Quantum ESPRESSO) into a convenient format for Yambo.
The QE save folder for MoS is already present at 00_QE-DFT
. We should move inside it and then run the p2y
executable to generate the uninitialised SAVE
.
But first, we need to access a node interactively:
The, we need to load the yambo-specific modules in in the cluster. On Leonardo Booster, we have
Finally:
Now, we need to run the initialization step. Every Yambo run must start with this step. This will be automatically performed when you run Yambo on a SAVE
directory for the first time. Just type
and then check the yambo log called l_setup
. The initialization step determines the -vector shells and the - and -point grids based on the DFT calculations. If you check inside the SAVE
you will see two types of databases. The static ones, starting with ns.*
, are directly converted in the p2y
step, while the dynamical ones, ndb.*
are generated during the initialisation.
The databases are written in netCDF format.
Yambo has produced also a human readable output, r_setup
, reporting relevant information such as lattice parameters, symmetries, atomic positions, k-points, DFT eigenvalues and band gaps. We can have a quick look at the sections.
Finally, let us move the SAVE
and the report file to the directory where we will run the first GW calculation.
Now that we have a working SAVE
, it is time to generate the input file we will be using for our first GW calculation.
This can be done by the yambo
executable via command-line instructions.
If you type
You will get a list of the possibile options:
In order to build our input, we need to use the options for a GW calculation. We want to use the plasmon pole approximation for the dynamical screening, solve the quasiparticle equation with the Newton method, and add a truncation of the Coulomb potential which is useful for 2D systems. In addition, we want to set up explicitly the parameters for parallel runs. Therefore we type:
Now we can exit the computing node, since all remaining calculations will be run by submitting jobs with the slurm
scheduler.
You can now inspect the input file gw.in
and try to familiarize with some of the parameters. The input will come with default values for many parameters that we might need to change.
We discuss them below step by step.
We start with the runlevels:
el_el_corr
and gw0
: Yambo learns that it has to run a GW calculation (enables [GW] variables).rim_cut
: Coulomb potential Random Integration Method, a long-range averaging technique, and low-dimensional cutoff (enables [RIM] and [CUT] variables).HF_and_locXC
: calculation of exchange part of the self-energy (i.e., Hartree-Fock approximation).em1d
: enables the calculation of the dynamical screening of the electrons, i.e. the dielectric matrix ([X] variables). In this way Yambo can go beyond Hartree-Fock and eventually compute .ppa
: tells Yambo that the dynamical screening should be computed in the plasmon pole approximation ([Xp] variables).dyson
: Yambo will solve the Dyson-like quasiparticle equation.Going through the file we find:
Recall that we have, for the exchange self-energy:
EXXRLvcs
controls the number of Reciprocal Lattice vectors (i.e., G-vectors) used to build the exchange self-energy, while VXCRLvcs
does the same for the exchange-correlation potential reconstructed from DFT. Since these two quantities are to be subtracted, it is important to keep the same values here (and possibly not change the default maximum value).Let us now have a look at the parameters for the calculation of the correlation part of the self-energy. Recall that we have:
(Here, the -terms represent the screening matrix elements which are computed separately by yambo and stored in their own database.)
The calculation is divided in two steps. First, the response function in the plasmon pole approximation (em1d ppa
), under the keywords [X]
and [Xp]
, i.e., .
Chimod= "Hartree"
indicates that we compute the response function in the Random Phase Approximation (RPA).BndsRnXp
represents the electronic states included in the response function , and is a convergence parameter.NGsBlkXp
is the number of G-vectors used to calculate the RPA response function . It is a convergence parameter and can be expressed in number of reciprocal lattice vectors (RL) or energy (Ry, suggested).LongDrXp
represents the direction of the long-range auxiliary external electric field used to compute at . In general you have to be mindful of the system symmetries. In our case, we will put 1 | 1 | 1
to cover all directions.PPAPntXp= 27.21138 eV
is the energy of the plasmon pole. We don't normally change this.XTermKind
is used to specify a "terminator": this accelerates numerical convergence with respect to the number of bands BndsRnXp
.Next, we have the [GW]
group of parameters controlling the next part of the correlation self-energy calculation:
GbndRnge
is the number of bands used to build the correlation self-energy. It is a convergence parameter and can be accelerated with the terminator GTermKind
.DysSolver="n"
specifies the method used to solve the linearised quasiparticle equation. In most cases, we use the Newton method "n"
.QPkrange
indicates the range of electronic (nk) states for which the GW correction is computed. The first pair of numbers represents the range of k-point indices, the second pair the range of band indices.We now take a look at the parameters relative to the Coulomb interaction at small momenta and for 2D systems, which we should edit now once and for all.
Finally, we have the parallel parameters. We are going to discuss them at the end of the parallel section, we can skip them for now.
In a GW calculation, the most important parameters to be numerically converged are:
BndsRnXp
NGsBlkXp
GbndRnge
From the above discussion you can easily guess that many-body perturbation theory calculations are much more numerically expensive than DFT calculations.
We will start by running a single GW calculation. Here we will focus on the magnitude of the quasiparticle gap. This means that we only need to calculate two quasi-particle corrections, i.e., valence and conduction bands at the k-point where the minimum gap occurs. This information can be found by inspecting the report file r_setup
produced when the SAVE
folder was initialised. Just search for the string 'Direct Gap' and you'll see that the latter occurs at k-point 7 between bands 13 and 14:
In addition, we'll set the number of bands in BndsRnXp
and GbndRnge
to a small value, just to have it run fast. Hence, we modify the input file accordingly (check BndsRnXp
, GbndRnge
, LongDrXp
, QPkrange
):
We are now ready to run this calculation. Since you should never run a Yambo calculation on the login node, we will need a submission script to add our job to the queue. A submission script optimized for Leonardo Booster (running on GPUs) is provided as an example. Modify it to suit your specific machine.
We will ignore all details regarding parallelization, as it will be covered in the next section. Since there are no lowercase flags after yambo
, it is not going to generate an input file, but rather, run the one specified by -F
. Now, go ahead an submit this job
The status of the jobs can be monitored via:
The newly generated databases will be stored in the job directory, as specified by -J
, while the report, log and output files will be stored in the communications directory (-C
). As this is your first yambo
run, take a moment to inspect the report and log files, which you can find inside the -C
directory. In these report and log files, you can see the steps performed by yambo
. For instance, the code calculates the screening at every k-point and stores it in the PPA database called ndb.pp
. By opening the report
you will see
Then, the actual GW section will use this calculated dielectric screening to construct the correlation part of the self-energy:
Now, inspect the output file
In this file, Eo
is our starting point (DFT) while E-Eo
shows the GW correction one should apply to obtain the quasi-particle energies. In order to calculate the gap (automatically from the command line), we'll use some simple commands. First, we get everything that is not a #
symbol grep -v '#'
and we pass that to another command with a "pipe" |
. Then, tail -n 1
/head -n 1
will retain the first/last line, and awk '{print $3+$4}'
will get us the sum of the third and fourth columns. Altogether, this would be as follows
These two commands give us the quasiparticle energies we've calculated - their difference is the GW-corrected optical gap.
In this part of the tutorial, we will study convergence with respect to some of the parameters mentioned above. In order to complete this tutorial within a single hands-on session, we will restrict ourselves to a very coarse -point grid.
Hence, we'll perform our convergence studies on top of a DFT calculation done with a 6 6 1 k-point grid and without spin-orbit coupling: the SAVE
we generated earlier.
While this will speed up calculations and could be run even on a single GPU card, you should be aware that such coarse sampling of the BZ is severely underconverged and should only be used for educational purposes. In addition, spin-orbit interaction is extremely relevant for the valley physics of MoS2 and should not be neglected in realistic calculations.
Let's move into the appropriate directory
We are now ready to start our convergence tests. We'll begin with the variables controlling the polarization function, i.e., NGsBlkXp
for the number of G-vectors and BndsRnXp
for the number of bands. For this, we will keep GbndRnge
constant at a reasonably high value - you can inspect the input i01-GW
and check that you have:
Since we need to run yambo
for several values of NGsBlkXp
and BndsRnXp
, it makes sense to use two nested loops. That is exactly what we did in the submission script run01_converge_pol.sh
(check it and adapt it to your cluster). Since this will take a few minutes, save time by submitting it straight away and we'll have a look at it while it runs:
You can monitor that the job is running by the squeue command
and also by checking the files created in your folder
Finally you can monitor how runs are proceeding by looking into the log files
Let's now have a look into the job we just submitted.
First, we defined the double loop and we intialize a summary file for each iteration of the outer loop by printing a header to it. The input file i01-GW
is used as a template for every calculation in the loops, so we assign it to a variable.
Inside the loops, we generate some useful labels which will come in handy to distinguish between runs. Then, we pass the variables from the loops to the sed
command, in order to generate new files in an automated way - sed
replaces any matching string with whatever is provided by the loop variable. Next, we run yambo
using the labels to specify different job -J
and communications -C
directories every time. Finally, we get the quasiparticle energies with grep
commands as shown before and append a new line to the summary file. So, inside each loop, we have
Finally, let us plot this data. First, check that the job has finished with
and verify that the energies were extracted correctly by inspecting the summary files. We need to load a python module first, and then plot:
The plot will produce a fig-01.png
file.
You can copy and open it in your local machine with something like
[Run this on another terminal in your local machine, fixing $USER, $LOGIN and $TUTORIALPATH]
For the purpose of the tutorial, we will choose 80 bands and 10 Ry as our converged parameters and move on. An error within 10 meV is usually acceptable. To retain the chosen variables, we'll make a copy of the corresponding input file:
We will now proceed to converge the number of bands for the correlation part of the self-energy, i.e., GbndRnge
. This step is actually simpler, since it only involves one loop. This is coded in the provided script run02_converge_Gbnds.noBG.sh
. You can look into it
and go ahead and submit it.
[OPTIONAL]: Use the terminator to accelerate convergence
While that runs, we'll have a look at the so-called Bruneval-Gonze (BG) terminator, which is a method to accelerate convergence with respect to empty bands. The variable that controls this for the bands in the correlation self-energy is GTermKind
. This is currently set to "none" in i02-GW
, so create a new input file i02-GW_BG
and set this variable to "BG". We can do this in the command line by simply typing
Note that XTermKind
also offers the same terminator for the sum over bands of the polarization function (we just chose not to use it in the previous section of this excercise, and we'll keep it as "none"). Now, copy the last submission script and edit it to run the same convergence test using the BG terminator.
Try and do this yourself first, and then continue reading to check your understanding.
You'll have to change the input file template, i.e., use i02-GW_BG
where the terminator has been activated. Modify also the name of the newly generated input files in order to avoid overwriting. Change the name of the summary file for the same reason and, finally, modify the communications and job directories of yambo
. Make sure you've done all the changes as outlined below.
Now submit your newly edited script
While this runs, check if the previous job has finished, i.e., you should have a complete summary_02_noBG.txt
file by now.
For a visual result, proceed to plot them with
You should get
You can copy and open it in your local machine with something like
[Run this on another terminal in your local machine, fixing $USER, $LOGIN and $TUTORIALPATH]
If you also did the optional step, you can compare summary_02_noBG.txt
with summary_03_BG.txt
once run03_converge_Gbnds.BG.sh
has finished - you'll see the effect of the terminator immediately.
Just open the plot-02.py
script and uncomment the line #list_of_files = ['summary_02_noBG.txt','summary_03_BG.txt']
, then rerun it with python plot-02.py
.
You can see that the terminator does a great job at accelerating convergence, and it allows us to use 60 bands incurring an error of only 3 meV (while the latter would have been larger than 0.1 eV had we not used the terminator).
We'll end the convergence part of the tutorial with an important point about k-points convergence. The latter is the most cumbersome and computationally intensive among the various convergence tests, and it involves re-running the DFT step. For this reason (and for this reason only) it was ignored in this tutorial. However, it absolutely cannot be overlooked since it is crucial for the accuracy of the calculated GW corrections. You can read about -points convergence in GW and, importantly, a very efficient workaround for 2D systems in a recent publication (here). MoS was one of the materials studied there, and it shows that our result, obtained with a 6x6x1 k-grid, is simply off the chart (blue line).
Guandalini, D’Amico, Ferretti & Varsano, npj Computational Materials 9, 44 (2023)
[OPTIONAL]: Use the RIM-W accelerator
However you can try to get a reasonable correction via the RIM-W approach.
Then, you just need to add the following two variables to the input file
and prepare a submission script
and edit it, by removing the loop and changin the input file and jobname
and then run
How much do you get for the band gap ?
For this section, let us enter the 03_GW_parallel
directory. If you were in the 02_GW_convegence
folder just do
and inspect the input gw.in
. You will see that we set low values for most of the convergence parameters except bands:
Note that we also added FFTGvecs
to reduce the size of the Fourier transforms (the default corresponds to Quantum ESPRESSO ecutwfc
, i.e. 60 Ry in this case).
In addition, we have deleted all the parallel parameters since we will be setting them via the submission script.
Actually we are now dealing with a heavier system than before: as you can see from the QPkrange
values, we have switched to a 12x12x1 -point grid - having 19 points in the irreducible Brillouin zone - and turned spin-orbit coupling on in the DFT calculation - now the top valence band is number 26 instead of 13 because the bands are spin-polarized.
For this part of the tutorial, we will be using the slurm
submission script job_parallel.sh
, which is available in the calculation directory.
If you inspect it, you will see that the script adds additional variables to the yambo input file.
These variables control the parallel execution of the code:
The keyword DIP
refers to the calculations of the screening matrix elements (also called "dipoles") needed for the screening function, X
is the screening function itself (it stands for since it is a response function), SE
the self-energy.
These three sections of the code can be parallelised independently.
We are running on GPUs. In particular, each node hosts for GPU cards. Yambo is coded in such a way that each MPI task is run on a single card, therefore ntasks=ngpu
.
We start by calculating the QP corrections using 4 MPI tasks / GPUs. We leave the number of openMP threads at 8, the optimized value for Yambo on Leonardo. Therefore, edit the submission script as:
and submit the job
This will create a new input file and run it. The calculation databases and the human-readable files will be put in separate directories. Check the location of the report r-*
file and the log l-*
files, and inspect them while the calculation runs.
For simplicity you could just type
to monitor the progress in the master thread (Ctrl+C
to exit).
As you can see, the run takes some time, even though we are using minimal parameters.
Meanwhile, we can run other jobs increasing the parallelisation. Let's employ 16 MPI tasks / GPUs (i.e., 4 nodes on Leonardo). To this end modify the job_parallel.sh
script changing
This time the code should be much faster. Once the run is over, try to run the simulation also on 8 MPI tasks by changing nodes
appropriately. Finally, you can try to produce a scaling plot.
The timings are contained in the r-*
report files. You can already have a look at them typing
The python script parse_ytiming.py
is useful for the post-processing of report files. You can already find it in the directory, together with the reports for the longer calculations with 1 and 2 MPI tasks which have been provided.
If you didn't do so already, load the python module
Then, after your jobs have finished, run the script as
to look for a report file in each run_MPI*.out
folder. Make sure you have only one report file per folder.
You can also play with the script to make it print detailed timing information, however you should already see that it produced a png plot showing times-to-completion on y axis against number of MPI tasks (i.e., GPUs in this case) on the x axis.
What can we learn from this plot? In particular, try to answer the following questions:
Keep in mind that the MPI scaling we are seeing here is not the true yambo scaling, but depends on the small size of our tutorial system. In a realistic calculation for a large-sized system, yambo has been shown to scale well up to tens of thousands of MPI tasks!
We have run the same calculation using a version of Yambo compiled in order to run on CPUs. This is not the preferred approach in an accelerator-based machine like Leonardo, but it can be instructive.
For a CPU calculation, we can use a hybrid parallel structure with threads. The OPENMP threads are controlled by modifying cpus-per-task
and OMP_NUM_THREADS
in the submission file. The product of the number of OpenMP threads and MPI tasks is equal to the total number of CPUs.
We have adopted two strategies. First, run 4 MPI tasks per node like in the GPU case, while adding also 8 OPENMP threads (ntasks*nthreads=ncpu=4*8=32
).
Second, run 32 MPI tasks per node with no multiple threads (ntasks*nthreads=ncpu=32*1=32
).
For example, in the first case we have:
while in the second case we have:
Actually, we don't need to change the related openMP variables for the yambo input, since the value 0
means "use the value of OMP_NUM_THREADS
" and we have now set this environment variable to our liking via the submission script.
Otherwise, any positive number can directly specify the number of threads to be used in each section of the code.
You can try to run these calculations and compare the timings with the previous GPU-based runs.
FIGURE AND EXPLANATION
Up to now we always parallelised over a single parameter, i.e. c
or qp
. However, Yambo allows for tuning the parallelisation scheme over several parameters broadly corresponding to "loops" (i.e., summations or discrete integrations) in the code.
To this end you can open again the run_parallel.sh
script and modify the section where the yambo input variables are set.
For example, X_CPU
sets how the MPI Tasks are distributed in the calculation of the response function. The possibilities are shown in the X_ROLEs
. The same holds for SE_CPU
and SE_ROLEs
which control how MPI Tasks are distributed in the calculation of the self-energy.
You can try different parallelization schemes and check the performances of Yambo. In doing so, you should also change the jobname label=MPI${ncpu}_OMP${nthreads}
in the run_parallel.sh
script to avoid confusion with previous calculations.
You may then check how speed, memory and load balance between the CPUs are affected. You could modify the script parse_ytiming.py
to parse the new data, read and distinguish between more file names, new parallelisation options, etc.
X_CPU
and SE_CPU
) times the number of threads should always match the total number of cores (unless you want to overload the cores taking advantage of multi-threads).c v b
).This is the final section of the tutorial, in which we want to compute the full correction to the band structure of single-layer MoS2.
This is a massive calculation, so run it right now and we'll discuss it in the meantime:
In order to get somewhat realistic results, we will use the larger values for the convergence parameters we have identified in the convergence section. In addition, we also increased the vacuum separation (to 30 au) and the k-point mesh (to 18x18x1) in the DFT calculation, and of course we consider spin-orbit coupling.
Now we have a heavier calculation, and we have to do it not just for the band gap, but the entire band structure which includes 37 kpoints in the irreducible Brillouin zone, two spin-orbit-split valence bands, and two spin-orbit-split conduction bands. Let us check the new input:
After about 6 minutes the calculation should be over and the results collected in folder GW_bnds
. The quasiparticle corrections are stored in human-readable form in the file o-GW_bnds.QP
, and in netCDF format in the quasiparticle database ndb.QP
.
In order to visualize the results in the form of a GW band structure, we will first interpolate the calculated points - recall that we have just 37 points, few of which lie on high-symmetry lines - with ypp
, the yambo pre- and post-processing executable.
We also have a python-based interface for advanced treatment of all the Yambo databases, called Yambopy. You can check it out on the yambo wiki.
Let us enter a computing node interactively
and load the yambo module:
We can review the options with ypp -h
and generate an input file for band structure interpolation with
Let us modify the resulting input file by selecting the 'boltztrap' approach to interpolation, the last two valence and first two conduction bands, and a path in the Brillouin zone along the the points -M-K-. We also set 100 points for each high-symmetry line.
Now, let's run ypp:
This run will produce the file o.bands_interpolated
. You can inspect it and see that it contains a plottable band structure, but beware: these are the DFT eigevalues! We didn't tell ypp
where to look for the quasiparticle corrections, so it went into the SAVE
folder and interpolated the DFT data.
Let's rename the output:
In order to interpolate the quasiparticle database, we append its location to the ypp
input:
add this line at the end
and run ypp
again.
When it's done, let's rename the new output as
Now we are ready to visualize the band structures. In order to do so, you can use the script plt_bands.py
that should be already available in the directory.
We load the python module
and run the script as
Now we can also exit the computing node
The python script should have produced a GW_bands.png
file containing the following visualization.
You can copy and open it in your local machine using scp
.
You may compare this plot with a converged result from this paper (also done with Yambo):
Dashed lines: DFT, thick lines: GW.
As you can see, the general result is not too bad, but there are some differences both at the DFT and GW levels. The magnitude of the band gap is too large, and the relative energy of the two conduction band minima is not correct. One obvious issue is the lack of convergence of our tutorial calculations. As we know, we should include more vacuum space and many, many more -points. Additionally, this is a transition metal dichalcogenide: for this class of systems, the details of the band structure can strongly depend on small variations in the lattice parameters and on the type of pseudopotential used. A great deal of care must be taken when performing these calculations!
In order to learn more about Yambo, we suggest visiting the Yambo website. For technical information and tutorials, you can check ou the Yambo wiki. If you have issues and questions about installing and running the code, you can write them on the Yambo forum.
Yambo
GW calculations
HPC
tutorial