From 3e927385a6d7d4c2023525efeed083c15900b9f9 Mon Sep 17 00:00:00 2001 From: filippi-claudia Date: Sat, 30 Jan 2021 21:41:41 +0000 Subject: [PATCH] deploy: 76adcbddf2442bab84d7cf22d3c77227d4715620 --- index.html | 544 ++++++++++++++++++++++++++++------------------------- 1 file changed, 286 insertions(+), 258 deletions(-) diff --git a/index.html b/index.html index 1efa19b..0e74cac 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,148 +329,147 @@ 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 @@ -508,12 +507,88 @@ is defined everywhere, continuous, and infinitely differentiable. All the quantities are expressed in atomic units (energies, coordinates, etc).

-
-
-
-

2 Numerical evaluation of the energy

-
+

+** Energy and local energy +

+ +

+For a given system with Hamiltonian \(\hat{H}\) and wave function \(\Psi\), we define the local energy as +

+ +

+\[ + E_L(\mathbf{r}) = \frac{\hat{H} \Psi(\mathbf{r})}{\Psi(\mathbf{r})}, + \] +

+ +

+where \(\mathbf{r}\) denotes the 3N-dimensional electronic coordinates. +

+ +

+The electronic energy of a system, \(E\), can be rewritten in terms of the +local energy \(E_L(\mathbf{r})\) as +

+ +\begin{eqnarray*} +E & = & \frac{\langle \Psi| \hat{H} | \Psi\rangle}{\langle \Psi |\Psi \rangle} + = \frac{\int \Psi(\mathbf{r})\, \hat{H} \Psi(\mathbf{r})\, d\mathbf{r}}{\int \left[\Psi(\mathbf{r}) \right]^2 d\mathbf{r}} \\ + & = & \frac{\int \left[\Psi(\mathbf{r})\right]^2\, \frac{\hat{H} \Psi(\mathbf{r})}{\Psi(\mathbf{r})}\,d\mathbf{r}}{\int \left[\Psi(\mathbf{r}) \right]^2 d\mathbf{r}} + = \frac{\int \left[\Psi(\mathbf{r})\right]^2\, E_L(\mathbf{r})\,d\mathbf{r}}{\int \left[\Psi(\mathbf{r}) \right]^2 d\mathbf{r}} +\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\). +

+ +

+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, \] +

+ +

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

+ +

+\[ \int_{-\infty}^\infty p(x)\,dx = 1. \] +

+ +

+Similarly, we can view the the energy of a system, \(E\), as the expected value of the local energy with respect to +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}\,, \] +

+ +

+where the probability density is given by the square of the wave function: +

+ +

+\[ p(\mathbf{r}) = \frac{|Psi(\mathbf{r}|^2){\int \left |\Psi(\mathbf{r})|^2 d\mathbf{r}}\,. \] +

+ +

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

+ +

+$$ E ≈ \frac{1}{M} ∑i=1M EL(\mathbf{r}i} \,. +

+ +
    +
  • Numerical evaluation of the energy of the hydrogen atoms
  • +
+

In this section, we consider the hydrogen atom with the following wave function: @@ -540,62 +615,15 @@ eigenfunction of the Hamiltonian To do that, we will compute the local energy, defined as

-

-\[ - E_L(\mathbf{r}) = \frac{\hat{H} \Psi(\mathbf{r})}{\Psi(\mathbf{r})}, - \] -

and check whether it is constant.

- -

-In general, the electronic energy of a system, \(E\), can be rewritten as the expectation value of the -local energy \(E(\mathbf{r})\) with respect to the 3N-dimensional -electron density given by the square of the wave function: -

- -\begin{eqnarray*} -E & = & \frac{\langle \Psi| \hat{H} | \Psi\rangle}{\langle \Psi |\Psi \rangle} - = \frac{\int \Psi(\mathbf{r})\, \hat{H} \Psi(\mathbf{r})\, d\mathbf{r}}{\int \left[\Psi(\mathbf{r}) \right]^2 d\mathbf{r}} \\ - & = & \frac{\int \left[\Psi(\mathbf{r})\right]^2\, \frac{\hat{H} \Psi(\mathbf{r})}{\Psi(\mathbf{r})}\,d\mathbf{r}}{\int \left[\Psi(\mathbf{r}) \right]^2 d\mathbf{r}} - = \frac{\int \left[\Psi(\mathbf{r})\right]^2\, E_L(\mathbf{r})\,d\mathbf{r}}{\int \left[\Psi(\mathbf{r}) \right]^2 d\mathbf{r}} - = \langle E_L \rangle_{\Psi^2}\,, -\end{eqnarray*} -

-where \(\mathbf{r}\) is the vector of the 3N-dimensional electronic coordinates (\(N=1\) for the hydrogen atom). -

- -

-For a small number of dimensions, one can compute \(E\) by evaluating the integrals on a grid. However, -

- -

-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, \] -

- -

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

- -

-\[ \int_{-\infty}^\infty p(x)\,dx = 1. \] -

- - - -
-

2.1 Local energy

-
+
+

1.1 Local energy

+

Write all the functions of this section in a single file : hydrogen.py if you use Python, or hydrogen.f90 is you use @@ -617,9 +645,9 @@ to catch the error.

-
-

2.1.1 Exercise 1

-
+
+

1.1.1 Exercise 1

+

Write a function which computes the potential at \(\mathbf{r}\). @@ -662,9 +690,9 @@ and returns the potential.

-
-
2.1.1.1 Solution   solution
-
+
+
1.1.1.1 Solution   solution
+

Python

@@ -703,9 +731,9 @@ and returns the potential.
-
-

2.1.2 Exercise 2

-
+
+

1.1.2 Exercise 2

+

Write a function which computes the wave function at \(\mathbf{r}\). @@ -739,9 +767,9 @@ input arguments, and returns a scalar.

-
-
2.1.2.1 Solution   solution
-
+
+
1.1.2.1 Solution   solution
+

Python

@@ -767,9 +795,9 @@ input arguments, and returns a scalar.
-
-

2.1.3 Exercise 3

-
+
+

1.1.3 Exercise 3

+

Write a function which computes the local kinetic energy at \(\mathbf{r}\). @@ -849,9 +877,9 @@ So the local kinetic energy is

-
-
2.1.3.1 Solution   solution
-
+
+
1.1.3.1 Solution   solution
+

Python

@@ -891,9 +919,9 @@ So the local kinetic energy is
-
-

2.1.4 Exercise 4

-
+
+

1.1.4 Exercise 4

+

Write a function which computes the local energy at \(\mathbf{r}\), @@ -935,9 +963,9 @@ local kinetic energy.

-
-
2.1.4.1 Solution   solution
-
+
+
1.1.4.1 Solution   solution
+

Python

@@ -966,9 +994,9 @@ local kinetic energy.
-
-

2.1.5 Exercise 5

-
+
+

1.1.5 Exercise 5

+

Find the theoretical value of \(a\) for which \(\Psi\) is an eigenfunction of \(\hat{H}\). @@ -977,9 +1005,9 @@ Find the theoretical value of \(a\) for which \(\Psi\) is an eigenfunction of \(

-
-
2.1.5.1 Solution   solution
-
+
+
1.1.5.1 Solution   solution
+
\begin{eqnarray*} E &=& \frac{\hat{H} \Psi}{\Psi} = - \frac{1}{2} \frac{\Delta \Psi}{\Psi} - \frac{1}{|\mathbf{r}|} \\ @@ -998,9 +1026,9 @@ equal to -0.5 atomic units.
-
-

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

-
+
+

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

+

The potential and the kinetic energy both diverge at \(r=0\), so we @@ -1010,9 +1038,9 @@ choose a grid which does not contain the origin.

-
-

2.2.1 Exercise

-
+
+

1.2.1 Exercise

+

For multiple values of \(a\) (0.1, 0.2, 0.5, 1., 1.5, 2.), plot the @@ -1094,9 +1122,9 @@ plot './data' index 0 using 1:2 with lines title 'a=0.1', \

-
-
2.2.1.1 Solution   solution
-
+
+
1.2.1.1 Solution   solution
+

Python

@@ -1170,9 +1198,9 @@ plt.savefig("plot_py.png")
-
-

2.3 Numerical estimation of the energy

-
+
+

1.3 Numerical estimation of the energy

+

If the space is discretized in small volume elements \(\mathbf{r}_i\) of size \(\delta \mathbf{r}\), the expression of \(\langle E_L \rangle_{\Psi^2}\) @@ -1201,9 +1229,9 @@ The energy is biased because:

-
-

2.3.1 Exercise

-
+
+

1.3.1 Exercise

+

Compute a numerical estimate of the energy in a grid of @@ -1271,9 +1299,9 @@ To compile the Fortran and run it:

-
-
2.3.1.1 Solution   solution
-
+
+
1.3.1.1 Solution   solution
+

Python

@@ -1387,9 +1415,9 @@ a = 2.0000000000000000 E = -8.0869806678448772E-002
-
-

2.4 Variance of the local energy

-
+
+

1.4 Variance of the local energy

+

The variance of the local energy is a functional of \(\Psi\) which measures the magnitude of the fluctuations of the local @@ -1415,9 +1443,9 @@ energy can be used as a measure of the quality of a wave function.

-
-

2.4.1 Exercise (optional)

-
+
+

1.4.1 Exercise (optional)

+

Prove that : @@ -1427,9 +1455,9 @@ Prove that :

-
-
2.4.1.1 Solution   solution
-
+
+
1.4.1.1 Solution   solution
+

\(\bar{E} = \langle E \rangle\) is a constant, so \(\langle \bar{E} \rangle = \bar{E}\) . @@ -1447,9 +1475,9 @@ Prove that :

-
-

2.4.2 Exercise

-
+
+

1.4.2 Exercise

+

Add the calculation of the variance to the previous code, and @@ -1522,9 +1550,9 @@ To compile and run:

-
-
2.4.2.1 Solution   solution
-
+
+
1.4.2.1 Solution   solution
+

Python

@@ -1660,9 +1688,9 @@ a = 2.0000000000000000 E = -8.0869806678448772E-002 s2 = 1.8068814
-
-

3 Variational Monte Carlo

-
+
+

2 Variational Monte Carlo

+

Numerical integration with deterministic methods is very efficient in low dimensions. When the number of dimensions becomes large, @@ -1677,9 +1705,9 @@ interval.

-
-

3.1 Computation of the statistical error

-
+
+

2.1 Computation of the statistical error

+

To compute the statistical error, you need to perform \(M\) independent Monte Carlo calculations. You will obtain \(M\) different @@ -1718,9 +1746,9 @@ And the confidence interval is given by

-
-

3.1.1 Exercise

-
+
+

2.1.1 Exercise

+

Write a function returning the average and statistical error of an @@ -1757,9 +1785,9 @@ input array.

-
-
3.1.1.1 Solution   solution
-
+
+
2.1.1.1 Solution   solution
+

Python

@@ -1817,9 +1845,9 @@ input array.
-
-

3.2 Uniform sampling in the box

-
+
+

2.2 Uniform sampling in the box

+

We will now do our first Monte Carlo calculation to compute the energy of the hydrogen atom. @@ -1852,9 +1880,9 @@ compute the statistical error.

-
-

3.2.1 Exercise

-
+
+

2.2.1 Exercise

+

Parameterize the wave function with \(a=0.9\). Perform 30 @@ -1953,9 +1981,9 @@ well as the index of the current step.

-
-
3.2.1.1 Solution   solution
-
+
+
2.2.1.1 Solution   solution
+

Python

@@ -2068,9 +2096,9 @@ E = -0.49518773675598715 +/- 5.2391494923686175E-004
-
-

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

-
+
+

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

+

We will now use the square of the wave function to sample random points distributed with the probability density @@ -2157,9 +2185,9 @@ step such that the acceptance rate is close to 0.5 is a good compromise.

-
-

3.3.1 Exercise

-
+
+

2.3.1 Exercise

+

Modify the program of the previous section to compute the energy, @@ -2265,9 +2293,9 @@ Can you observe a reduction in the statistical error?

-
-
3.3.1.1 Solution   solution
-
+
+
2.3.1.1 Solution   solution
+

Python

@@ -2411,9 +2439,9 @@ A = 0.51695266666666673 +/- 4.0445505648997396E-004
-
-

3.4 Gaussian random number generator

-
+
+

2.4 Gaussian random number generator

+

To obtain Gaussian-distributed random numbers, you can apply the Box Muller transform to uniform random numbers: @@ -2474,9 +2502,9 @@ In Python, you can use the -

3.5 Generalized Metropolis algorithm

-
+
+

2.5 Generalized Metropolis algorithm

+

One can use more efficient numerical schemes to move the electrons, but the Metropolis accepation step has to be adapted accordingly: @@ -2574,9 +2602,9 @@ The transition probability becomes:

-
-

3.5.1 Exercise 1

-
+
+

2.5.1 Exercise 1

+

Write a function to compute the drift vector \(\frac{\nabla \Psi(\mathbf{r})}{\Psi(\mathbf{r})}\). @@ -2609,9 +2637,9 @@ Write a function to compute the drift vector \(\frac{\nabla \Psi(\mathbf{r})}{\P

-
-
3.5.1.1 Solution   solution
-
+
+
2.5.1.1 Solution   solution
+

Python

@@ -2643,9 +2671,9 @@ Write a function to compute the drift vector \(\frac{\nabla \Psi(\mathbf{r})}{\P
-
-

3.5.2 Exercise 2

-
+
+

2.5.2 Exercise 2

+

Modify the previous program to introduce the drifted diffusion scheme. @@ -2738,9 +2766,9 @@ Modify the previous program to introduce the drifted diffusion scheme.

-
-
3.5.2.1 Solution   solution
-
+
+
2.5.2.1 Solution   solution
+

Python

@@ -2925,13 +2953,13 @@ A = 0.78839866666666658 +/- 3.2503783452043152E-004
-
-

4 Diffusion Monte Carlo   solution

-
+
+

3 Diffusion Monte Carlo   solution

+
-
-

4.1 Schrödinger equation in imaginary time

-
+
+

3.1 Schrödinger equation in imaginary time

+

Consider the time-dependent Schrödinger equation:

@@ -2989,9 +3017,9 @@ system.
-
-

4.2 Diffusion and branching

-
+
+

3.2 Diffusion and branching

+

The diffusion equation of particles is given by

@@ -3044,9 +3072,9 @@ the combination of a diffusion process and a branching process.
-
-

4.3 Importance sampling

-
+
+

3.3 Importance sampling

+

In a molecular system, the potential is far from being constant, and diverges at inter-particle coalescence points. Hence, when the @@ -3102,9 +3130,9 @@ error known as the fixed node error.

-
-

4.3.1 Appendix : Details of the Derivation

-
+
+

3.3.1 Appendix : Details of the Derivation

+

\[ -\frac{\partial \psi(\mathbf{r},\tau)}{\partial \tau} \Psi_T(\mathbf{r}) = @@ -3165,9 +3193,9 @@ Defining \(\Pi(\mathbf{r},t) = \psi(\mathbf{r},\tau)

-
-

4.4 Fixed-node DMC energy

-
+
+

3.4 Fixed-node DMC energy

+

Now that we have a process to sample \(\Pi(\mathbf{r},\tau) = \psi(\mathbf{r},\tau) \Psi_T(\mathbf{r})\), we can compute the exact @@ -3218,9 +3246,9 @@ energies computed with the trial wave function.

-
-

4.5 Pure Diffusion Monte Carlo (PDMC)

-
+
+

3.5 Pure Diffusion Monte Carlo (PDMC)

+

Instead of having a variable number of particles to simulate the branching process, one can choose to sample \([\Psi_T(\mathbf{r})]^2\) instead of @@ -3271,14 +3299,14 @@ code, so this is what we will do in the next section.

-
-

4.6 Hydrogen atom

-
+
+

3.6 Hydrogen atom

+
-
-

4.6.1 Exercise

-
+
+

3.6.1 Exercise

+

Modify the Metropolis VMC program to introduce the PDMC weight. @@ -3376,9 +3404,9 @@ energy of H for any value of \(a\).

-
-
4.6.1.1 Solution   solution
-
+
+
3.6.1.1 Solution   solution
+

Python

@@ -3593,9 +3621,9 @@ A = 0.98788066666666663 +/- 7.2889356133441110E-005
-
-

4.7 TODO H2

-
+
+

3.7 TODO H2

+

We will now consider the H2 molecule in a minimal basis composed of the \(1s\) orbitals of the hydrogen atoms: @@ -3615,9 +3643,9 @@ the nuclei.

-
-

5 TODO [0/3] Last things to do

-
+
+

4 TODO [0/3] Last things to do

+
  • [ ] Give some hints of how much time is required for each section
  • [ ] Prepare 4 questions for the exam: multiple-choice questions @@ -3632,7 +3660,7 @@ the H\(_2\) molecule at $R$=1.4010 bohr. Answer: 0.17406 a.u.

Author: Anthony Scemama, Claudia Filippi

-

Created: 2021-01-30 Sat 12:21

+

Created: 2021-01-30 Sat 21:41

Validate