Ising coupling.py

From Werner KRAUTH

Jump to: navigation, search

Contents

Context

This page is part of my 2024 Beg Rohu Lectures on "The second Markov chain revolution" at the Summer School "Concepts and Methods of Statistical Physics" (3 - 15 June 2024).

The present program illustrates the coupling and the phenomenon of monotone coupling in Markov-chain sampling in the example of the two-dimensional Ising model on an LxL square lattice with periodic boundary conditions. We start, at time t=0 with two configurations, one called SLow (all spins equal to -1) and another one, called SHigh (all spins equal to +1), and runs the same Markov chain based on the heat-bath algorithm on both of them until the resulting configurations coincide.

Python program

import math
import random
 
L = 64; N = L * L
nbr = {i : ((i // L) * L + (i + 1) % L, (i + L) % N,
             (i // L) * L + (i - 1) % L, (i - L) % N) \
                                    for i in range(N)}
beta = 0.4  #  beta = 0.4407 is critical temperature
SLow = [-1 for site in range(N)]
SHigh = [1 for site in range(N)]
iter = 0
while True:
    iter += 1
    k = random.randint(0, N - 1)
    Upsilon = random.uniform(0.0, 1.0)
    hLow = sum(SLow[nn] for nn in nbr[k])
    hHigh = sum(SHigh[nn] for nn in nbr[k])
    SLow[k] = -1
    if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * hLow)):
        SLow[k] = 1
    SHigh[k] = -1
    if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * hHigh)):
        SHigh[k] = 1
    if SHigh == SLow:
        print(iter / N)
        print(SLow, SHigh)
        break

Output of the above program (mean coupling time / (N^3 logN)

 N t_coup / N^3 / log N
 8 1.2698
16 1.1993
32 1.1190
64 1.1028

Further information

This program can easily be adapted to the coupling-from-the-past approach to Markov-chain sampling introduced by Propp and Wilson in 1996, and then it allows one to obtain direct samples of the Boltzmann distribution. It uses the concept of monotone coupling. When SLow and SHigh have coupled, ALL 2^N configurations have coupled also. This algorithm is also explained in Chapter 5 of my book (see below)

References

  • Propp J., Wilson D., Random Struct. Algorithms 9, 223 (1996)
  • Krauth, W., Statistical Mechanics: Algorithms and Computations (Oxford University Press, 2006) (Chapter 5)
Personal tools