From 8df8ddbf26bbff83c062bf52bcf2a46517a65985 Mon Sep 17 00:00:00 2001 From: scemama Date: Tue, 2 Feb 2021 12:31:24 +0000 Subject: [PATCH] deploy: e697ff2da46ce2431d6b748784a6cbda51f37756 --- index.html | 410 +++++++++++++++++++++++++++++------------------------ 1 file changed, 222 insertions(+), 188 deletions(-) diff --git a/index.html b/index.html index 70dcd21..5012b44 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,152 +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 +496,7 @@ starting from an approximate wave function.

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

@@ -514,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 @@ -598,8 +598,8 @@ energy computed over these configurations:

-
-

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 @@ -628,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. @@ -656,8 +656,8 @@ to catch the error.

-
-

2.1.1 Exercise 1

+
+

2.1.1 Exercise 1

@@ -679,7 +679,8 @@ and returns the potential. Python

-
import numpy as np
+
#!/usr/bin/env python3
+import numpy as np
 
 def potential(r):
     # TODO
@@ -701,14 +702,15 @@ and returns the potential.
 
-
-
2.1.1.1 Solution   solution
+
+
2.1.1.1 Solution   solution

Python

-
import numpy as np
+
#!/usr/bin/env python3
+import numpy as np
 
 def potential(r):
     distance = np.sqrt(np.dot(r,r))
@@ -742,8 +744,8 @@ and returns the potential.
 
-
-

2.1.2 Exercise 2

+
+

2.1.2 Exercise 2

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

-
-
2.1.2.1 Solution   solution
+
+
2.1.2.1 Solution   solution

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

-
-

2.1.3 Exercise 3

+
+

2.1.3 Exercise 3

@@ -827,7 +829,7 @@ We differentiate \(\Psi\) with respect to \(x\):

-\[\Psi(\mathbf{r}) = \exp(-a\,|\mathbf{r}|) \] +\[ \Psi(\mathbf{r}) = \exp(-a\,|\mathbf{r}|) \] \[\frac{\partial \Psi}{\partial x} = \frac{\partial \Psi}{\partial |\mathbf{r}|} \frac{\partial |\mathbf{r}|}{\partial x} = - \frac{a\,x}{|\mathbf{r}|} \Psi(\mathbf{r}) \] @@ -888,8 +890,8 @@ Therefore, the local kinetic energy is

-
-
2.1.3.1 Solution   solution
+
+
2.1.3.1 Solution   solution

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

-
-

2.1.4 Exercise 4

+
+

2.1.4 Exercise 4

@@ -990,8 +992,8 @@ are calling is yours.

-
-
2.1.4.1 Solution   solution
+
+
2.1.4.1 Solution   solution

Python @@ -1022,8 +1024,8 @@ are calling is yours.

-
-

2.1.5 Exercise 5

+
+

2.1.5 Exercise 5

@@ -1033,8 +1035,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} - @@ -1054,8 +1056,8 @@ 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 program you will write in this section will be written in @@ -1068,7 +1070,9 @@ It will use the functions previously defined. In Python, you should put at the beginning of the file

-
from hydrogen import e_loc
+
#!/usr/bin/env python3
+
+from hydrogen import e_loc
 

@@ -1084,8 +1088,8 @@ In Fortran, you will need to compile all the source files together:

-
-

2.2.1 Exercise

+
+

2.2.1 Exercise

@@ -1111,7 +1115,9 @@ choose a grid which does not contain the origin to avoid numerical issues. Python

-
import numpy as np
+
#!/usr/bin/env python3
+
+import numpy as np
 import matplotlib.pyplot as plt
 
 from hydrogen import e_loc
@@ -1177,14 +1183,16 @@ 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

-
import numpy as np
+
#!/usr/bin/env python3
+
+import numpy as np
 import matplotlib.pyplot as plt
 
 from hydrogen import e_loc
@@ -1253,8 +1261,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\) @@ -1267,7 +1275,7 @@ multiplied by the volume element:

\[ \langle E \rangle_{\Psi^2} \approx \frac{\sum_i w_i E_L(\mathbf{r}_i)}{\sum_i w_i}, \;\; - w_i = \left[\Psi(\mathbf{r}_i)\right]^2 \delta \mathbf{r} + w_i = \left|\Psi(\mathbf{r}_i)\right|^2 \delta \mathbf{r} \]

@@ -1284,8 +1292,8 @@ The energy is biased because:
-
-

2.3.1 Exercise

+
+

2.3.1 Exercise

@@ -1300,7 +1308,9 @@ Compute a numerical estimate of the energy using a grid of Python

-
import numpy as np
+
#!/usr/bin/env python3
+
+import numpy as np
 from hydrogen import e_loc, psi
 
 interval = np.linspace(-5,5,num=50)
@@ -1354,14 +1364,16 @@ To compile the Fortran and run it:
 
-
-
2.3.1.1 Solution   solution
+
+
2.3.1.1 Solution   solution

Python

-
import numpy as np
+
#!/usr/bin/env python3
+
+import numpy as np
 from hydrogen import e_loc, psi
 
 interval = np.linspace(-5,5,num=50)
@@ -1470,8 +1482,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\) @@ -1498,8 +1510,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)

@@ -1510,8 +1522,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} @@ -1530,8 +1542,8 @@ Prove that :

-
-

2.4.2 Exercise

+
+

2.4.2 Exercise

@@ -1547,7 +1559,9 @@ a grid of \(50\times50\times50\) points in the range \((-5,-5,-5) \le Python

-
import numpy as np from hydrogen import e_loc, psi
+
#!/usr/bin/env python3
+
+import numpy as np from hydrogen import e_loc, psi
 
 interval = np.linspace(-5,5,num=50)
 
@@ -1605,14 +1619,16 @@ To compile and run:
 
-
-
2.4.2.1 Solution   solution
+
+
2.4.2.1 Solution   solution

Python

-
import numpy as np
+
#!/usr/bin/env python3
+
+import numpy as np
 from hydrogen import e_loc, psi
 
 interval = np.linspace(-5,5,num=50)
@@ -1743,8 +1759,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 @@ -1754,14 +1770,14 @@ on a grid, it is usually more efficient to use Monte Carlo sampling.

-Moreover, Monte Carlo sampling will alow us to remove the bias due +Moreover, Monte Carlo sampling will allow us to remove the bias due to the discretization of space, and compute a statistical confidence 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\) @@ -1801,8 +1817,8 @@ And the confidence interval is given by

-
-

3.1.1 Exercise

+
+

3.1.1 Exercise

@@ -1816,7 +1832,9 @@ input array. Python

-
from math import sqrt
+
#!/usr/bin/env python3
+
+from math import sqrt
 def ave_error(arr):
     #TODO
     return (average, error)
@@ -1840,14 +1858,16 @@ input array.
 
-
-
3.1.1.1 Solution   solution
+
+
3.1.1.1 Solution   solution

Python

-
from math import sqrt
+
#!/usr/bin/env python3
+
+from math import sqrt
 def ave_error(arr):
     M = len(arr)
     assert(M>0)
@@ -1900,8 +1920,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 @@ -1943,9 +1963,9 @@ One Monte Carlo run will consist of \(N_{\rm MC}\) Monte Carlo iterations. At ev

  • Draw a random point \(\mathbf{r}_i\) in the box \((-5,-5,-5) \le (x,y,z) \le (5,5,5)\)
  • -
  • Compute \([\Psi(\mathbf{r}_i)]^2\) and accumulate the result in a +
  • Compute \(|\Psi(\mathbf{r}_i)|^2\) and accumulate the result in a variable normalization
  • -
  • Compute \([\Psi(\mathbf{r}_i)]^2 \times E_L(\mathbf{r}_i)\), and accumulate the +
  • Compute \(|\Psi(\mathbf{r}_i)|^2 \times E_L(\mathbf{r}_i)\), and accumulate the result in a variable energy
@@ -1962,8 +1982,8 @@ compute the statistical error.

-
-

3.2.1 Exercise

+
+

3.2.1 Exercise

-
-
3.2.1.1 Solution   solution
+
+
3.2.1.1 Solution   solution

Python

-
from hydrogen  import *
+
#!/usr/bin/env python3
+
+from hydrogen  import *
 from qmc_stats import *
 
 def MonteCarlo(a, nmax):
@@ -2178,8 +2202,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 @@ -2270,7 +2294,7 @@ The algorithm is summarized as follows:

  1. Compute \(\Psi\) at a new position \(\mathbf{r'} = \mathbf{r}_n + \delta L\, \mathbf{u}\)
  2. -
  3. Compute the ratio \(A = \frac{\left[\Psi(\mathbf{r'})\right]^2}{\left[\Psi(\mathbf{r}_{n})\right]^2}\)
  4. +
  5. Compute the ratio \(A = \frac{\left|\Psi(\mathbf{r'})\right|^2}{\left|\Psi(\mathbf{r}_{n})\right|^2}\)
  6. Draw a uniform random number \(v \in [0,1]\)
  7. if \(v \le A\), accept the move : set \(\mathbf{r}_{n+1} = \mathbf{r'}\)
  8. else, reject the move : set \(\mathbf{r}_{n+1} = \mathbf{r}_n\)
  9. @@ -2318,8 +2342,8 @@ the same variable later on to store a time step.
-
-

3.3.1 Exercise

+
+

3.3.1 Exercise

@@ -2342,7 +2366,9 @@ Can you observe a reduction in the statistical error? Python

-
from hydrogen  import *
+
#!/usr/bin/env python3
+
+from hydrogen  import *
 from qmc_stats import *
 
 def MonteCarlo(a,nmax,dt):
@@ -2426,14 +2452,16 @@ Can you observe a reduction in the statistical error?
 
-
-
3.3.1.1 Solution   solution
+
+
3.3.1.1 Solution   solution

Python

-
from hydrogen  import *
+
#!/usr/bin/env python3
+
+from hydrogen  import *
 from qmc_stats import *
 
 def MonteCarlo(a,nmax,dt):
@@ -2572,8 +2600,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 @@ -2636,8 +2664,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. @@ -2764,8 +2792,8 @@ Evaluate \(\Psi\) and \(\frac{\nabla \Psi(\mathbf{r})}{\Psi(\mathbf{r})}\) at th

-
-

3.5.1 Exercise 1

+
+

3.5.1 Exercise 1

@@ -2799,8 +2827,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 @@ -2833,8 +2861,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

@@ -2848,7 +2876,9 @@ Modify the previous program to introduce the drift-diffusion scheme. Python

-
from hydrogen  import *
+
#!/usr/bin/env python3
+
+from hydrogen  import *
 from qmc_stats import *
 
 def MonteCarlo(a,nmax,dt):
@@ -2928,14 +2958,16 @@ Modify the previous program to introduce the drift-diffusion scheme.
 
-
-
3.5.2.1 Solution   solution
+
+
3.5.2.1 Solution   solution

Python

-
from hydrogen  import *
+
#!/usr/bin/env python3
+
+from hydrogen  import *
 from qmc_stats import *
 
 def MonteCarlo(a,nmax,dt):
@@ -3115,12 +3147,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: @@ -3188,8 +3220,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 @@ -3286,8 +3318,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 @@ -3383,8 +3415,8 @@ energies computed with the trial wave function.

-
-

4.3.1 Appendix : Details of the Derivation

+
+

4.3.1 Appendix : Details of the Derivation

\[ @@ -3445,8 +3477,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 @@ -3527,13 +3559,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

@@ -3632,14 +3664,16 @@ energy of H for any value of \(a\).

-
-
4.5.1.1 Solution   solution
+
+
4.5.1.1 Solution   solution

Python

-
from hydrogen  import *
+
#!/usr/bin/env python3
+
+from hydrogen  import *
 from qmc_stats import *
 
 def MonteCarlo(a, nmax, dt, tau, Eref):
@@ -3849,8 +3883,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 @@ -3871,8 +3905,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
  • @@ -3886,8 +3920,8 @@ the H\(_2\) molecule at $R$=1.4010 bohr. Answer: 0.17406 a.u.
-
-

6 Schedule

+
+

6 Schedule

@@ -3926,8 +3960,8 @@ the H\(_2\) molecule at $R$=1.4010 bohr. Answer: 0.17406 a.u. - - + +
  <2021-02-04 Thu 14:00>–<2021-02-04 Thu 14:10>3.1
@@ -3936,7 +3970,7 @@ the H\(_2\) molecule at $R$=1.4010 bohr. Answer: 0.17406 a.u.

Author: Anthony Scemama, Claudia Filippi

-

Created: 2021-02-02 Tue 10:29

+

Created: 2021-02-02 Tue 12:31

Validate