Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Variational Monte Carlo for Ground State Energy

Hello! Welcome back to our study of numerical methods in quantum mechanics.

In our last lesson, we mastered the Metropolis-Hastings algorithm, a powerful technique for sampling from complex, high-dimensional classical probability distributions like the Boltzmann distribution for the Ising model. You learned how to construct a "smart" random walk that explores the state space according to a target probability, and you understood the core principles of detailed balance, acceptance rates, and burn-in.

Today, we will apply this powerful sampling machinery directly to a quantum problem. We'll combine the variational principle—a concept you're already familiar with from your coursework—with the Monte Carlo methods we just learned. This fusion creates one of the workhorse algorithms of computational many-body physics: Variational Monte Carlo (VMC).

Your learning outcome is to apply Variational Monte Carlo to calculate the ground state energy of a simple quantum system. By the end of this lesson, you will understand the VMC algorithm and be able to implement it to find a variational estimate for the ground state energy.

1. The Variational Principle Meets Monte Carlo

Let's begin with the familiar variational principle. For any trial wavefunction , where represents the coordinates of all particles in the system, the expectation value of the Hamiltonian provides an upper bound to the true ground state energy :

When we write this out as an integral over the -dimensional configuration space, it becomes:

As we discussed in the last lesson, evaluating such multi-dimensional integrals with standard grid-based methods is impossible for more than a few particles due to the curse of dimensionality. This is where Monte Carlo integration becomes essential.

The key insight of VMC is to reinterpret this integral as the expectation value of a quantity called the local energy, , over a specific probability distribution.

First, let's define the local energy:

The local energy is the result of applying the Hamiltonian to the trial wavefunction at a single point in configuration space, , divided by the value of the wavefunction at that point.

Now, we can rewrite the energy expectation value:

where we've defined the probability distribution function (PDF) as .

This final expression, , is exactly what we need. It tells us that the variational energy is simply the average of the local energy, sampled from the probability distribution defined by the square of our trial wavefunction, .

And how do we sample from a complicated distribution like ? With the Metropolis algorithm we learned in the last lesson!

5. Variational Monte Carlo methods

The following text, 'Variational Monte Carlo methods', provides an excellent and concise summary of this theoretical foundation. It formally connects the variational principle to the Monte Carlo framework.

Please read the section 'Quantum Monte Carlo Motivation'. Focus on understanding the definitions of the local energy and how the problem of calculating the ground state energy is transformed into computing the expectation value of this local energy.

2. The Variational Monte Carlo Algorithm

We can now lay out the complete VMC algorithm. Suppose we have a trial wavefunction that depends on a set of variational parameters . Our goal is to find the parameters that minimize the energy .

For a fixed set of parameters , the VMC procedure is:

  1. Initialization: Place the particles (our "walkers") at some initial random configuration .

  2. Markov Chain Generation: Use the Metropolis algorithm to generate a sequence of configurations that are sampled from the distribution .

    • For each step , propose a move from to a new configuration (e.g., by randomly displacing one particle).
    • Calculate the Metropolis acceptance ratio: .
    • Accept the move with probability . If rejected, the next state in the chain is just .
  3. Local Energy Calculation: For each configuration in the chain (after an initial burn-in period), calculate the local energy . The Hamiltonian is typically , so the local energy is:

    Note that the potential energy is usually simple to calculate. The kinetic energy term requires calculating the Laplacian of the trial wavefunction, which must be derived analytically beforehand.

  4. Energy Estimation: The variational energy is estimated as the average of the local energies over the generated samples:

    The statistical error of this estimate scales as , where is the standard deviation of the local energy values.

  5. Optimization: Repeat steps 2-4 for different values of the parameters to find the minimum energy.

Python Code for Variational Monte Carlo Setup
An example of the core Python functions for a VMC simulation of a 1D harmonic oscillator. You can see the definitions for the trial wavefunction (`psi_trial`) and the local energy (`local_energy`), which includes the analytically derived kinetic energy term and the potential energy.

A powerful feature of VMC is related to the variance of the local energy. If our trial wavefunction happens to be the exact ground state eigenfunction , then . In this case, the local energy is constant everywhere:

This means the variance of the local energy, , will be zero. A smaller variance generally indicates a better trial wavefunction. Therefore, a common strategy is to optimize by minimizing not just the energy, but a combination of the energy and its variance.

Test your understanding!

You are performing a VMC calculation for the 1D simple harmonic oscillator (). You choose the trial wavefunction . The exact ground state wavefunction has this form with .

What do you expect will happen to the list of local energies you calculate during your Monte Carlo run as your variational parameter gets very close to ?

Show answer

As approaches , your trial wavefunction gets closer to the true ground state eigenfunction. Consequently, the local energy will become nearly constant for all positions . The list of local energies calculated at each step of your Monte Carlo walk will show very little fluctuation, and their standard deviation (and variance) will approach zero. This "zero variance principle" is a unique and powerful feature of VMC.

3. Implementation: VMC for the Hydrogen Molecule

Now for the practical part. Your background in Python and Numpy makes you well-equipped to build a VMC simulation. We will follow a guided tutorial to calculate the ground state energy of a simple diatomic molecule: H₂.

The system consists of two protons (which we'll fix in space) and two electrons. Our configuration vector is . The Hamiltonian in atomic units () for protons fixed at positions and is:

We will use a very simple (and frankly, not very accurate, but good for learning) trial wavefunction that ignores electron correlation:

This function has one variational parameter, .

In this tutorial, we will write a variational Monte Carlo code ...

The following resource provides a step-by-step guide to writing a VMC code in Python to solve this exact problem. We will work through its main sections to build our simulation.

This is a hands-on coding task. Follow the tutorial to build your VMC program. Read 'Trial Wave functions for a hydrogen molecule' and 'Building the WaveFunction'. Implement the psi function in Python and verify it with the provided test case. Read 'Building a Monte Carlo Code'. Implement the main VMC loop that proposes moves and uses the Metropolis criterion to accept/reject them. Initially, just compute the acceptance ratio and check it against the expected value. Read 'Computing the local energy'. This is the most physics-intensive step. You need to analytically derive the expression for the local energy for our given Hamiltonian and trial wavefunction. Then, implement the LocalEnergy function and verify it with its test case. Integrate the pieces. Add the local energy calculation to your main VMC loop, as described in the paragraph starting 'Now add the calculation of the local energy...'. Collect a list of energies and compute their mean and standard error.

This implementation will give you a working VMC code. To make it more robust and extensible—essential for tackling the many-body problems you're interested in—it's good practice to use an object-oriented approach. The tutorial also discusses an important optimization called importance sampling, which modifies the proposal step of the Metropolis algorithm to achieve much higher acceptance rates.

In this tutorial, we will write a variational Monte Carlo code ...

To see how to structure your code more effectively and how to improve the sampling efficiency, continue with the same tutorial.

Read the sections 'Classes all around' and 'A better acceptance ratio'. You don't need to re-implement everything right now, but focus on understanding: How a class can encapsulate the wavefunction and its parameters (alpha, ion positions). The concept of the 'quantum force' (F(R) = abla \Psi / \Psi) and how it's used to bias the random walk towards regions of higher probability, improving efficiency. This connects to the Metropolis-Hastings algorithm (asymmetric proposal) from our last lesson.

The concept of using the "quantum force" for importance sampling is a standard technique in advanced QMC methods, connecting the random walk to a drift-diffusion process described by the Langevin equation. The text 5. Variational Monte Carlo methods (resource LINK) provides a deeper theoretical treatment of this in its section on 'Importance sampling' if you wish to explore it further.

Conclusion

Congratulations! You have now bridged the gap between the variational principle, a cornerstone of quantum theory, and the powerful Monte Carlo methods from computational science.

Key Takeaways:

  • Variational Monte Carlo (VMC) transforms the problem of finding the ground state energy into a statistical sampling problem.
  • The method relies on calculating the local energy at configurations sampled from the probability distribution .
  • The Metropolis algorithm is the engine used to generate the configurations that correctly sample the distribution.
  • The quality of a trial wavefunction can be judged not only by the resulting energy but also by the variance of the local energy, which is zero for an exact eigenstate.
  • Implementing VMC involves a blend of analytical work (deriving the local energy) and programming (implementing the Metropolis sampler and statistical averaging).

Preview of the Next Lesson:

While VMC is powerful, its accuracy is fundamentally limited by the quality of the trial wavefunction you choose. How do we deal with systems where we don't have a good guess for ? In the next lesson, we will explore Diffusion Monte Carlo (DMC), a more advanced QMC method that can, in principle, find the exact ground state energy, stochastically evolving an ensemble of walkers in imaginary time to project out the ground state component. VMC often serves as the crucial first step for initializing a DMC simulation.

Can't find a good explanation? Sign up and we'll make it for you

Sign up