Key Terms
- J - Interaction strength between neighboring spins
- h - External magnetic field strength (h > 0 favors +1 spins, h < 0 favors -1 spins)
- T - Temperature of the system
- s - Spin at site (i, j), either +1 or -1
- s_up, s_down, s_left, s_right - Spins of the four nearest neighbors of (i, j)
- ΔE - Change in energy if a spin is flipped
- N² - Total number of spins in the system (e.g for N=64, the lattice is 64x64 with 4096 total sites)
Metropolis Algorithm
The Metropolis algorithm is a single-spin flip Monte Carlo method that follows the detailed balance condition. It's one of the most widely used algorithms for simulating the Ising model.
Implementation Details:
- Randomly select a spin site (i, j)
- Calculate the energy change ΔE if the spin is flipped
- Accept the flip with probability min(1, e^(-ΔE/T))
- Repeat for N² sites per sweep
ΔE = 2J·s·(s_up + s_down + s_left + s_right) + 2h·s
P_accept = min(1, exp(-ΔE/T))
This algorithm efficiently samples the canonical ensemble and is particularly effective near equilibrium. The acceptance rate decreases at low temperatures but maintains detailed balance.
Glauber Dynamics
The Glauber algorithm is very similar to Metropolis, but uses a different acceptance probability that naturally satisfies detailed balance without requiring the min(1, ...) condition.
Implementation Details:
- Randomly select a spin site (i, j)
- Calculate the energy change ΔE if the spin is flipped
- Accept the flip with probability 1/(1+exp(ΔE/T))
ΔE = 2J·s·(s_up + s_down + s_left + s_right) + 2h·s
P_accept = 1/(1+exp(ΔE/T))
Heat Bath Algorithm
The Heat Bath algorithm works by calculating the local field at site (i, j) from the nearest neighbors of each spin and the external field.
This differs from other methods because we do not calculate ΔE to determine if a spin is flipped,
rather we calculate the probability of it being +1 or -1 based on the local field.
Implementation Details:
- Randomly select a spin site (i, j)
- Calculate the local field at (i, j)
- Set s = +1 with probability P(s = +1)
- If the probability check fails, set s = -1
local_field = J·(s_up + s_down + s_left + s_right) + h
P(s = +1) = 1 / (1 + exp(-2 * local_field / T))
Wolff Cluster Algorithm
The Wolff algorithm is a single cluster update method that can dramatically reduce critical slowing down near phase transitions. It constructs and flips an entire cluster of aligned spins.
This algorithm is rejection-free, meaning that once a cluster is formed, it is always flipped.
Implementation Details:
- If J<0.0, perform a checkerboard gauge transformation
- Randomly select a spin site (i, j)
- Check if the site will be coupled to the ghost spin with probability P = 1 - exp(-2|h|/T)
- Add aligned neighboring sites to the cluster with probability P = 1 - exp(-2|J|/T)
- Set (i, j) to the coordinates of a neighbor that was added to the cluster
- Repeat steps 3-5 until every site in the cluster has been checked, and the cluster stops growing. Each bond should be checked once.
- If any of the sites in the cluster were coupled to the ghost spin, set all sites in the cluster to align with it.
- If no sites in the cluster were coupled to the ghost spin, flip all sites in the cluster.
- If J<0, undo the checkerboard gauge transformation.
P_add = 1 - exp(-2|J|/T) (add a site to the cluster)
P_ghost = 1 - exp(-2|h|/T) (couple a site to the ghost spin)
ghost_spin = 1 if h>=0 else -1
Note for Antiferromagnetism: This algorithm does not work out of the box for antiferromagnetic interactions (J<0).
In order to handle this, we perform a gauge transformation by flipping one color of the checkerboard lattice before applying the Wolff algorithm.
This effectively converts the antiferromagnetic problem into a ferromagnetic one, allowing the cluster algorithm to function correctly.
At the end of every sweep, we flip the sublattice back to restore the original configuration.
Learn more about checkerboard transformations here.
Swendsen-Wang Algorithm
The Swendsen-Wang algorithm is another cluster algorithm that can efficiently update clusters of spins in a single move.
The key difference between the Swendsen-Wang and Wolff algorithms is that Wolff only creates a single cluster which is always flipped with 100% certainty.
Swendsen-Wang instead creates multiple clusters such that every site in the lattice is part of exactly one cluster, and then each cluster is flipped independently with a probability check.
This means that for a lattice of N² sites, we can create anywhere from 1 to N² clusters, and none of them are guaranteed to be flipped.
Implementation Details:
Coming soon!
Note for Antiferromagnetism: This algorithm does not work out of the box for antiferromagnetic interactions (J<0).
In order to handle this, we perform a gauge transformation by flipping one color of the checkerboard lattice before applying the Wolff algorithm.
This effectively converts the antiferromagnetic problem into a ferromagnetic one, allowing the cluster algorithm to function correctly.
At the end of every sweep, we flip the sublattice back to restore the original configuration.
Learn more about checkerboard transformations here.
Kawasaki Dynamics
The Kawasaki algorithm conserves the total magnetization by exchanging spins between neighboring sites rather than flipping individual spins. This is useful for studying systems with conserved quantities.
Implementation Details:
- Randomly select a spin site and one of its nearest neighbors
- Calculate the energy change for swapping these spins
- Accept the swap with Metropolis probability
- This conserves total magnetization while allowing local rearrangements
ΔE = E_after - E_before
P_accept = min(1, exp(-ΔE/T))
Note for ΔE Calculation: Normally when a site is flipped, 4 bonds are affected. In Kawasaki dynamics, since we exchange two spins, 6 bonds are affected (3 for each spin,
the bond connecting the two sites is left unchanged).
This must be accounted for in the ΔE calculation.
Comparison and Usage Guidelines
Performance Characteristics:
- Metropolis/Glauber/Heat Bath: Good general-purpose algorithms, suffer from critical slowing down
- Kawasaki: Essential for conserved magnetization studies, slower convergence
- Wolff/Swendsen-Wang: Excellent near critical points, reduced critical slowing down
When to Use Each Algorithm:
- High Temperature: All algorithms perform similarly; Metropolis is often sufficient
- Near Critical Temperature: Cluster algorithms (Wolff/SW) are strongly recommended
- Low Temperature: Cluster algorithms help overcome energy barriers
- Conserved Quantities: Use Kawasaki for magnetization conservation
- Dynamic Studies: Glauber provides natural connection to physical time scales
Tip: In the simulation, you can switch between algorithms to see how they behave differently, especially near the critical temperature T_c ≈ 2.269 for the 2D Ising model.