-
Notifications
You must be signed in to change notification settings - Fork 0
/
heisenberg_gs_polish.py
97 lines (72 loc) · 3.11 KB
/
heisenberg_gs_polish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import numpy as np
import sys
import os
from time import time
import tebd
import gates
import peps
import util
import globallog
#from polish import polish
import polish
t0 = time()
chi = int(sys.argv[1])
J = int(sys.argv[2])
h = float(sys.argv[3])
statefile = sys.argv[4]
num_workers = 1
if "-workers" in sys.argv:
num_workers = int(sys.argv[sys.argv.index("-workers") + 1])
globallog.write("heisenberg_gs_polish.py, chi={0:d}, J={1:d}, h={2:f}, statefile=\"{3:s}\"\n".format(chi, J, h, statefile))
basepath = "output_heisenberg_polish/"
if not ("-writehere" in sys.argv):
logfile = open(basepath + statefile[statefile.rfind("/")+1:-5] + ".log", "a")
sys.stdout = logfile
sys.stderr = logfile
def test_fct(a, A):
n = len(a)
Z = map(lambda b: peps.make_double_layer(b, o=gates.sigmaz), a)
AT = map(lambda B: B.transpose([1,2,3,0]), A)
ZT = map(lambda B: B.transpose([1,2,3,0]), Z)
X = map(lambda b: peps.make_double_layer(b, o=gates.sigmax), a)
Y = map(lambda b: peps.make_double_layer(b, o=gates.sigmay), a)
XT = map(lambda B: B.transpose([1,2,3,0]), X)
YT = map(lambda B: B.transpose([1,2,3,0]), Y)
def test_fct_impl(e):
c_zz = 0
c_xx = 0
c_yy = 0
mz = [0, 0]
for j in xrange(n):
e1 = e.get_site_environment(j)
mz[j] = e1.contract(Z[j]) / e1.contract(A[j])
e2 = e.get_bond_environment_horizontal(j)
norm = e2.contract(A[j], A[lut[j,1,0]])
c_xx += e2.contract(X[j], X[lut[j,1,0]]) / norm
c_yy += np.real(e2.contract(Y[j], Y[lut[j,1,0]]) / norm)
c_zz += e2.contract(Z[j], Z[lut[j,1,0]]) / norm
e2 = e.get_bond_environment_vertical(j)
norm = e2.contract(AT[j], AT[lut[j,0,1]])
c_xx += e2.contract(XT[j], XT[lut[j,0,1]]) / norm
c_yy += np.real(e2.contract(YT[j], YT[lut[j,0,1]]) / norm)
c_zz += e2.contract(ZT[j], ZT[lut[j,0,1]]) / norm
c_xx /= (2*n)
c_yy /= (2*n)
c_zz /= (2*n)
E = 2*J*(c_xx + c_yy + c_zz) + h*0.5*(mz[0] + mz[1])
return mz + [c_xx, c_yy, c_zz, E]
return test_fct_impl
a, nns = peps.load(statefile, dtype=complex)
lut = util.build_lattice_lookup_table(nns, [4,4])
if np.all(map(lambda b: (np.imag(b) < 1e-15).all(), a)):
a = map(lambda b: np.real(b), a)
#env_contractor = tebd.CTMRGEnvContractor(lut, chi, test_fct, 1e-12, 1e-15)
#a = tebd.polish(a, lut, env_contractor, pepsfilename=(basepath + statefile[statefile.rfind("/")+1:]))
#a = tebd.polish(a, lut, chi, test_fct, pepsfilename=(basepath + statefile[statefile.rfind("/")+1:]))
def save_callback(a):
peps.save(a, lut, basepath + statefile[statefile.rfind("/")+1:])
ecf = tebd.CTMRGEnvContractorFactory(lut, chi, test_fct, 1e-12, 1e-15, max_iterations_per_update=1000)
a = polish.polish(a, lut, ecf, num_workers=num_workers, peps_save_callback=save_callback)
#a = polish.polish_fast(a, lut, ecf)
peps.save(a, lut, basepath + statefile[statefile.rfind("/")+1:])
print "heisenberg_gs_polish.py done; needed {0:f} seconds".format(time() - t0)