# Local Metropolis and Cluster algorithm for the Ising model

Homework 08: Local Metropolis and Cluster algorithm for the Ising model

# Introduction

In this exercise, we study the local Metropolis algorithm and the Cluster algorithm for the two-dimensional Ising model.

# A- Local algorithm

Implement the local Metropolis algorithm, as seen during the lecture:
def square_neighbors(L):
N = L*L
site_dic = {}
x_y_dic = {}
for j in range(N):
row = j//L
column = j-row*L
site_dic[(row,column)] = j
x_y_dic[j] = (row,column)
nbr=[]
for j in range(N):
row,column = x_y_dic[j]
right_nbr = site_dic[row,(column+1)%L]
up_nbr = site_dic[(row+1)%L,column]
left_nbr = site_dic[row,(column-1+L)%L]
down_nbr = site_dic[(row-1+L)%L,column]
nbr.append((right_nbr,up_nbr,left_nbr,down_nbr))
nbr = tuple(nbr)
return nbr,site_dic,x_y_dic
L=32
N=L*L
S=[choice([-1,1]) for k in range(N)]
beta=0.42
nbr,site_dic,x_y_dic=square_neighbors(L)
for i_sweep in range(100):
for iter in range(N):
k=randint(0,N-1)
h=sum(S[nbr[k][j]] for j in range(4))
Delta_E=2.*h*S[k]
Upsilon=exp(-beta*Delta_E)
if ran(0.,1.) < Upsilon: S[k] = -S[k]
1. Change two lines in this algorithm so as to compute the internal energy and the specific heat (see SMAC p. 235).
2. Check the implementation of this algorithm in the 6x6 lattice with periodic boundary conditions (compare with SMAC Table 5.3 page 236, which was obtained using exact enumerations): compare (on a graphics) your numerical evaluations of the internal energy and the specific heat to that provided in the table. Comment on the convergence in time. For a some well-chosen values of the temperatures (i.e. far and around Tc), determine the error of your evaluation using the bunching algorithm, and comment.

# B- Cluster algorithm

Implement the Wolff cluster algorithm as seen during the lecture:
L=32
N=L*L
S=[choice([-1,1]) for k in range(N)]
beta=
p=1 - exp(-2*beta)
nbr,site_dic,x_y_dic=square_neighbors(L)
for iter in range(100):
k=randint(0,N-1)
Pocket = [k]
Cluster = [k]
N_cluster = 1
while Pocket != []:
k =choice(Pocket)
for l in nbr[k]:
if S[l] == S[k] and l not in Cluster and ran(0,1) < p:
N_cluster += 1
Pocket.append(l)
Cluster.append(l)
Pocket.remove(k)
for k in Cluster: S[k] = - S[k]
print iter, N_cluster
1. For large lattices, such as 32x32, determine numerically the mean cluster size flipped at each step of this algorithm as a function of temperature. Comment, especially, considering temperatures (i) well below the critical temperature, (ii) around the the critical temperature and (iii) well above the critical temperature. Explain the observed behaviour.

# C- Comparison between local and cluster algorithm

Consider as an observable the mean value of the absolute magnetization

$\displaystyle |M|=|\sum_i\sigma_i|$

1. Using the bunching algorithm (and displaying your results on a graphics), determine the error on the measure of this observable for the two algorithms at the inverse temperatures β = 0.2 and β = 0.4. (Try 14 bunching iterations for β = 0.2 and 16 bunching iterations for β = 0.4).
2. Comment (in view of the critical slowing down).