-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathiTEBD.py
148 lines (114 loc) · 3.2 KB
/
iTEBD.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import sys
sys.path.append("..")
import tor10 as Tt
import torch as tor
import copy
import numpy as np
if len(sys.argv) < 5:
print(".py <J> <Hx> <chi> <converge>")
exit(1)
## Params H = [J]SzSz - [Hx]Sx
chi = int(sys.argv[3])
Hx = float(sys.argv[2])
J = float(sys.argv[1])
CvgCrit = float(sys.argv[4])
## check:
if chi<1:
raise ValueError("[ERROR] bond dimension should be >=1")
if CvgCrit<=0:
raise ValueError("[ERROR] converge should be >0")
## Create onsite-Op.
Sz = Tt.UniTensor(bonds=[Tt.Bond(2),Tt.Bond(2)],rowrank=1,dtype=tor.float64,device=tor.device("cpu"))
Sx = copy.deepcopy(Sz)
I = copy.deepcopy(Sz)
Sz.SetElem([1, 0,\
0,-1 ])
Sx.SetElem([0, 1,\
1, 0 ])
I.SetElem([1, 0,\
0, 1 ])
Sz = Sz*J
## Create NN terms
Sx = Sx*Hx
TFterm = Tt.Otimes(Sx,I) + Tt.Otimes(I,Sx)
ZZterm = Tt.Otimes(Sz,Sz)
del Sz,Sx,I
H = TFterm + ZZterm
del TFterm,ZZterm
H = H.Reshape([4,4],new_labels=[0,1],rowrank=1)
## Create Evov Op.
eH = Tt.ExpH(H*-0.1)
eH = eH.Reshape([2,2,2,2],new_labels=[0,1,2,3],rowrank=2)
H = H.Reshape([2,2,2,2],new_labels=[0,1,2,3],rowrank=2) # this is estimator.
## Create MPS:
#
# | |
# --A-la-B-lb--
#
A = Tt.UniTensor(bonds=[Tt.Bond(chi),Tt.Bond(2),Tt.Bond(chi)],
rowrank=1,
labels=[-1,0,-2]).Rand()
B = Tt.UniTensor(bonds=A.bonds,rowrank=1,labels=[-3,1,-4]).Rand()
la = Tt.UniTensor(bonds=[Tt.Bond(chi),Tt.Bond(chi)],
rowrank=1,
labels=[-2,-3],is_diag=True).Rand()
lb = Tt.UniTensor(bonds=[Tt.Bond(chi),Tt.Bond(chi)],
rowrank=1,
labels=[-4,-5],is_diag=True).Rand()
## Evov:
Elast = 0
for i in range(100000):
A.SetLabels([-1,0,-2])
B.SetLabels([-3,1,-4])
la.SetLabels([-2,-3])
lb.SetLabels([-4,-5])
X = Tt.Contract(Tt.Contract(A,la),Tt.Contract(B,lb))
lb.SetLabel(-1,idx=1)
X = Tt.Contract(lb,X)
## X =
# (0) (1)
# | |
# (-4) --lb-A-la-B-lb-- (-5)
#
#X.Print_diagram()
Xt = copy.deepcopy(X)
#Xt.Whole_transpose()
XNorm = Tt.Contract(X, Xt)
XH = Tt.Contract(X, H)
XH.SetLabels([-4,-5,0,1]) ## JJ, this is your bug.
XHX = Tt.Contract(Xt, XH)
XeH = Tt.Contract(X,eH)
# measurements
E = (XHX.Storage / XNorm.Storage).item()
if np.abs(E - Elast) < CvgCrit:
print("[Converged!]")
break
Elast = E
print("Energy = {:.6f}".format(E))
XeH.Permute([-4,2,3,-5],by_label=True)
#XeH.Contiguous_()
#XeH.View_([chi*2,chi*2],rowrank=1)
XeH.Reshape_([chi*2,chi*2],rowrank=1)
A,la,B = Tt.Svd_truncate(XeH,chi)
la *= la.Norm()**-1
A = A.Reshape([chi,2,chi], new_labels=[-1,0,-2], rowrank=1)
B = B.Reshape([chi,2,chi], new_labels=[-3,1,-4], rowrank=1)
# de-contract the lb tensor , so it returns to
#
# | |
# --lb-A'-la-B'-lb--
#
# again, but A' and B' are updated
lb_inv = Tt.Inverse(lb)
A = Tt.Contract(lb_inv, A)
B = Tt.Contract(B, lb_inv)
# translation symmetry, exchange A and B site
A,B = B,A
la,lb = lb,la
del X
## Trainsion save:
#Tt.Save(A,"A")
#Tt.Save(B,"B")
#Tt.Save(la,"la")
#Tt.Save(lb,"lb")
print("[Done]")