-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCorr.h
More file actions
193 lines (164 loc) · 5.45 KB
/
Corr.h
File metadata and controls
193 lines (164 loc) · 5.45 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef __CORR_H_CMC__
#define __CORR_H_CMC__
#include "itensor/all.h"
#include "IUtility.h"
using namespace iutility;
template <typename SiteType, typename NumType>
Mat<NumType> exact_corr (const MPS& psi)
{
int N = length (psi);
auto sites = SiteType (siteInds(psi));
auto corr = Mat<NumType> (N,N);
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
{
AutoMPO ampo (sites);
ampo += 1.,"Cdag",i,"C",j;
auto C = toMPO (ampo);
if constexpr (is_same_v <NumType, Real>)
corr(i-1,j-1) = inner (psi, C, psi);
else
corr(i-1,j-1) = innerC (psi, C, psi);
}
return corr;
}
inline ITensor multSite (ITensor A, ITensor const& B)
{
A *= B;
A.noPrime();
return A;
}
inline Index make_index (int m)
{
//return Index (QN({"Nf",0}), m, Out, "Mix");
return Index (m, "Mix");
}
ITensor make_expand_proj (Index ii, int m_extra=1)
{
ii.dag();
// Make projector between the original space (m) and the enlarged space (m+m_extra)
Index inew = make_index (dim(ii) + m_extra);
auto P_expand = ITensor (ii, inew);
for(int i = 1; i <= dim(ii); i++)
P_expand.set (ii=i, inew=i, 1.);
return P_expand;
}
template <typename SiteType, typename NumType>
class Cdag_Set
{
public:
Cdag_Set () {}
Cdag_Set (const MPS& psi, int ell, string spin_str="");
void to_right (const MPS& psi, int ell, Args const& args=Args::global(), string spin_str="");
Vec<NumType> apply_C (const MPS& psi, int j, string spin_str) const;
int m () const { return dim(_si); }
private:
vector<ITensor> _Us, _Proj;
ITensor _V;
int _ilast;
Index _si; // The "site" (left) index of _V
SiteType _sites;
};
template <typename SiteType, typename NumType>
Cdag_Set<SiteType,NumType> :: Cdag_Set (const MPS& psi, int ell, string spin_str)
: _ilast (0)
, _sites (siteInds(psi))
{
if (orthoCenter(psi) <= ell) {
cout << "Error: Cdag_Set<SiteType,NumType> :: init: orthogonality center must be > ell" << endl;
cout << " " << orthoCenter(psi) << ", " << ell << endl;
throw;
}
_V = multSite (_sites.op("Cdag"+spin_str, ell), multSite (_sites.op("F",ell), psi(ell)));
_V *= prime (dag(psi(ell)), rightLinkIndex(psi,ell));
// Make a dummy site-index to C
_si = make_index (1);
_V *= setElt(_si=1);
}
template <typename SiteType, typename NumType>
void Cdag_Set<SiteType,NumType> :: to_right (const MPS& psi, int ell, Args const& args, string spin_str)
{
if (orthoCenter(psi) <= ell) {
cout << "Error: Cdag_Set<SiteType,NumType> :: to_right: orthogonality center must be > ell" << endl;
cout << " " << orthoCenter(psi) << ", " << ell << endl;
throw;
}
// Apply the i-th transfer matrix
_V *= prime (dag(psi(ell)), "Link");
_V *= multSite (_sites.op("F",ell), psi(ell));
// Compute the element for c_{i=ell}
ITensor c_l = multSite (_sites.op("Cdag"+spin_str,ell), multSite(_sites.op("F",ell), psi(ell)));
c_l *= prime (dag(psi(ell)), rightLinkIndex(psi,ell));
// ------- Add c_l to Cdag -------
//
ITensor P_ex = make_expand_proj (_si);
_Proj.push_back (P_ex);
_V *= P_ex; // expand _V
// Add c_l into _V
Index si = findIndex (_V, "Mix");
int m = dim(si);
_V += c_l * setElt(si=m);
// -------------------------------------------
// Truncate by SVD; keep the UV form
_Us.emplace_back (si);
ITensor Vtmp, D;
svd (_V, _Us.back(), D, Vtmp, args);
_V = D * Vtmp;
_si = commonIndex (_V, _Us.back());
_ilast++;
}
template <typename SiteType, typename NumType>
Vec<NumType> Cdag_Set<SiteType,NumType> :: apply_C (const MPS& psi, int j, string spin_str) const
{
// Apply Cj
ITensor V = _V * multSite (_sites.op("C"+spin_str,j), psi(j));
V *= prime (dag(psi(j)), rightLinkIndex (psi,j-1));
// Contract back _Us to get CidagCj
Vec<NumType> cdagc (_ilast+1);
for(int i = _ilast; i > 0; i--)
{
int im = i-1;
V *= _Us.at(im);
const Index& ii = V.inds()(1);
cdagc(i) = eltT<NumType> (V, ii=dim(ii));
V *= dag(_Proj.at(im)); // Project to left space (the column of U)
}
Index si = V.inds()(1);
cdagc(0) = eltT<NumType> (V, si=1);
return cdagc;
}
template <typename SiteType, typename NumType>
Mat<NumType> Measure_corr (MPS psi, Args const& args=Args::global(), string spin_str="")
{
int N = length(psi);
auto sp = SiteType (siteInds(psi));
auto corr = Mat<NumType> (N,N);
Cdag_Set<SiteType,NumType> Cdag;
int mmax = 0;
for(int j = 1; j <= N; j++)
{
psi.position(j);
// Diagonal
ITensor tmp = multSite (sp.op("N"+spin_str,j), psi(j));
ITensor ci = tmp * dag(psi(j));
corr(j-1,j-1) = eltT<NumType> (ci);
if (j == 1) continue;
else if (j == 2)
Cdag = Cdag_Set<SiteType,NumType> (psi, 1, spin_str); // Initialize C
else
Cdag.to_right (psi, j-1, args, spin_str); // Extend C to the next site
// Off-diagonal
auto cdagc = Cdag.apply_C (psi, j, spin_str);
for(int i = 1; i < j; i++)
{
auto c = cdagc (i-1);
corr(i-1,j-1) = c;
corr(j-1,i-1) = conjT (c);
}
if (Cdag.m() > mmax)
mmax = Cdag.m();
}
cout << "maxm in Measure_corr = " << mmax << endl;
return corr;
}
#endif