-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFinalSuperblock.cpp
271 lines (258 loc) · 10.7 KB
/
FinalSuperblock.cpp
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include "FinalSuperblock.h"
#define obsId_d Matrix<obsScalar, d, d>::Identity()
#ifndef differentScalars
#define obsProjectBlock projectBlock
#define obsProjectBASCoupling projectBASCoupling
#define obsProjectFreeSite projectFreeSite
#endif
using namespace Eigen;
FinalSuperblock::FinalSuperblock(double gsEnergy, int lSup,
const rmMatrixX_t& psiGround, int mS, int mE,
int skips)
: gsEnergy(gsEnergy), lSup(lSup), psiGround(psiGround), mS(mS), mE(mE),
skips(skips)
{
if(lSup % 2)
{
lS = (lSup - 1)/2;
lE = (lSup - 3)/2;
}
else
lS = lE = lSup / 2 - 1;
};
double FinalSuperblock::expValue(const opsVec& ops,
std::vector<TheBlock>& westBlocks,
std::vector<TheBlock>& eastBlocks)
{
sysBlockOps.clear();
envBlockOps.clear();
lFreeSite = obsId_d;
rFreeSite = obsId_d;
bool opInSysBlock = false,
opAtlFreeSite = false,
opAtrFreeSite = false,
opInEnvBlock = false;
for(const auto& opToEvaluate : ops) // split up operators into their blocks
{
int site = opToEvaluate.second;
if(site < lS)
{
opInSysBlock = true;
placeOp(opToEvaluate, sysBlockOps, true);
}
else if(site == lS) // if necessary, assign left free-site operator
{
opAtlFreeSite = true;
lFreeSite *= opToEvaluate.first;
}
else if(site == lS + 1) // and right free-site operator
{
opAtrFreeSite = true;
rFreeSite *= opToEvaluate.first;
}
else
{
opInEnvBlock = true;
placeOp(opToEvaluate, envBlockOps, false);
};
};
reshapePsiGround();
obsVectorX_t psiPrime;
// output of observables in one half of system's action on ground state
switch(8 * opInSysBlock + 4 * opAtlFreeSite + 2 * opInEnvBlock
+ opAtrFreeSite) // evaluate observable
{
case 0: // no operators
return 1.;
case 1: // op at right-hand free site
psiPrime = actRFreeSite();
reshapePsiGround();
return obsRe(psiGround.col(0).dot(psiPrime));
case 2: // ops in environment block
psiPrime = actEnvBlock(eastBlocks);
reshapePsiGround();
return obsRe(psiGround.col(0).dot(psiPrime));
case 3: // ops in environment block and right-hand free site
psiPrime = actEnvBlockRFreeSite(eastBlocks);
reshapePsiGround();
return obsRe(psiGround.col(0).dot(psiPrime));
case 4: // op at left free site
psiPrime = actLFreeSite();
reshapePsiGround();
return obsRe(psiGround.col(0).dot(psiPrime));
case 5: // ops at both free sites
psiPrime = actRFreeSite();
reshapePsiGround();
return obsRe(actLFreeSite().dot(psiPrime));
case 6: // ops in environment block and at left-hand free site
psiPrime = actLFreeSite();
reshapePsiGround();
return obsRe(actEnvBlock(eastBlocks).dot(psiPrime));
case 7: // ops at both free sites and environment block
psiPrime = actEnvBlockRFreeSite(eastBlocks);
reshapePsiGround();
return obsRe(actLFreeSite().dot(psiPrime));
case 8: // ops in system block
psiPrime = actSysBlock(westBlocks);
reshapePsiGround();
return obsRe(psiGround.col(0).dot(psiPrime));
case 9: // ops in system block and at right-hand free site
psiPrime = actSysBlock(westBlocks);
reshapePsiGround();
return obsRe(actRFreeSite().dot(psiPrime));
case 10: // ops in system and environment blocks
psiPrime = actEnvBlock(eastBlocks);
reshapePsiGround();
return obsRe(actSysBlock(westBlocks).dot(psiPrime));
case 11: // ops in system and environment blocks and right-hand free site
psiPrime = actEnvBlockRFreeSite(eastBlocks);
reshapePsiGround();
return obsRe(actSysBlock(westBlocks).dot(psiPrime));
case 12: // ops in system block and left-hand free site
psiPrime = actSysBlockLFreeSite(westBlocks);
reshapePsiGround();
return obsRe(psiGround.col(0).dot(psiPrime));
case 13: // ops in system block and both free sites
psiPrime = actRFreeSite();
reshapePsiGround();
return obsRe(actSysBlockLFreeSite(westBlocks).dot(psiPrime));
case 14: // ops in system and environment blocks and left-hand free site
psiPrime = actEnvBlock(eastBlocks);
reshapePsiGround();
return obsRe(actSysBlockLFreeSite(westBlocks).dot(psiPrime));
case 15: // ops in system and environment blocks and both free sites
psiPrime = actEnvBlockRFreeSite(eastBlocks);
reshapePsiGround();
return obsRe(actSysBlockLFreeSite(westBlocks).dot(psiPrime));
default:
return 0.;
// can't actually reach this case - just here to quiet compiler warning
};
};
void FinalSuperblock::placeOp(const std::pair<obsMatrixD_t, int>& op,
opsMap& blockSide, bool systemSide)
{
int lhSite = (systemSide ? op.second : lSup - 1 - op.second);
if(blockSide.count(lhSite)) // already an observable at this site?
blockSide[lhSite] *= op.first;
else
blockSide.insert(std::pair<int, obsMatrixD_t>(lhSite, op.first));
};
void FinalSuperblock::reshapePsiGround()
{
psiGround.resize(mS * d * mE * d, 1);
};
obsVectorX_t FinalSuperblock::actSysBlock(std::vector<TheBlock>& westBlocks)
{
psiGround.resize(mS, d * mE * d);
obsMatrixX_t oPsi = rhoBasisRep(sysBlockOps, westBlocks, lS) * psiGround;
oPsi.resize(mS * d * mE * d, 1);
return oPsi;
};
obsVectorX_t FinalSuperblock::actLFreeSite()
{
int mSd = mS * d,
mEd = mE * d;
psiGround.resize(mSd, mEd);
rmMatrixX_t psiT = psiGround.transpose();
psiT.resize(mEd * mS, d);
obsMatrixX_t psiTOT = psiT * lFreeSite.transpose();
psiTOT.resize(mEd, mSd);
psiTOT.transposeInPlace();
psiTOT.resize(mSd * mEd, 1);
return psiTOT;
};
obsVectorX_t FinalSuperblock::actSysBlockLFreeSite(std::vector<TheBlock>&
westBlocks)
{
obsMatrixX_t oLPsi = actLFreeSite();
oLPsi.resize(mS, d * mE * d);
obsMatrixX_t oSOLPsi = rhoBasisRep(sysBlockOps, westBlocks, lS) * oLPsi;
oSOLPsi.resize(mS * d * mE * d, 1);
return oSOLPsi;
};
obsVectorX_t FinalSuperblock::actEnvBlock(std::vector<TheBlock>& eastBlocks)
{
int mSd = mS * d;
psiGround.resize(mSd, mE * d);
rmMatrixX_t psiT = psiGround.transpose();
psiT.resize(mE, d * mSd);
obsMatrixX_t oDagPsiT
= rhoBasisRep(envBlockOps, eastBlocks, lE).adjoint() * psiT;
oDagPsiT.resize(mE * d, mSd);
oDagPsiT.transposeInPlace();
oDagPsiT.resize(mSd * mSd, 1);
return oDagPsiT;
};
obsVectorX_t FinalSuperblock::actRFreeSite()
{
psiGround.resize(mS * d * mE, d);
obsMatrixX_t psiOStar = psiGround * rFreeSite.conjugate();
psiOStar.resize(mS * d * mE * d, 1);
return psiOStar;
};
obsVectorX_t FinalSuperblock::actEnvBlockRFreeSite(std::vector<TheBlock>&
eastBlocks)
{
obsMatrixX_t psiOEDag = actEnvBlock(eastBlocks);
psiOEDag.resize(mS * d * mE, d);
obsMatrixX_t psiOEDagORStar = psiOEDag * rFreeSite.conjugate();
psiOEDagORStar.resize(mS * d * mE * d, 1);
return psiOEDagORStar;
};
obsMatrixX_t FinalSuperblock::rhoBasisRep(const opsMap& blockOps,
std::vector<TheBlock>& blocks,
int blockSize) const
{
obsMatrixX_t rhoBasisBlockOp;
const auto firstOp = blockOps.begin(), // first nontrivial site operator
opsEnd = blockOps.end(); // last one
auto currentOp = firstOp;
int currentSite;
if(currentOp -> first < skips) // if necessary, do edge ED
{
if(currentOp -> first == 0) // at first site in system?
{
currentSite = 0;
rhoBasisBlockOp = currentOp++ -> second;
}
else
{
currentSite = firstOp -> first - 1;
// move to last consecutive site with no operator
rhoBasisBlockOp
= obsMatrixX_t::Identity(blocks[currentSite].blockParts.m,
blocks[currentSite].blockParts.m);
};
for(; currentSite < skips; currentSite++)
// perform ED tensoring until you reach end of edge ED
rhoBasisBlockOp
= kp(rhoBasisBlockOp,
( currentOp != opsEnd
&& currentSite == currentOp -> first - 1 ?
currentOp++ -> second :
obsId_d)).eval();
}
else if(currentOp -> first == skips)
{
currentSite = skips;
rhoBasisBlockOp
= kp(obsMatrixX_t::Identity(blocks[currentSite - 1].blockParts.m,
blocks[currentSite - 1].blockParts.m),
currentOp++ -> second);
}
else
{
currentSite = currentOp -> first - 1;
rhoBasisBlockOp
= blocks[currentSite++].obsProjectFreeSite(currentOp++ -> second);
};
for(int end = blockSize - 1; currentSite < end; currentSite++)
// project rhoBasisBlockOp into new bases
rhoBasisBlockOp
= (currentOp != opsEnd && currentSite == currentOp -> first - 1 ?
blocks[currentSite].obsProjectBASCoupling(rhoBasisBlockOp,
currentOp++ -> second) :
blocks[currentSite].obsProjectBlock(rhoBasisBlockOp));
return rhoBasisBlockOp;
};