Ising coupling.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 21:13, 12 June 2024 Werner (Talk | contribs) ← Previous diff |
Revision as of 22:13, 12 June 2024 Werner (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| + | ==Context== | ||
| + | This page is part of my [[BegRohu_Lectures_2024|2024 Beg Rohu Lectures]] on "The second Markov chain revolution" at the [https://www.ipht.fr/Meetings/BegRohu2024/index.html Summer School] "Concepts and Methods of Statistical Physics" (3 - 15 June 2024). | ||
| + | |||
| + | ==Python program== | ||
| + | |||
| import math | import math | ||
| import random | import random | ||
Revision as of 22:13, 12 June 2024
Context
This page is part of my 2024 Beg Rohu Lectures on "The second Markov chain revolution" at the Summer School "Concepts and Methods of Statistical Physics" (3 - 15 June 2024).
Python program
import math
import random
L = 64; 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)}
beta = 0.4 # beta = 0.4407 is critical temperature
SLow = [-1 for site in range(N)]
SHigh = [1 for site in range(N)]
iter = 0
while True:
iter += 1
k = random.randint(0, N - 1)
Upsilon = random.uniform(0.0, 1.0)
hLow = sum(SLow[nn] for nn in nbr[k])
hHigh = sum(SHigh[nn] for nn in nbr[k])
SLow[k] = -1
if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * hLow)):
SLow[k] = 1
SHigh[k] = -1
if Upsilon < 1.0 / (1.0 + math.exp(-2.0 * beta * hHigh)):
SHigh[k] = 1
if SHigh == SLow:
print(iter / N)
print(SLow, SHigh)
break
