From 52c44000317215a5d3bf5df5d23443adfbfd57cd Mon Sep 17 00:00:00 2001 From: scemama Date: Tue, 2 Feb 2021 10:29:35 +0000 Subject: [PATCH] deploy: e8bf999e258bde25b111bc0ca4790cc2774c08c5 --- index.html | 446 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 272 insertions(+), 174 deletions(-) diff --git a/index.html b/index.html index 8fd3089..70dcd21 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Quantum Monte Carlo @@ -329,151 +329,152 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 Introduction

+
+

1 Introduction

This website contains the QMC tutorial of the 2021 LTTC winter school @@ -496,7 +497,7 @@ starting from an approximate wave function.

Code examples will be given in Python and Fortran. You can use -whatever language you prefer to write the program. +whatever language you prefer to write the programs.

@@ -513,8 +514,8 @@ coordinates, etc).

-
-

1.1 Energy and local energy

+
+

1.1 Energy and local energy

For a given system with Hamiltonian \(\hat{H}\) and wave function \(\Psi\), we define the local energy as @@ -543,20 +544,23 @@ E & = & \frac{\langle \Psi| \hat{H} | \Psi\rangle}{\langle \Psi |\Psi \rangle} \end{eqnarray*}

-For few dimensions, one can easily compute \(E\) by evaluating the integrals on a grid but, for a high number of dimensions, one can resort to Monte Carlo techniques to compute \(E\). +For few dimensions, one can easily compute \(E\) by evaluating the +integrals on a grid but, for a high number of dimensions, one can +resort to Monte Carlo techniques to compute \(E\).

-To this aim, recall that the probabilistic expected value of an arbitrary function \(f(x)\) -with respect to a probability density function \(P(x)\) is given by +To this aim, recall that the probabilistic expected value of an +arbitrary function \(f(x)\) with respect to a probability density +function \(P(x)\) is given by

-\[ \langle f \rangle_p = \int_{-\infty}^\infty P(x)\, f(x)\,dx, \] +\[ \langle f \rangle_P = \int_{-\infty}^\infty P(x)\, f(x)\,dx, \]

-where a probability density function \(p(x)\) is non-negative +where a probability density function \(P(x)\) is non-negative and integrates to one:

@@ -570,7 +574,7 @@ a probability density \(P(\mathbf{r})\) defined in 3\(N\) dimensions:

-\[ E = \int E_L(\mathbf{r}) P(\mathbf{r})\,d\mathbf{r} \equiv \langle E_L \rangle_{\Psi^2}\,, \] +\[ E = \int E_L(\mathbf{r}) P(\mathbf{r})\,d\mathbf{r} \equiv \langle E_L \rangle_{P}\,, \]

@@ -582,7 +586,9 @@ where the probability density is given by the square of the wave function:

-If we can sample \(N_{\rm MC}\) configurations \(\{\mathbf{r}\}\) distributed as \(p\), we can estimate \(E\) as the average of the local energy computed over these configurations: +If we can sample \(N_{\rm MC}\) configurations \(\{\mathbf{r}\}\) +distributed as \(P\), we can estimate \(E\) as the average of the local +energy computed over these configurations:

@@ -592,8 +598,8 @@ If we can sample \(N_{\rm MC}\) configurations \(\{\mathbf{r}\}\) distributed as

-
-

2 Numerical evaluation of the energy of the hydrogen atom

+
+

2 Numerical evaluation of the energy of the hydrogen atom

In this section, we consider the hydrogen atom with the following @@ -622,8 +628,8 @@ To do that, we will compute the local energy and check whether it is constant.

-
-

2.1 Local energy

+
+

2.1 Local energy

You will now program all quantities needed to compute the local energy of the H atom for the given wave function. @@ -650,13 +656,13 @@ to catch the error.

-
-

2.1.1 Exercise 1

+
+

2.1.1 Exercise 1

Write a function which computes the potential at \(\mathbf{r}\). -The function accepts a 3-dimensional vector r as input arguments +The function accepts a 3-dimensional vector r as input argument and returns the potential.

@@ -695,8 +701,8 @@ and returns the potential.
-
-
2.1.1.1 Solution   solution
+
+
2.1.1.1 Solution   solution

Python @@ -736,8 +742,8 @@ and returns the potential.

-
-

2.1.2 Exercise 2

+
+

2.1.2 Exercise 2

@@ -772,8 +778,8 @@ input arguments, and returns a scalar.

-
-
2.1.2.1 Solution   solution
+
+
2.1.2.1 Solution   solution

Python @@ -800,8 +806,8 @@ input arguments, and returns a scalar.

-
-

2.1.3 Exercise 3

+
+

2.1.3 Exercise 3

@@ -813,7 +819,7 @@ local kinetic energy.

-The local kinetic energy is defined as \[-\frac{1}{2}\frac{\Delta \Psi}{\Psi}.\] +The local kinetic energy is defined as \[T_L(\mathbf{r}) = -\frac{1}{2}\frac{\Delta \Psi(\mathbf{r})}{\Psi(\mathbf{r})}.\]

@@ -854,7 +860,7 @@ applied to the wave function gives:

Therefore, the local kinetic energy is \[ - -\frac{1}{2} \frac{\Delta \Psi}{\Psi} (\mathbf{r}) = -\frac{1}{2}\left(a^2 - \frac{2a}{\mathbf{|r|}} \right) + T_L (\mathbf{r}) = -\frac{1}{2}\left(a^2 - \frac{2a}{\mathbf{|r|}} \right) \]

@@ -882,8 +888,8 @@ Therefore, the local kinetic energy is
-
-
2.1.3.1 Solution   solution
+
+
2.1.3.1 Solution   solution

Python @@ -924,8 +930,8 @@ Therefore, the local kinetic energy is

-
-

2.1.4 Exercise 4

+
+

2.1.4 Exercise 4

@@ -956,11 +962,27 @@ local kinetic energy.

Fortran

+ +
+

+When you call a function in Fortran, you need to declare its +return type. +You might by accident choose a function name which is the +same as an internal function of Fortran. So it is recommended to +always use the keyword external to make sure the function you +are calling is yours. +

+ +
+
double precision function e_loc(a,r)
   implicit none
   double precision, intent(in) :: a, r(3)
 
+  double precision, external :: kinetic
+  double precision, external :: potential
+
   ! TODO
 
 end function e_loc
@@ -968,8 +990,8 @@ local kinetic energy.
 
-
-
2.1.4.1 Solution   solution
+
+
2.1.4.1 Solution   solution

Python @@ -988,7 +1010,8 @@ local kinetic energy. implicit none double precision, intent(in) :: a, r(3) - double precision, external :: kinetic, potential + double precision, external :: kinetic + double precision, external :: potential e_loc = kinetic(a,r) + potential(r) @@ -999,8 +1022,8 @@ local kinetic energy.

-
-

2.1.5 Exercise 5

+
+

2.1.5 Exercise 5

@@ -1010,8 +1033,8 @@ Find the theoretical value of \(a\) for which \(\Psi\) is an eigenfunction of \(

-
-
2.1.5.1 Solution   solution
+
+
2.1.5.1 Solution   solution
\begin{eqnarray*} E &=& \frac{\hat{H} \Psi}{\Psi} = - \frac{1}{2} \frac{\Delta \Psi}{\Psi} - @@ -1031,20 +1054,38 @@ equal to -0.5 atomic units.
-
-

2.2 Plot of the local energy along the \(x\) axis

+
+

2.2 Plot of the local energy along the \(x\) axis

-

-The potential and the kinetic energy both diverge at \(r=0\), so we -choose a grid which does not contain the origin. +The program you will write in this section will be written in +another file (plot_hydrogen.py or plot_hydrogen.f90 for +example). +It will use the functions previously defined.

+

+In Python, you should put at the beginning of the file +

+
+
from hydrogen import e_loc
+
+
+

+to be able to use the e_loc function of the hydrogen.py file. +

+ +

+In Fortran, you will need to compile all the source files together: +

+
+
gfortran hydrogen.f90 plot_hydrogen.f90 -o plot_hydrogen
+
-
-

2.2.1 Exercise

+
+

2.2.1 Exercise

@@ -1052,7 +1093,16 @@ For multiple values of \(a\) (0.1, 0.2, 0.5, 1., 1.5, 2.), plot the local energy along the \(x\) axis. In Python, you can use matplotlib for example. In Fortran, it is convenient to write in a text file the values of \(x\) and \(E_L(\mathbf{r})\) for each point, and use -Gnuplot to plot the files. +Gnuplot to plot the files. With Gnuplot, you will need 2 blank +lines to separate the data corresponding to different values of \(a\). +

+ +
+ +
+

+The potential and the kinetic energy both diverge at \(r=0\), so we +choose a grid which does not contain the origin to avoid numerical issues.

@@ -1127,8 +1177,8 @@ plot './data' index 0 using 1:2 with lines title 'a=0.1', \
-
-
2.2.1.1 Solution   solution
+
+
2.2.1.1 Solution   solution

Python @@ -1203,8 +1253,8 @@ plt.savefig("plot_py.png")

-
-

2.3 Numerical estimation of the energy

+
+

2.3 Numerical estimation of the energy

If the space is discretized in small volume elements \(\mathbf{r}_i\) @@ -1234,8 +1284,8 @@ The energy is biased because:

-
-

2.3.1 Exercise

+
+

2.3.1 Exercise

@@ -1304,8 +1354,8 @@ To compile the Fortran and run it:

-
-
2.3.1.1 Solution   solution
+
+
2.3.1.1 Solution   solution

Python @@ -1420,8 +1470,8 @@ a = 2.0000000000000000 E = -8.0869806678448772E-002

-
-

2.4 Variance of the local energy

+
+

2.4 Variance of the local energy

The variance of the local energy is a functional of \(\Psi\) @@ -1448,8 +1498,8 @@ energy can be used as a measure of the quality of a wave function.

-
-

2.4.1 Exercise (optional)

+
+

2.4.1 Exercise (optional)

@@ -1460,8 +1510,8 @@ Prove that :

-
-
2.4.1.1 Solution   solution
+
+
2.4.1.1 Solution   solution

\(\bar{E} = \langle E \rangle\) is a constant, so \(\langle \bar{E} @@ -1480,8 +1530,8 @@ Prove that :

-
-

2.4.2 Exercise

+
+

2.4.2 Exercise

@@ -1555,8 +1605,8 @@ To compile and run:

-
-
2.4.2.1 Solution   solution
+
+
2.4.2.1 Solution   solution

Python @@ -1693,8 +1743,8 @@ a = 2.0000000000000000 E = -8.0869806678448772E-002 s2 = 1.8068814

-
-

3 Variational Monte Carlo

+
+

3 Variational Monte Carlo

Numerical integration with deterministic methods is very efficient @@ -1710,8 +1760,8 @@ interval.

-
-

3.1 Computation of the statistical error

+
+

3.1 Computation of the statistical error

To compute the statistical error, you need to perform \(M\) @@ -1751,8 +1801,8 @@ And the confidence interval is given by

-
-

3.1.1 Exercise

+
+

3.1.1 Exercise

@@ -1790,8 +1840,8 @@ input array.

-
-
3.1.1.1 Solution   solution
+
+
3.1.1.1 Solution   solution

Python @@ -1850,8 +1900,8 @@ input array.

-
-

3.2 Uniform sampling in the box

+
+

3.2 Uniform sampling in the box

We will now perform our first Monte Carlo calculation to compute the @@ -1912,8 +1962,8 @@ compute the statistical error.

-
-

3.2.1 Exercise

+
+

3.2.1 Exercise

@@ -2013,8 +2063,8 @@ well as the index of the current step.

-
-
3.2.1.1 Solution   solution
+
+
3.2.1.1 Solution   solution

Python @@ -2128,8 +2178,8 @@ E = -0.49518773675598715 +/- 5.2391494923686175E-004

-
-

3.3 Metropolis sampling with \(\Psi^2\)

+
+

3.3 Metropolis sampling with \(\Psi^2\)

We will now use the square of the wave function to sample random @@ -2268,8 +2318,8 @@ the same variable later on to store a time step.

-
-

3.3.1 Exercise

+
+

3.3.1 Exercise

@@ -2376,8 +2426,8 @@ Can you observe a reduction in the statistical error?

-
-
3.3.1.1 Solution   solution
+
+
3.3.1.1 Solution   solution

Python @@ -2522,8 +2572,8 @@ A = 0.51695266666666673 +/- 4.0445505648997396E-004

-
-

3.4 Gaussian random number generator

+
+

3.4 Gaussian random number generator

To obtain Gaussian-distributed random numbers, you can apply the @@ -2586,8 +2636,8 @@ In Python, you can use the -

3.5 Generalized Metropolis algorithm

+
+

3.5 Generalized Metropolis algorithm

One can use more efficient numerical schemes to move the electrons by choosing a smarter expression for the transition probability. @@ -2714,8 +2764,8 @@ Evaluate \(\Psi\) and \(\frac{\nabla \Psi(\mathbf{r})}{\Psi(\mathbf{r})}\) at th

-
-

3.5.1 Exercise 1

+
+

3.5.1 Exercise 1

@@ -2749,8 +2799,8 @@ Write a function to compute the drift vector \(\frac{\nabla \Psi(\mathbf{r})}{\P

-
-
3.5.1.1 Solution   solution
+
+
3.5.1.1 Solution   solution

Python @@ -2783,8 +2833,8 @@ Write a function to compute the drift vector \(\frac{\nabla \Psi(\mathbf{r})}{\P

-
-

3.5.2 Exercise 2

+
+

3.5.2 Exercise 2

@@ -2878,8 +2928,8 @@ Modify the previous program to introduce the drift-diffusion scheme.

-
-
3.5.2.1 Solution   solution
+
+
3.5.2.1 Solution   solution

Python @@ -3065,12 +3115,12 @@ A = 0.78839866666666658 +/- 3.2503783452043152E-004

-
-

4 Diffusion Monte Carlo   solution

+
+

4 Diffusion Monte Carlo   solution

-
-

4.1 Schrödinger equation in imaginary time

+
+

4.1 Schrödinger equation in imaginary time

Consider the time-dependent Schrödinger equation: @@ -3138,8 +3188,8 @@ system.

-
-

4.2 Diffusion and branching

+
+

4.2 Diffusion and branching

The imaginary-time Schrödinger equation can be explicitly written in terms of the kinetic and @@ -3236,8 +3286,8 @@ Therefore, in both cases, you are dealing with a "Bosonic" ground state.

-
-

4.3 Importance sampling

+
+

4.3 Importance sampling

In a molecular system, the potential is far from being constant @@ -3333,8 +3383,8 @@ energies computed with the trial wave function.

-
-

4.3.1 Appendix : Details of the Derivation

+
+

4.3.1 Appendix : Details of the Derivation

\[ @@ -3395,8 +3445,8 @@ Defining \(\Pi(\mathbf{r},t) = \psi(\mathbf{r},\tau)

-
-

4.4 Pure Diffusion Monte Carlo (PDMC)

+
+

4.4 Pure Diffusion Monte Carlo (PDMC)

Instead of having a variable number of particles to simulate the @@ -3477,13 +3527,13 @@ code, so this is what we will do in the next section.

-
-

4.5 Hydrogen atom

+
+

4.5 Hydrogen atom

-
-

4.5.1 Exercise

+
+

4.5.1 Exercise

@@ -3582,8 +3632,8 @@ energy of H for any value of \(a\).

-
-
4.5.1.1 Solution   solution
+
+
4.5.1.1 Solution   solution

Python @@ -3799,8 +3849,8 @@ A = 0.98788066666666663 +/- 7.2889356133441110E-005

-
-

4.6 TODO H2

+
+

4.6 TODO H2

We will now consider the H2 molecule in a minimal basis composed of the @@ -3821,8 +3871,8 @@ the nuclei.

-
-

5 TODO [0/3] Last things to do

+
+

5 TODO [0/3] Last things to do

  • [ ] Give some hints of how much time is required for each section
  • @@ -3835,10 +3885,58 @@ the H\(_2\) molecule at $R$=1.4010 bohr. Answer: 0.17406 a.u.
+ +
+

6 Schedule

+
+ + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<2021-02-04 Thu 09:00>–<2021-02-04 Thu 10:30>Lecture
<2021-02-04 Thu 10:45>–<2021-02-04 Thu 11:10>2.1
<2021-02-04 Thu 11:10>–<2021-02-04 Thu 11:30>2.2
<2021-02-04 Thu 11:30>–<2021-02-04 Thu 12:15>2.3
<2021-02-04 Thu 12:15>–<2021-02-04 Thu 12:30>2.4
  
+
+

Author: Anthony Scemama, Claudia Filippi

-

Created: 2021-02-01 Mon 21:10

+

Created: 2021-02-02 Tue 10:29

Validate