This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

vp.statmech.ising

The two-dimensional Ising model on an L by L square lattice with periodic edges, sampled by Metropolis (checkerboard order) or Wolff clusters at temperature T, coupling J and field h. A run returns the energy per site, |m|, the susceptibility, the specific heat and Binder's cumulant with error bars from binning, the autocorrelation times, the time series and the final spins, beside the exact results it can be checked against: Onsager's T_c and infinite-lattice energy, Yang's spontaneous magnetization, and Kaufman's energy and specific heat of the same finite lattice. Every random number is a Philox4x32-10 word of a counter, so a run is bit-identical in every engine.

Part of the distribution vipyr; it runs from a checkout of the repository. Planned on PyPI as pip install vipyr.

Signature

vp.statmech.ising(*, size=16, temperature=2.0, coupling=1.0, field=0.0, algorithm="metropolis", start="cold", sweeps=2000, thermalization=500, seed=1, bins=20)

Parameters

size : int, default 16
L, the lattice's side: N = L * L spins, periodic edges; even, so the checkerboard's two colors alternate around the wrap. Range: >= 4, <= 4096.
temperature : float, default 2.0
T, in units of J / k_B when J = 1; beta = 1 / T. Range: > 0.
coupling : float, default 1.0
J, between neighbors: positive is ferromagnetic (Wolff needs J > 0).
field : float, default 0.0
H, the external field.
algorithm : str, default "metropolis"
"metropolis": single-spin flips in checkerboard order; "wolff": cluster flips. Range: one of metropolis, wolff.
start : str, default "cold"
"cold": every spin up; "hot": each spin up or down at random. Range: one of cold, hot.
sweeps : int, default 2000
The measured sweeps; a Wolff sweep is as many clusters as add up to N spins or more. Range: >= 2, <= 100000000.
thermalization : int, default 500
The sweeps run and discarded before measuring. Range: >= 0, <= 100000000.
seed : int, default 1
The Philox key: runs with the same seed and settings give the same bits. Range: >= 0, <= 4294967295.
bins : int, default 20
The number of bins for the error bars; each holds sweeps / bins sweeps, which should be many autocorrelation times. Range: >= 2, <= 100000.

Returns

A frozen IsingResult. Iterating it gives the fields below in order; it also has params, tests, log and check().

energy : float
The energy per site, <E> / N.
energy_err : float
Its standard error, from the scatter of the bin means.
mag_abs : float
<|m|>, m = sum_i s_i / N.
mag_abs_err : float
Its standard error, from the bins.
mag : float
<m>, which is near 0 at h = 0 on a finite lattice once the run flips between up and down.
mag_err : float
Its standard error, from the bins.
heat : float
The specific heat per site, beta^2 N (<e^2> - <e>^2), e = E / N.
heat_err : float
Its jackknife error over the bins.
chi : float
The susceptibility per site, beta N (<m^2> - <|m|>^2).
chi_err : float
Its jackknife error over the bins.
binder : float
Binder's cumulant 1 - <m^4> / (3 <m^2>^2): 2/3 when ordered, 0 for a Gaussian m.
binder_err : float
Its jackknife error over the bins.
tau_energy : float
The integrated autocorrelation time of the energy, in sweeps.
tau_mag : float
The integrated autocorrelation time of |m|, in sweeps.
accept : float
Metropolis: the fraction of proposed flips accepted; Wolff: the mean cluster size over N.
energy_series : ndarray[float64]
The energy per site after each measured sweep.
mag_series : ndarray[float64]
M after each measured sweep.
spins : ndarray[float64]
The final arrangement, L by L, each +1 or -1 (rank 2).
t_critical : float
Onsager's critical temperature 2 J / ln(1 + sqrt 2) (for J > 0).
exact_known : bool
Whether exact_energy, exact_heat and energy_infinite apply: field 0, coupling positive and temperature not T_c.
exact_energy : float
Kaufman's exact energy per site of this L by L lattice (0 unless exact_known).
exact_heat : float
Kaufman's exact specific heat per site of this L by L lattice (0 unless exact_known).
energy_infinite : float
Onsager's energy per site of the infinite lattice (0 unless exact_known).
mag_infinite : float
Yang's spontaneous magnetization of the infinite lattice at h = 0: 0 at and above T_c.

Raises

vipyr.ParameterError
A ValueError: an argument outside its range, choices, rank or shape, or one of a group given without the rest; its .param names the argument.
TypeError
An argument of the wrong type, or an unknown keyword.
vipyr.VivBuildError
An ImportError: no C compiler, or the program's C does not build.
RuntimeError
The program stops with its own message (a combination it rejects, or no convergence where the program treats that as an error).

Examples

import vipyr as vp
r = vp.statmech.ising()                 # 16 x 16 at T = 2.0, Metropolis
print(r.energy, r.energy_err, r.mag_abs, r.exact_energy)
assert r.check()
-1.7462734375 0.004405968213157423 0.91094921875 -1.745530669046443

Each example ran as written when these pages were generated, and the output shown is what it printed.

Checked against

Exact
Onsager, Phys. Rev. 65, 117 (1944): T_c and the infinite lattice's energy; Yang, Phys. Rev. 85, 808 (1952): the spontaneous magnetization; Kaufman, Phys. Rev. 76, 1232 (1949), as Ferdinand and Fisher, Phys. Rev. 185, 832 (1969) eq. 2.1, write it: the finite periodic lattice's partition function
Rng
Philox4x32-10, Salmon, Moraes, Dror and Shaw, SC11 (2011); Random123's known-answer vectors pass in lib/ising.viv
Tests
stat/ising/test_ising.py: every tolerance is stated beside its check

Source