Wolff cluster Monte Carlo for the 2D Ising model
Drag the temperature through the critical point below — this is a real Metropolis simulation running in your browser, not a video.
⟨m⟩ = –sweep 0
Near the critical temperature , single-spin Metropolis updates suffer from critical slowing down: the autocorrelation time diverges as with . The Wolff algorithm grows clusters and flips them together, driving close to .
A bond between aligned neighbors is added with probability
def wolff_step(spins, beta, J=1.0):
L = spins.shape[0]
p = 1 - np.exp(-2 * beta * J)
i, j = np.random.randint(L, size=2)
sign = spins[i, j]
stack, cluster = [(i, j)], {(i, j)}
while stack:
x, y = stack.pop()
for dx, dy in ((1,0),(-1,0),(0,1),(0,-1)):
nx, ny = (x+dx) % L, (y+dy) % L
if (nx, ny) not in cluster and spins[nx, ny] == sign \
and np.random.random() < p:
cluster.add((nx, ny)); stack.append((nx, ny))
for (x, y) in cluster:
spins[x, y] = -sign
return spins
The exact critical point for the square lattice is , which the simulation recovers from the peak of the susceptibility.