Repository navigation
Expand file tree
/
Copy pathUtils.cpp.old
More file actions
196 lines (147 loc) · 5.1 KB
/
Copy pathUtils.cpp.old
File metadata and controls
196 lines (147 loc) · 5.1 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
194
195
#include "Utils.hpp"
#include "boost/math/special_functions.hpp"
#include "mkl.h"
#include <vector>
#include <cmath>
using namespace std;
using namespace uni10;
using namespace boost::math;
double Utils::GetMax(UniTensor<double> &T){
return abs(T.GetElem()[cblas_idamax(T.ElemNum(), T.GetElem() , 1)]);
}
uni10::UniTensor<double> Utils::MakeLocal(const double &J1, const double &J2, const double &Beta){
// Geometry :
// u
// _|_
// l--| |--r
// | |
// ---
// |
// d
// Tensor : left-BD : in / right-BD : out
//
// --------
// l--| |--r
// u--| |--d
// --------
vector<Bond> Bds(2,Bond(BD_IN,2));
Bds.push_back(Bond(BD_OUT,2));
Bds.push_back(Bond(BD_OUT,2));
UniTensor<double> O(Bds);
vector<double> Raw(16);
double sigD1, sigD2;
// i-j-k-l = L-U-R-D
for(int l=0;l<2;l++)
for(int u=0;u<2;u++)
for(int r=0;r<2;r++)
for(int d=0;d<2;d++){
sigD1 = (2.*l - 1)*(2.*d - 1);
sigD2 = (2.*l - 1)*(2.*u - 1);
Raw[l*8+u*4+r*2+d] = (1.+(2.*l-1.)*(2.*r-1.)*(2.*u-1.)*(2.*d-1.))/2
* exp(-J1*Beta*0.5*(2.*(l+u+r+d)-4.) - J2*Beta*(sigD1+sigD2));
}
//O.SetElem(Raw);
O.SetElem(Raw);
return O;
}
UniTensor<double> Utils::Make_T(const double &Beta,const double &h,const unsigned int &Chi){
unsigned int Chi2 = Chi*Chi;
unsigned int Chi3 = Chi2*Chi;
///Set Raw elements
Matrix<double> rawN(Chi2,Chi2);
for(unsigned int l=0;l<Chi;l++)
for(unsigned int u=0;u<Chi;u++)
for(unsigned int r=0;r<Chi;r++)
for(unsigned int d=0;d<Chi;d++)
rawN[l*Chi3 + u*Chi2 + r*Chi + d] = sqrt(cyl_bessel_i(l,Beta)*
cyl_bessel_i(u,Beta)*
cyl_bessel_i(r,Beta)*
cyl_bessel_i(d,Beta))*
cyl_bessel_i(l+u-r-d,Beta*h);
//rawN *= 1./norm(rawN);
///Set Tensor T_lurd:
vector<Bond> Bds(2,Bond(BD_IN,Chi));
Bds.push_back(Bond(BD_OUT,Chi));
Bds.push_back(Bond(BD_OUT,Chi));
UniTensor<double> T(Bds);
//T.PutBlock(rawN);
T.PutBlock(rawN);
return T;
}
void Utils::truncateLUs(const int dir, const int &chi, vector<UniTensor<double> >& svdUs,UniTensor<double> &T2){
vector<int> ori_labels;
vector<Bond> new_bonds;// = Us[0].bond();
Matrix<double> blk;
//L or U
if(dir==0){
ori_labels = svdUs[1].label();
new_bonds = svdUs[1].bond();
new_bonds[1] = Bond(BD_OUT, chi);
Resize(blk, svdUs[1].GetBlock(), svdUs[1].GetBlock().row(), chi, INPLACE);
svdUs[1].Assign(new_bonds);
svdUs[1].PutBlock(blk);
svdUs[1].SetLabel(ori_labels);
Contract(T2,T2,svdUs[1],INPLACE);
//cout << T2 ;
ori_labels = svdUs[3].label();
svdUs[1].SetLabel(ori_labels);
Contract(T2,T2,svdUs[1],INPLACE);
//cout << T2;
}else{
ori_labels = svdUs[3].label();
new_bonds = svdUs[3].bond();
new_bonds[1] = Bond(BD_OUT, chi);
Resize(blk, svdUs[3].GetBlock(), svdUs[3].GetBlock().row(), chi, INPLACE);
svdUs[3].Assign(new_bonds);
svdUs[3].PutBlock(blk);
svdUs[3].SetLabel(ori_labels);
Contract(T2,T2,svdUs[3],INPLACE);
//cout << T2;
ori_labels = svdUs[1].label();
svdUs[3].SetLabel(ori_labels);
Contract(T2,T2,svdUs[3],INPLACE);
//cout << T2;
}
}
//void Utils::Update(const int dir,const unsigned int &chi,UniTensor<double> &T, Network &Nwrk){
void Utils::Update(const int dir,const unsigned int &chi,UniTensor<double> &T, Network &Nwrk){
vector<int> per_lbl;
if(dir == 0) per_lbl = vector<int>{0,1,3,4};
else per_lbl = vector<int>{4,0,1,3};
vector<int> groups(4,1);
vector<Matrix<double> > svdLs;
vector<UniTensor<double> > svdUs;
UniTensor<double> Core,T2;
double e1=0,e2=0;
//ContractArgs(T2,Nwrk,T,T);
//T2.CombineBond({1,2});
//T2.CombineBond({4,5});
ContractArgs(T2,Nwrk,T,T);
//cout << T2 << endl;
T2.CombineBond({1,2});
T2.CombineBond({4,5});
//Hosvd( T2, T2.label(), groups, svdUs, Core, svdLs, INPLACE);
//cout << "OK";
//exit(1);
///truncation :
if(T2.bond(1).dim() > chi){
Hosvd( T2, T2.label(), groups, svdUs, Core, svdLs, INPLACE);
//cout << "IN" << endl;
//cout << svdLs[1] << endl;
//exit(1);
for(unsigned int s=chi;s<svdUs[1].bond(1).dim();s++)
e1 += pow(svdLs[1][s],2);
for(unsigned int s=chi;s<svdUs[3].bond(1).dim();s++)
e2 += pow(svdLs[3][s],2);
//cout << e1 << " " << e2;
//exit(1);
if(e1<e2)
truncateLUs(0,chi,svdUs,T2);
else
truncateLUs(1,chi,svdUs,T2);
T2.SetLabel({0,3,1,4});
}
Permute(T2,per_lbl,2,INPLACE);
T.Assign(T2.bond());
T.PutBlock(T2.GetBlock());
}