Please upload one PDF file to Gradescope (Entry code: ME62YG).
For this homework you will implement code (on PrairieLearn) for the Ising model and simulate it in three different ways: Conventional Metropolis Monte Carlo, using the heat-bath algorithm, and a cluster algorithm.
The 2D Ising model studied here will not be in a magnetic field and you will use periodic boundary conditions. In the absence of an external magnetic field, the only interaction in the system is the nearest-neighbor spin interaction. The Hamiltonian is: \[H = -J\sum_{\langle i,j\rangle} s_i \cdot s_j,\] where the summation is taken over all nearest-neighbor spin pairs in the system.
To observe the evolution of the system, you will measure the square of the magnetization per spin: \[M^2 = \left\{\frac{1}{N}\sum_{i=1}^N s_i \right\}^2.\] This quantity measures the amount of magnetic order in the system in a size-independent manner. If all spins are pointing up, then \(M^2\)=1. If every spin points up or down with equal probability, then \(M^2\)=0. Ideally you would study \(M^2\) as a function of the spin-coupling strength \(\beta J\) with \(\beta J\) ranging from 0.0 to 1.0. If your code is fast enough, this is what you should do! Unfortunately, this may not be the case, hence, you are only required to use the following 3 values for each algorithm:
Let’s define a sweep as 1 step of the cluster algorithm or \(N\) steps of the Metropolis or heat bath algorithm, where \(N\) is the total number of spins in the system. For each of these algorithms, you should compute and specify the value after 1000 sweeps of
To help you validate and debug your code, you should check against the result for \(\beta J\)=0.25, which should lead to \(M^2\)=0.0107(1). Remember that this is the square of the magnetization per spin. Also recall the “comparison of data sets” section of HW1 when comparing statistical numbers.
In order to calculate the error, we typically take the standard deviation and divide by the number of effective points. For everything but the conventional metropolis at \(\beta J=0.44096\) you should use this method. For this one point the correlation time might be deceivingly large. Hence, use a different method to calculate the error of this one particular simulation: For each point (for each algorithm), run the simulation 10 times. Then calculate the standard deviation of these ten values. This should give you a more accurate assessment of your error and automatically deal with the auto-correlation time.
For your simulations, you need to initialize your system. Do this with
import numpy
spinsPerSide=20
spins=numpy.ones((spinsPerSide,spinsPerSide)) # fills new array with 1
J=1.0
Currently, the spins on the lattice do not know who their nearest neighbors are. Introduce them to their neighbors by constructing a neighbor list, i.e., for each spin, a list of linear indices of its neighbors. You need to do this only during the construction of the lattice and will not invoke this again during MC. Hence, speed does not matter, only correctness does.
The first method of simulating the Ising model will be using conventional naive Metropolis moves. Remember, the algorithm that we are proposing to do this includes:
Refine your code, so that it can do the heat-bath algorithm.:
Note: This algorithm doesn’t care what the current spin is.
If you’re interested in getting an even better speedup, one way would be this (optional for everyone): Instead of flipping one spin at once, you could flip a whole block of spins at once. Imagine you take a \(3\times 3\) block of spins and use the heat-bath technique to write down all the probabilities for all the different \(2^9\) spin configurations and select one with probability proportional to their likelihood.
You will write code that performs a cluster move that flips a large collection of spins at once. The steps to do this will be the following:
Your overall Monte-Carlo loop needs to include:
Make sure you indicate clearly where you answer each question in your report. Specifically, please enter this information into Gradescope when uploading your report!