Enumerate ising.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 21:39, 22 September 2015 Werner (Talk | contribs) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
| Line 1: | Line 1: | ||
| - | This page presents the program markov_disks_box.py, a Markov-chain algorithm for four disks in a square box of sides 1. | + | This page presents the Python3 program enumerate_ising.py, an enumeration algorithm for the Ising model using the Gray code, on the two-dimensional L x L lattice with periodic boundary conditions. As it stands, the program is only really suited for L=2 and L=4. As Python is a bit slow, it will take a few hours to terminate for L=6. |
| __FORCETOC__ | __FORCETOC__ | ||
| Line 5: | Line 5: | ||
| =Program= | =Program= | ||
| - | |||
| - | import random | ||
| - | |||
| - | L = [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]] | ||
| - | sigma = 0.15 | ||
| - | sigma_sq = sigma ** 2 | ||
| - | delta = 0.1 | ||
| - | n_steps = 1000 | ||
| - | for steps in range(n_steps): | ||
| - | a = random.choice(L) | ||
| - | b = [a[0] + random.uniform(-delta, delta), a[1] + random.uniform(-delta, delta)] | ||
| - | min_dist = min((b[0] - c[0]) ** 2 + (b[1] - c[1]) ** 2 for c in L if c != a) | ||
| - | box_cond = min(b[0], b[1]) < sigma or max(b[0], b[1]) > 1.0 - sigma | ||
| - | if not (box_cond or min_dist < 4.0 * sigma ** 2): | ||
| - | a[:] = b | ||
| - | print L | ||
| - | |||
| - | =Version= | ||
| - | See history for version information. | ||
| - | |||
| - | [[Category:Python]] | ||
| - | |||
| - | |||
| def gray_flip(t, N): | def gray_flip(t, N): | ||
| k = t[0] | k = t[0] | ||
| Line 50: | Line 27: | ||
| E += 2 * h * S[k - 1] | E += 2 * h * S[k - 1] | ||
| S[k - 1] *= -1 | S[k - 1] *= -1 | ||
| - | print S, E | + | print(S, E) |
| + | |||
| + | =Version= | ||
| + | See history for version information. | ||
| + | |||
| + | [[Category:Python]] [[Category:Oxford_2024]] [[Category:MOOC_SMAC]] | ||
Current revision
This page presents the Python3 program enumerate_ising.py, an enumeration algorithm for the Ising model using the Gray code, on the two-dimensional L x L lattice with periodic boundary conditions. As it stands, the program is only really suited for L=2 and L=4. As Python is a bit slow, it will take a few hours to terminate for L=6.
Contents |
[edit]
Description
[edit]
Program
def gray_flip(t, N):
k = t[0]
if k > N: return t, k
t[k - 1] = t[k]
t[k] = k + 1
if k != 1: t[0] = 1
return t, k
L = 4
N = L * L
nbr = {i : ((i // L) * L + (i + 1) % L, (i + L) % N,
(i // L) * L + (i - 1) % L, (i - L) % N)
for i in range(N)}
S = [-1] * N
E = -2 * N
print S, E
tau = range(1, N + 2)
for i in range(1, 2 ** N):
tau, k = gray_flip(tau, N)
h = sum(S[n] for n in nbr[k - 1])
E += 2 * h * S[k - 1]
S[k - 1] *= -1
print(S, E)
[edit]
Version
See history for version information.
