Classical statistical physics · Ising, XY, Heisenberg and Potts models

Classical Monte Carlo Lab

Thermal averages of a spin system are defined by the sum \(Z=\sum e^{-\beta H}\), which contains exponentially many terms in the number of spins \(N\). Instead of evaluating the sum, Monte Carlo samples configurations with their Boltzmann weight: one builds a Markov chain whose stationary distribution is \(e^{-\beta H}/Z\) and estimates observables by sample averages. On this page you can solve the same model with different algorithms, measure how correlated the samples are and how large the errors are, and locate phase transitions with finite-size scaling.

\[ \begin{aligned} H=&-J\sum_{\langle ij\rangle}\big(S^x_iS^x_j+S^y_iS^y_j+\lambda S^z_iS^z_j\big)\\ &-h\sum_i S^{\parallel}_i-K\sum_i\big(S^z_i\big)^2 \end{aligned} \] \[ H_{\rm Potts}=-J\sum_{\langle ij\rangle}\delta_{\sigma_i\sigma_j}-h\sum_i\delta_{\sigma_i,0} \]

\(\sigma_i\in\{0,\dots,q-1\}\) · \(J=+1\) ferromagnet (FM), \(J=-1\) antiferromagnet (AFM) · Ising: \(S_i=\pm1\) (\(n=1\)); XY: unit vector in the plane (\(n=2\)); Heisenberg: unit vector (\(n=3\)) · \(\lambda\) and \(K\) only for Heisenberg · the field points along \(S\) for Ising, along \(\hat x\) for XY and along \(\hat z\) for Heisenberg · \(k_B=1\), temperature in units of \(J\) · periodic boundaries on all lattices.

SimulationClassical Monte Carlo Lab
2D square · Ising · Metropolis
sweeps0 samples0 e– ⟨|m|⟩– χ– C– U– defects– acceptance– τint |m| · e– independent samples/s– sweeps/s–
Samples
Figure 1. Samples taken after every sweep. Series: order parameter or energy over the last 400 sweeps; the dashed line is the running average. For \(n=1\) models the signed \(m\) is plotted: below \(T_c\) a small system tunnels between \(+m\) and \(-m\). Histogram: \(P(m)\) or \(P(e)\) over the whole measurement; a double peak appears in \(P(m)\) below \(T_c\) and in \(P(e)\) at a first-order transition. Autocorrelation: \(\rho(t)=\langle\delta O_0\,\delta O_t\rangle/\langle\delta O^2\rangle\) and from it \(\tau_{\rm int}=\tfrac12+\sum_{t\ge1}\rho(t)\) (Sokal window, \(W\ge6\tau_{\rm int}\)).
Temperature scan
Figure 2. Points are stored scans (colour = scan; error bars from binary binning and jackknife). The black ring is the measurement of the current run; the dashed curve is the estimate obtained from this run by histogram reweighting, drawn only where the effective number of samples is sufficient. The thin cyan line is the exact result (Onsager for the 2D square Ising model, transfer matrix for 1D models); the vertical dashed line is the literature \(T_c\). For the XY model the slanted line in the \(\Upsilon\) plot is the BKT jump condition \(\Upsilon=2T/\pi\).

Temperature scan

Results appear in Figure 2. Each point starts with thermalization sweeps equal to 20% of the measurement; the scan starts at high T and continues from the state of the previous point. It runs in a separate thread, so the simulation can be used meanwhile.
Visualization

How to read the colours

Ising and Potts

In the Ising model a dark square is \(S=+1\) and a light square is \(S=-1\). In the Potts model every state has its own colour; the colour wheel is divided into \(q\) equal parts. Domain walls are colour boundaries; near \(T_c\) domains of every size appear.

For AFM with "show the order" switched on, every spin is drawn multiplied by its sublattice sign \((-1)^{x+y+z}\): Néel order appears as a single colour and sublattice domains as different colours. Switch it off to see the raw checkerboard pattern.

XY and Heisenberg

The hue is the in-plane angle of the spin: \(\hat x\) red, \(\hat y\) yellow-green, \(-\hat x\) cyan, \(-\hat y\) violet-blue. It is the same wheel as in the spin-wave lab.

For Heisenberg the lightness shows \(S^z\): \(S^z=+1\) tends to white and \(S^z=-1\) to black; in-plane spins are fully saturated. With easy-axis order (\(K>0\) or \(\lambda>1\)) the picture therefore resembles a black-and-white Ising model.

Space-time in the 1D chain

In 1D the horizontal axis is the site and the vertical axis is MC time (one row per sweep, newest row at the bottom). You can see domain walls spread and annihilate in MC time; the correlation length \(\xi\) is the typical domain width.

This is not a physical time evolution: these are steps of the Markov chain. With Metropolis domain walls perform random walks; with cluster algorithms the pattern can change completely within one sweep.

Clusters and vortices

With Wolff the last flipped cluster is tinted orange. With SW, if the corresponding box is checked, every cluster is drawn in a random colour instead of the spins. The clusters are Fortuin–Kasteleyn clusters; at \(T_c\) their sizes span all scales.

In the 2D XY model a filled orange circle is a \(+1\) vortex and an open cyan ring a \(-1\) vortex (the sum of angle differences around a plaquette is \(\pm2\pi\)). Below \(T_{\rm BKT}\) vortices are bound in pairs, above it they are free.

Commands and keyboard shortcuts

The bar right below the picture controls the simulation: play/pause, random or ordered start, resetting the measurement and speed. The temperature scan is in the card below the figures; the "Annealing" and "Numerics" groups in the right panel open when their title is clicked.

Keyboard: Space play/pause · R random · D ordered · M reset measurement · +/− speed · T start/cancel scan · F full page · Esc leave. Shortcuts are inactive while a number box or a list has the focus; the ⌨ button in the bar shows the list.

Method

Sampling the Boltzmann distribution

1 · Importance sampling

Samples instead of a sum

The thermal average of an observable is

\[ \begin{gathered} \langle O\rangle=\frac1Z\sum_{\{\mathbf S\}}O\,e^{-\beta H}\\ \approx\frac1M\sum_{t=1}^{M}O(\mathbf S_t), \end{gathered} \]

where the configurations \(\mathbf S_t\) are drawn with \(P\propto e^{-\beta H}\). Uniform random sampling does not work: the important configurations are an exponentially small fraction of phase space.

The error decreases as \(M^{-1/2}\) independently of the system size, which makes the method powerful for high-dimensional sums. However, \(Z\) itself (and hence the free energy and entropy) is not measured directly.

2 · Markov chain

Detailed balance

If the transition probability \(W\) for \(\mathbf S\to\mathbf S'\) satisfies detailed balance and the chain is ergodic, its stationary distribution is the Boltzmann distribution:

\[ \begin{gathered} P(\mathbf S)\,W(\mathbf S\to\mathbf S')\\ =P(\mathbf S')\,W(\mathbf S'\to\mathbf S). \end{gathered} \]

Metropolis: a change is proposed and accepted with probability \(\min(1,e^{-\beta\Delta E})\). Heat bath: the chosen spin is redrawn directly from the Boltzmann distribution in the local field of its neighbours.

One sweep is \(N\) update attempts. In Metropolis the sites are chosen at random. Strictly sequential Metropolis can get stuck in the wrong distribution in 1D because moves with \(\Delta E=0\) are always accepted; this version uses random site selection.

3 · Thermalization

Forgetting the start

The chain starts from a random or ordered state and reaches equilibrium only after a few \(\tau_{\rm exp}\). Samples from this period are discarded (thermalization). When a parameter changes, the measurement is reset automatically and as many samples as given in the "Thermalization" box are discarded.

A practical test: two runs with the same parameters from a random (hot) and an ordered (cold) start must converge to the same average. At first-order transitions and in frustrated systems this test can fail: the chain stays in a metastable state.

Statistics

Correlated samples and error bars

1 · Autocorrelation

Effective number of samples

Consecutive Markov samples are not independent. The variance of the mean is

\[ \begin{gathered} \sigma^2_{\bar O}=\frac{\sigma_O^2}{M}\,2\tau_{\rm int},\\ \tau_{\rm int}=\frac12+\sum_{t\ge1}\rho_O(t). \end{gathered} \]

\(M\) samples are equivalent to only \(M/2\tau_{\rm int}\) independent ones. \(\tau_{\rm int}\) depends on the observable: \(|m|\) is usually slower than \(e\).

\(\tau_{\rm int}\) in the readout is measured in sweeps. The autocorrelation view in Figure 1 computes the same quantity directly from \(\rho(t)\); agreement between the two estimates is a sign of a reliable measurement.

2 · Binning and jackknife

How the errors are computed

The series is repeatedly averaged in pairs; once the block length exceeds \(\tau_{\rm int}\) the block means become independent and the error reaches a plateau. For nonlinear functions of averages such as \(\chi\), \(C\) and \(U\) the error is obtained from a 32-block jackknife:

\[ \begin{gathered} \chi=N\beta\big(\langle m^2\rangle-\langle|m|\rangle^2\big),\\ C=N\beta^2\big(\langle e^2\rangle-\langle e\rangle^2\big). \end{gathered} \]

If the measurement is shorter than a few hundred \(\tau_{\rm int}\), both \(\tau_{\rm int}\) and the error come out too small. This is common for Metropolis at the critical point; trust the agreement of two independent runs rather than the error bar.

3 · Efficiency

A fair comparison of algorithms

Comparing algorithms by \(\tau_{\rm int}\) per sweep is misleading: a Wolff sweep is more expensive than a Metropolis sweep. The right measure is the number of independent samples per second:

\[ \text{efficiency}=\frac{\text{sweeps/s}}{2\,\tau_{\rm int}}. \]

At the critical point \(\tau\sim L^{z}\): for the 2D Ising model \(z\simeq2.17\) for Metropolis and \(z\lesssim0.3\) for Swendsen–Wang and Wolff. For large \(L\) the difference therefore reaches hundreds. Away from the critical point local algorithms can be more efficient.

Cluster algorithms

Beating critical slowing down

1 · Fortuin–Kasteleyn

Swendsen–Wang

The Ising/Potts partition function can be rewritten with bond variables. Every satisfied bond (equal spins for FM) is activated with probability

\[ \begin{gathered} p=1-e^{-2\beta|J|}\ \ (\text{Ising}),\\ p=1-e^{-\beta J}\ \ (\text{Potts}) \end{gathered} \]

and each cluster connected by active bonds is flipped independently (assigned a random state for Potts). The acceptance probability is 1.

The clusters carry the physical correlations: at \(T_c\) they are at the percolation threshold. Large-scale changes are therefore made in a single step.

2 · Wolff

Single cluster

A single FK cluster is grown from a random seed site and flipped. Because large clusters are chosen more often it is somewhat more efficient than SW. In the disordered phase the mean cluster size equals the susceptibility: \(\langle|C|\rangle=\chi'/\beta\).

A hidden trap: the rule "generate clusters until the number of flipped sites exceeds \(N\), then measure" correlates the measurement with the size of the last cluster and produces a measurable bias. Here the number of clusters per sweep is set during thermalization and then frozen.

3 · Continuous spins

Embedding and overrelaxation

For XY and Heisenberg a random \(\hat r\) is chosen; the reflection \(\mathbf S\to\mathbf S-2(\mathbf S\cdot\hat r)\hat r\) defines an embedded Ising model that flips the sign of \(\hat r\cdot\mathbf S\):

\[ \begin{gathered} p_{ij}=1-e^{-2\beta J\max(0,\,r_ir_j)},\\ r_i=\hat r\cdot\mathbf S_i. \end{gathered} \]

With anisotropy only reflections that leave \(H\) invariant (\(\hat r\in xy\) or \(\hat r=\hat z\)) can be used. They map the \(xy\) plane onto itself, so the chain is not ergodic; a Metropolis sweep is added to every sweep. Overrelaxation reflects the spin about the local field, \(\mathbf S\to2(\mathbf S\cdot\hat{\mathbf H})\hat{\mathbf H}-\mathbf S\); it conserves energy and is cheap, but on its own it is microcanonical.

Phase transitions

Finite-size scaling and the Binder cumulant

1 · Scaling

A finite system has no transition

At finite \(L\) every observable is analytic; singularities are rounded once \(\xi\sim L\). At the critical point

\[ \begin{gathered} \langle|m|\rangle\sim L^{-\beta/\nu},\qquad \chi_{\max}\sim L^{\gamma/\nu},\\ T_c(L)-T_c\sim L^{-1/\nu}. \end{gathered} \]

2D Ising: \(\beta=1/8,\ \gamma=7/4,\ \nu=1\), \(C\) diverges logarithmically. 3D Ising: \(\nu\simeq0.630\), \(\gamma\simeq1.237\). The positions of the \(\chi\) and \(C\) peaks shift with \(L\); reading \(T_c\) off a single \(L\) gives a systematic error.

2 · Binder cumulant

The crossing point

For an order parameter with \(n\) components

\[ U=\frac{n+2}{2}-\frac n2\,\frac{\langle m^4\rangle}{\langle m^2\rangle^2}. \]

In the ordered phase \(U\to1\), in the disordered phase (Gaussian fluctuations) \(U\to0\). Being dimensionless under scaling, the curves for different \(L\) cross at a single point at \(T_c\), up to leading corrections.

For Ising this is \(3/2\) times the standard definition \(1-\langle m^4\rangle/3\langle m^2\rangle^2\); the crossing value \(U^*\) is universal but depends on boundary conditions and aspect ratio (2D square Ising: \(U^*\simeq0.916\)). No crossing (1D, 2D Heisenberg) means no long-range order. At a first-order transition \(U\) develops a negative dip.

3 · Reweighting

A curve from one run

Samples collected at \(\beta_0\) also give the average at a nearby \(\beta\) (Ferrenberg–Swendsen):

\[ \langle O\rangle_\beta=\frac{\sum_t O_t\,e^{-(\beta-\beta_0)E_t}}{\sum_t e^{-(\beta-\beta_0)E_t}}. \]

The method relies on the tails of the \(P(E)\) histogram; the reliable range is of order \(|\Delta T|\lesssim T^2/\sqrt{NC}\) and shrinks as \(L\) grows. The dashed curve in Figure 2 is drawn only where the effective number of independent samples \(N_{\rm eff}=(\sum w)^2/\sum w^2/2\tau\ge30\).

Continuous symmetry

Mermin–Wagner, BKT and anisotropy

1 · Mermin–Wagner

No continuous symmetry breaking in 2D

In 2D XY and Heisenberg models with short-range interactions \(\langle\mathbf m\rangle=0\) at \(T>0\). Spin-wave fluctuations diverge logarithmically, like \(\int d^2k/k^2\).

On a finite lattice \(|m|\) is nonzero and decreases slowly with \(L\). In 2D Heisenberg \(\xi\propto e^{2\pi/T}\) easily exceeds the lattice at low \(T\); the state that looks "ordered" on screen is a finite-size effect. The Binder curves do not cross.

2 · BKT transition

Unbinding of vortex pairs

In the 2D XY model correlations decay algebraically at low \(T\) (quasi-long-range order). At \(T_{\rm BKT}\simeq0.893\) bound vortex–antivortex pairs unbind and the helicity modulus makes a universal jump:

\[ \begin{aligned} \Upsilon=&\ \frac1A\Big\langle\sum_{\langle ij\rangle}e_x^2\cos\theta_{ij}\Big\rangle\\ &-\frac{\beta}{A}\Big\langle\Big(\sum_{\langle ij\rangle}e_x\sin\theta_{ij}\Big)^2\Big\rangle, \end{aligned} \] \[ \Upsilon(T_{\rm BKT}^-)=\frac{2T_{\rm BKT}}{\pi}. \]

At finite \(L\), \(\Upsilon\) decreases continuously and crosses the \(2T/\pi\) line slightly above \(T_{\rm BKT}\); the corrections decay very slowly, like \(1/\ln L\). The Binder crossing is not a good criterion for BKT: the curves merge below \(T_{\rm BKT}\).

3 · 3D and anisotropy

The universality class depends on \(n\)

\(T_c\) on the simple cubic lattice: Ising \(4.5115\), XY \(2.2018\), Heisenberg \(1.4430\). In the Heisenberg model the effective anisotropy \(A=(1-\lambda)-K\) changes the number of order-parameter components:

\[ \begin{gathered} A<0:\ n=1\ \ (\text{easy axis}),\\ A>0:\ n=2\ \ (\text{easy plane}). \end{gathered} \]

A small anisotropy produces a crossover near \(T_c\): \(n=3\) behaviour at large distances from \(T_c\), \(n=1\) or \(2\) close to it. In 2D an easy axis restores an Ising transition and an easy plane a BKT transition. The page computes \(U\) with the \(n\) appropriate for the chosen anisotropy.

Potts and frustration

First-order transitions and degenerate ground states

1 · q-state Potts

From continuous to first order

On the 2D square lattice self-duality gives \(T_c=1/\ln(1+\sqrt q)\). For \(q\le4\) the transition is continuous (\(q=2\) Ising, \(q=3\): \(\nu=5/6\), \(q=4\): \(\nu=2/3\)); for \(q>4\) it is first order: ordered and disordered phases coexist at \(T_c\), \(P(e)\) is double peaked and there is latent heat.

At \(q=5\) the transition is very weakly first order; the correlation length at \(T_c\) is \(\sim2500\) lattice spacings. At the sizes accessible in a browser it cannot be distinguished from a continuous transition. Choose \(q\ge8\) to see the double peak.

2 · Frustration

AFM Ising on the triangular lattice

The three bonds of a triangle cannot all be satisfied. In the ground state every triangle has exactly one unsatisfied bond: \(e_0=-|J|\), but the number of such states grows exponentially. The Wannier entropy is

\[ s_0=\lim_{N\to\infty}\frac{\ln\Omega}{N}\simeq0.3383. \]

There is no transition at \(T>0\); correlations become algebraic as \(T\to0\). The page shows the three-sublattice \(\sqrt3\times\sqrt3\) order parameter and, as "defects", the fraction of triangles whose three spins are equal. The lattice side must be a multiple of 3.

3 · Annealing

Slow cooling and defects

In simulated annealing \(T\) is lowered over time. A system cooled slowly enough approaches the ground state; a system cooled quickly freezes in domain walls, vortices or frustration defects. The remaining defect density decreases with the cooling rate.

Cluster algorithms fail in frustrated systems: at low \(T\) the FK clusters cover the whole lattice and the defects cannot be removed. Compare Wolff with Metropolis for the triangular AFM. This is an example of an algorithm that is correct but effectively frozen.

Critical notes

Limitations and caveats

Computational limits

The simulation runs entirely in the browser and is tuned for an ordinary laptop. Lattice sizes are limited accordingly: 1D \(N\le512\), 2D \(L\le128\) (96 for the triangular lattice), 3D \(L\le24\). For large systems the computation per frame is capped, so the displayed speed drops; the result does not change, only the waiting time.

Scans run in a separate thread (Web Worker) so that the interface does not freeze. A typical finite-size scaling study (3 sizes × 16 temperatures × 4000 sweeps) takes a few minutes. On phones and tablets this can take several times longer. Research-quality exponent estimates need much larger systems and measurements.

Critical slowing down and error estimates

Near \(T_c\) the Metropolis correlation time grows like \(L^{2.17}\). If the measurement is short compared with this time, the binning does not reach a plateau and the error bar looks smaller than it is. Repeating the same point with two different seeds or two algorithms is the most reliable check.

Random numbers and reproducibility

The generator is xoshiro128** and can be seeded. The same seed, the same parameters and the same number of sweeps give the same result. In a scan every point continues the same chain; the points are therefore not fully independent.

Connection to the spin-wave lab

Stochastic LLG dynamics and Monte Carlo sample the same canonical distribution; their dynamics differ, their equilibrium averages agree. At low \(T\) MC should give \(1-\langle|m|\rangle\simeq0.253\,T\) for the 3D isotropic FM (Watson integral). This is the classical equipartition result; quantum spins follow Bloch's \(T^{3/2}\) law.

Finite size and \(T_c\)

The positions of the peaks, the size of the slopes and even the nonzero \(|m|\) above \(T_c\) are finite-size effects (\(\langle|m|\rangle\sim N^{-1/2}\)). Literature values of \(T_c\) are \(L\to\infty\) extrapolations; a peak at a single small \(L\) reproduces them only to within a few percent.

Not included

Long-range (dipolar) interactions, disorder (spin glasses), DMI and skyrmion textures, Wang–Landau and parallel tempering are not part of this version. At first-order transitions and in frustrated systems these methods are needed to free the chain from metastable states.

Scope

Models and reference values

\(J=1\), \(k_B=1\), \(|\mathbf S|=1\). Values marked "exact" are analytic, the others are high-precision MC results.

Model and lattice\(T_c\)Physics to observe
1D Ising, XY, Heisenbergnonefinite \(\xi\); exact \(e(T)\): \(-\tanh\beta\), \(-I_1(\beta)/I_0(\beta)\), \(-(\coth\beta-T)\)
2D square Ising\(2/\ln(1+\sqrt2)=2.2692\) (exact)Onsager \(m(T)\), \(e(T)\); Binder crossing; critical slowing down
2D triangular Ising (FM)\(4/\ln3=3.6410\) (exact)Same universality class, different \(T_c\)
2D triangular Ising (AFM)noneFrustration, \(s_0=0.3383\), freezing of the cluster algorithm
3D cubic Ising\(4.5115\)\(\nu\simeq0.630\), \(U^*\simeq0.698\) (in this normalization)
2D Potts (square)\(1/\ln(1+\sqrt q)\) (exact)\(q\le4\) continuous, \(q>4\) first order; double-peaked \(P(e)\)
2D XY\(T_{\rm BKT}\simeq0.893\)Vortices, helicity jump \(2T/\pi\), absence of a Binder crossing
3D XY\(2.2018\)\(n=2\) universality class
2D HeisenbergnoneMermin–Wagner, \(\xi\propto e^{2\pi/T}\)
3D Heisenberg\(1.4430\)\(n=3\); crossover to \(n=1,2\) with \(\lambda\), \(K\); spin flop for AFM