-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpeps_h.py
166 lines (157 loc) · 5.55 KB
/
peps_h.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from ptensor.parray import PArray
from ptensor.include import np
from ptensor.parray_helper import einsum,concatenate
import peps
# Conventions:
# alpha - 0
# beta - 1
# then Sp = [[0,1]
# [0,0]]
# Sz = .5*np.array([[1.,0.],[0.,-1.]])
def get_Sz():
Sz = PArray([[0,1],[0,1]],[[1,1],[1,1]])
Sz[0,0] = np.array(0.5).reshape(1,1)
Sz[1,1] = np.array(-0.5).reshape(1,1)
return Sz
# Sp = np.array([[0.,1.],[0.,0.]])
def get_Sp():
Sp = PArray([[1],[0,1],[0,1]],[[1],[1,1],[1,1]]) # To match with PEPS qnums!
Sp[0,0,1] = np.array(1).reshape(1,1,1)
return Sp
# Sm = np.array([[0.,0.],[1.,0.]])
def get_Sm():
Sm = PArray([[1],[0,1],[0,1]],[[1],[1,1],[1,1]])
Sm[0,1,0] = np.array(1).reshape(1,1,1)
return Sm
Sz = get_Sz()
Sp = get_Sp()
Sm = get_Sm()
# Evaluate: vec{S}_i*vec{S}_j = Sz_i*Sz_j + 0.5*(Sp_i*Sm_j+c.c.)
#
# Horizontal:
#
# parity=odd,bond=1
# |----|
# |/ |/
# ===*====*===
# / /
# [i,j] [i,j+1]
#
def eval_hbond(pepsa0, pepsa, i, j, auxbond):
debug = False
# Sz*Sz
pepsb = peps.copy(pepsa)
pepsb[i,j] = einsum("pq,qludr->pludr",Sz,pepsa[i,j])
pepsb[i,j+1] = einsum("pq,qludr->pludr",Sz,pepsa[i,j+1])
valzz = peps.dot(pepsa0,pepsb,auxbond)
if debug: print (i,j),'valzz=',valzz
# Sp*Sm
pepsb = peps.copy(pepsa)
pepsb[i,j] = einsum("xpq,qludr->pludxr",Sp,pepsa[i,j] ).merge_adjpair(4,5)
pepsb[i,j+1] = einsum("xpq,qludr->pxludr",Sm,pepsa[i,j+1]).merge_adjpair(1,2)
valpm = peps.dot(pepsa0,pepsb,auxbond)
if debug: print (i,j),'valpm=',valpm
# Sm*Sp
pepsb = peps.copy(pepsa)
pepsb[i,j] = einsum("xpq,qludr->pludxr",Sm,pepsa[i,j] ).merge_adjpair(4,5)
pepsb[i,j+1] = einsum("xpq,qludr->pxludr",Sp,pepsa[i,j+1]).merge_adjpair(1,2)
valmp = peps.dot(pepsa0,pepsb,auxbond)
if debug: print (i,j),'valmp=',valmp
return valzz + 0.5*(valpm+valmp)
# Vertial
# |
# * [i+1,j]
# |
# * [i]
# |
def eval_vbond(pepsa0, pepsa, i, j,auxbond):
debug = False
# Sz*Sz
pepsb = peps.copy(pepsa)
pepsb[i,j] = einsum("pq,qludr->pludr",Sz,pepsa[i,j])
pepsb[i+1,j] = einsum("pq,qludr->pludr",Sz,pepsa[i+1,j])
valzz = peps.dot(pepsa0,pepsb,auxbond)
if debug: print (i,j),'valzz=',valzz
# Sp*Sm
pepsb = peps.copy(pepsa)
pepsb[i,j] = einsum("xpq,qludr->plxudr",Sp,pepsa[i,j] ).merge_adjpair(2,3)
pepsb[i+1,j] = einsum("xpq,qludr->pluxdr",Sm,pepsa[i+1,j]).merge_adjpair(3,4)
valpm = peps.dot(pepsa0,pepsb,auxbond)
if debug: print (i,j),'valpm=',valpm
# Sm*Sp
pepsb = peps.copy(pepsa)
pepsb[i,j] = einsum("xpq,qludr->plxudr",Sm,pepsa[i,j] ).merge_adjpair(2,3)
pepsb[i+1,j] = einsum("xpq,qludr->pluxdr",Sp,pepsa[i+1,j]).merge_adjpair(3,4)
valmp = peps.dot(pepsa0,pepsb,auxbond)
if debug: print (i,j),'valmp=',valmp
return valzz + 0.5*(valpm+valmp)
# Evaluate <PEPSa|Si*Sj|PEPSb> for each term of Si*Sj
def eval_heish(pepsa, pepsb, auxbond, debug=False):
shape = pepsa.shape
nr,nc = shape
val = 0.
for i in range(nr):
for j in range(nc-1):
val += eval_hbond(pepsa,pepsb,i,j,auxbond)
if debug: print '(i,j)/val=',(i,j),val
for i in range(nr-1):
for j in range(nc):
val += eval_vbond(pepsa,pepsb,i,j,auxbond)
if debug: print '(i,j)/val=',(i,j),val
return val
# # A special prod (1+xSi*Sj)
# def product(pepsa,auxbond,x):
# pepsb = peps.copy(pepsa)
# nr,nc = pepsa.shape
#
# Sz = PArray([[0,1],[0,1]],[[1,1],[1,1]])
# Sz[0,0] = np.sqrt(x)*np.array(0.5).reshape(1,1)
# Sz[1,1] = np.sqrt(x)*np.array(-0.5).reshape(1,1)
# Sp = PArray([[1],[0,1],[0,1]],[[1],[1,1],[1,1]]) # To match with PEPS qnums!
# Sp[0,0,1] = np.sqrt(x)*np.array(1).reshape(1,1,1)
# Sp = Sp.merge([[0,1],[2]])
# Sm = PArray([[1],[0,1],[0,1]],[[1],[1,1],[1,1]])
# Sm[0,1,0] = np.sqrt(x)*np.array(1).reshape(1,1,1)
# Sm = Sm.merge([[0,1],[2]])
#
# # Hbond: left-right
# for i in range(nr):
# for j in range(nc-1):
# tmp1 = pepsb[i,j].copy()
# tmp2 = einsum("pq,qludr->pludr",Sz, pepsb[i,j])
# tmp1 = concatenate(tmp1,tmp2,4)
# tmp2 = einsum("Pq,qludr->Pludr",Sp, pepsb[i,j])
# tmp1 = concatenate(tmp1,tmp2,4)
# tmp2 = einsum("Pq,qludr->Pludr",Sm, pepsb[i,j])
# tmp1 = concatenate(tmp1,tmp2,4)
# pepsb[i,j] = tmp1.copy()
# tmp1 = pepsb[i,j+1].copy()
# tmp2 = einsum("pq,qludr->pludr",Sz, pepsb[i,j+1])
# tmp1 = concatenate(tmp1,tmp2,1)
# tmp2 = einsum("Pq,qludr->Pludr",Sm, pepsb[i,j+1])
# tmp1 = concatenate(tmp1,tmp2,1)
# tmp2 = einsum("Pq,qludr->Pludr",Sp, pepsb[i,j+1])
# tmp1 = concatenate(tmp1,tmp2,1)
# pepsb[i,j+1] = tmp1.copy()
# # Vbond: up-down
# for i in range(nr-1):
# for j in range(nc):
# tmp1 = pepsb[i,j].copy()
# tmp2 = einsum("pq,qludr->pludr",Sz, pepsb[i,j])
# tmp1 = concatenate(tmp1,tmp2,2)
# tmp2 = einsum("Pq,qludr->Pludr",Sp, pepsb[i,j])
# tmp1 = concatenate(tmp1,tmp2,2)
# tmp2 = einsum("Pq,qludr->Pludr",Sm, pepsb[i,j])
# tmp1 = concatenate(tmp1,tmp2,2)
# pepsb[i,j] = tmp1.copy()
# # right
# tmp1 = pepsb[i+1,j].copy()
# tmp2 = einsum("pq,qludr->pludr",Sz, pepsb[i+1,j])
# tmp1 = concatenate(tmp1,tmp2,3)
# tmp2 = einsum("Pq,qludr->Pludr",Sm, pepsb[i+1,j])
# tmp1 = concatenate(tmp1,tmp2,3)
# tmp2 = einsum("Pq,qludr->Pludr",Sp, pepsb[i+1,j])
# tmp1 = concatenate(tmp1,tmp2,3)
# pepsb[i+1,j] = tmp1.copy()
# val = peps.dot(pepsb,pepsa,auxbond)
# return val