Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 74

Metropolis-Hastings for Lattice Scalar Fields

Recommended resources

Hello! Welcome back to our course on Quantum Field Theory.

In our last lesson, we took the crucial first step into non-perturbative QFT by reformulating scalar field theory on a discrete Euclidean spacetime lattice. We derived the discretized Euclidean action, , and saw that the path integral for the theory becomes a well-defined (though very high-dimensional) integral:

This expression establishes a beautiful equivalence between QFT and 4D classical statistical mechanics, where plays the role of the Boltzmann weight.

Today, we tackle the next logical question: how do we actually compute this integral and the expectation values of observables? Direct integration is computationally intractable. The answer lies in Monte Carlo methods. Our goal for this lesson is to implement a Metropolis-Hastings algorithm to generate field configurations for a lattice scalar field theory according to the Boltzmann distribution. This is the core computational engine of lattice field theory.

1. The Monte Carlo Approach: Importance Sampling

The fundamental idea behind using Monte Carlo methods here is importance sampling. Instead of trying to sample the vast space of all possible field configurations uniformly, we want to generate a sequence of configurations that are already distributed according to the probability measure .

This means that configurations with a small action (large Boltzmann weight) will appear more frequently in our sequence. If we succeed in generating such a sequence, the expectation value of any observable can be approximated by a simple arithmetic mean:

This transforms a difficult integration problem into a much simpler averaging problem. The challenge now becomes: how do we generate this special sequence of configurations? This is where the Metropolis-Hastings algorithm comes in.

Metropolis Algorithm vs. Boltzmann Distribution in an Isothermal Atmosphere
This graph provides an intuitive picture of what we want to achieve. It shows results from a Metropolis simulation (blue histogram) sampling the density of gas molecules at different heights in an atmosphere. The simulation results closely match the theoretical Boltzmann distribution (red dotted line), demonstrating that the algorithm successfully generates a set of states that are representative of the physical probability distribution.

2. The Metropolis-Hastings Algorithm

The Metropolis-Hastings algorithm is a Markov Chain Monte Carlo (MCMC) method. It constructs a Markov chain of states (in our case, field configurations) whose stationary distribution is precisely the target distribution we want to sample.

To build our intuition for how this works, let's watch a video that explains the general algorithm.

Metropolis - Hastings : Data Science Concepts

This video, 'Metropolis - Hastings : Data Science Concepts' by ritvikmath, provides an excellent and clear derivation of the algorithm. It explains how the acceptance probability is constructed to satisfy the 'detailed balance' condition, which is the key to ensuring the algorithm converges to the correct distribution.

Watch the video from the beginning until 13:21. Pay close attention to: The two main steps: proposing a new state and then accepting/rejecting it. The 'detailed balance' condition and how it's used to derive the acceptance probability A. The final, compact form of the acceptance probability: min(1, r_f * r_g). The distinction between the general Metropolis-Hastings (asymmetric proposal g) and the simpler Metropolis algorithm (symmetric proposal g), where the acceptance probability simplifies to min(1, r_f).

Let's summarize the algorithm based on the video, adapting the notation to our physics context. We want to generate a sequence of field configurations . Given a configuration , we generate the next one, , as follows:

  1. Propose: Generate a candidate configuration from a proposal distribution . For lattice field theory, a simple and common choice is a local update:

    • Pick a single lattice site at random.
    • Propose a new field value at that site: , where is a random number drawn from a symmetric interval, e.g., .
    • For all other sites , .
      This proposal is symmetric: the probability of proposing a move from to is the same as from to . This simplifies the algorithm to the "Metropolis" case, as mentioned in the video.
  2. Accept/Reject: Calculate the change in the action, . The acceptance probability is:

    This is exactly the simplified form from the video for a symmetric proposal.

  3. Update: Generate a uniform random number .

    • If , the move is accepted: .
    • If , the move is rejected: . We keep the old configuration in our sequence.

Notice the intuitive nature of this rule:

  • If a proposed change decreases the action (), then , and the acceptance probability is 1. The system always accepts moves to lower-action (more probable) configurations.
  • If a proposed change increases the action (), then . The system might still accept this "uphill" move, but with a probability that is exponentially smaller for larger . This allows the system to escape local minima and explore the entire configuration space, which is essential for correct sampling.
Test your understanding!

In the context of our lattice theory, why is it computationally efficient to propose changes to the field at only one site at a time, rather than changing the entire field configuration at once?

Show answer

The lattice action involves nearest-neighbor interactions. When we change the field at a single site , the change in the total action, , depends only on the field at site and its immediate neighbors. All other terms in the action sum remain unchanged. This means we can calculate very quickly with an O(1) computation, rather than re-summing the entire action over all lattice sites, which would be an O() operation. This local nature makes the algorithm feasible for large lattices.


3. Implementing the Metropolis Algorithm for Theory

Now, let's see how this algorithm is put into practice for the scalar field theory we discretized in the last lesson. Your strong background in Python and creating simulations will be very helpful here. We will study a concrete implementation.

The following resource provides a full Python implementation for a simulation of theory. It builds directly on the concepts from the previous lesson and is a perfect example of today's learning outcome.

7. Lattice field theory — Monte Carlo Techniques

The resource '7. Lattice field theory — Monte Carlo Techniques' contains a complete, well-commented Python code for simulating scalar field theory on a 4D lattice using the Metropolis-Hastings algorithm. This is the heart of today's lesson.

Please read the section 'Scalar field theory on the lattice'. First, review the form of the dimensionless action S_L[φ]. Then, focus on the Python code block. Specifically analyze the functions: scalar_action_diff(phi, site, newphi, lamb, kappa): This function calculates ΔS locally. Try to derive its expression from the lattice action S_L[φ]. scalar_MH_step(phi, lamb, kappa, delta): This is a single step of the algorithm. Map each line of code to the propose-calculate-accept/reject steps we just discussed. run_scalar_MH(...): This function orchestrates the simulation by repeatedly calling the single-step function. Notice the concept of a 'sweep' (a number of updates equal to the number of sites). Since you enjoy writing simulations, think about this code as a blueprint for your own implementation.

Let's break down the key function scalar_MH_step:

def scalar_MH_step(phi, lamb, kappa, delta):
    # 1. Propose a local update
    site = tuple(rng.integers(0,len(phi),4))         # Pick a random 4D site
    newphi = phi[site] + rng.uniform(-delta,delta)   # Propose a new field value

    # 2. Calculate local change in action
    deltaS = scalar_action_diff(phi, site, newphi, lamb, kappa)

    # 3. Accept/Reject step
    if deltaS < 0 or rng.uniform() < np.exp(-deltaS):
        phi[site] = newphi   # Accept: update the configuration
        return True          # Return status (e.g., for acceptance rate)
    return False             # Reject: do nothing

This code is a direct and elegant translation of the Metropolis algorithm. The run_scalar_MH function simply calls this step function repeatedly, forming the Markov chain.


4. Practical Considerations in MCMC Simulations

Running a real simulation involves a few more practical details:

  • Thermalization (or Burn-in): The simulation starts from an arbitrary configuration (e.g., all ). The first several thousand configurations in the chain will not be representative of the true distribution as the system "relaxes" towards equilibrium. These initial configurations must be discarded. In the provided code, this is handled by equil_sweeps.
  • Autocorrelation: By construction, each configuration in the Markov chain is correlated with the previous one. To obtain statistically independent samples for averaging, we should only measure observables every steps (or "sweeps"). This is the measure_sweeps parameter in the code.
  • Tuning the Proposal Step (): The delta parameter, which controls the size of the proposed change, is crucial.
    • If is too small, nearly every move is accepted, but the field configuration changes very slowly. The simulation explores the space inefficiently.
    • If is too large, proposed moves make large jumps in the action, so is large and positive, and most moves are rejected. The simulation gets "stuck".
    • A common rule of thumb is to tune so that the acceptance rate (the fraction of accepted moves) is around 50%. The code in the resource LINK includes a comment to this effect.

Conclusion

Today we have built the engine for our lattice field theory simulations. By understanding and implementing the Metropolis algorithm, we can now generate a statistically representative ensemble of field configurations for a given theory.

Key Takeaways:

  • Lattice path integrals are evaluated using Monte Carlo importance sampling.
  • The Metropolis-Hastings algorithm generates a Markov chain of configurations that converges to the desired Boltzmann distribution .
  • The core of the algorithm consists of a propose-accept/reject cycle, where the acceptance probability satisfies detailed balance.
  • For lattice theories, local updates make the calculation of extremely efficient, enabling simulations on large lattices.
  • Practical simulations must account for thermalization and autocorrelation to produce reliable results.

Preview of the Next Lesson:

We are now equipped to run a simulation and generate valid field configurations. In the next lesson, we will put this to use. We will learn how to compute the two-point correlation function from our generated configurations and extract a physical observable: the mass of the scalar particle. This will be our first calculation of a physical quantity from a non-perturbative QFT simulation.