Xped
Loading...
Searching...
No Matches
CTM.hpp
Go to the documentation of this file.
1#ifndef XPED_CTM_H_
2#define XPED_CTM_H_
3
4#include <filesystem>
5#include <memory>
6
7#include "yas/serialize.hpp"
8#include "yas/std_types.hpp"
9
10#include "Xped/AD/ADTensor.hpp"
11#include "Xped/Core/Tensor.hpp"
12#include "Xped/PEPS/CTMOpts.hpp"
13#include "Xped/PEPS/TMatrix.hpp"
15#include "Xped/PEPS/iPEPS.hpp"
16
17namespace Xped {
18
19template <typename, typename, bool>
20struct OneSiteObservable;
21template <typename, typename, bool>
22struct TwoSiteObservable;
23
60template <typename Scalar_, typename Symmetry_, std::size_t TRank = 2, bool ENABLE_AD = false, Opts::CTMCheckpoint CPOpts = Opts::CTMCheckpoint{}>
61class CTM
62{
63 template <typename Scalar__,
64 typename Symmetry__,
65 std::size_t TRank__,
66 bool ENABLE_AD__,
67 Opts::CTMCheckpoint CPOpts__,
68 typename OpScalar__,
69 bool HERMITIAN__>
72
73 template <typename Scalar__,
74 typename Symmetry__,
75 std::size_t TRank__,
76 bool ENABLE_AD__,
77 Opts::CTMCheckpoint CPOpts__,
78 typename OpScalar__,
79 bool HERMITIAN__>
80 friend std::array<
82 4>
84
85 template <typename, typename, std::size_t, bool, Opts::CTMCheckpoint>
86 friend class CTM;
87
88public:
89 typedef Symmetry_ Symmetry;
90 typedef Scalar_ Scalar;
91
92 template <std::size_t N>
93 using cdims = std::array<int, N>;
94
95 CTM() = default;
96
97 explicit CTM(std::size_t chi, Opts::CTM_INIT init = Opts::CTM_INIT::FROM_A)
98 : chi_(chi)
99 , init_m(init)
100 {}
101
102 CTM(std::size_t chi, const UnitCell& cell, Opts::CTM_INIT init = Opts::CTM_INIT::FROM_A)
103 : cell_(cell)
104 , chi_(chi)
105 , init_m(init)
106 {}
107
108 CTM(std::shared_ptr<iPEPS<Scalar, Symmetry, ENABLE_AD>> A, std::size_t chi, const Opts::CTM_INIT init = Opts::CTM_INIT::FROM_A)
109 : A(A)
110 , cell_(A->cell())
111 , chi_(chi)
112 , init_m(init)
113 {}
114
115 // This is a copy constructor for non-AD CTM (CTM<Scalar, Symmetry, TRank, false>) so it prohibits implicitly declared move operations in this
116 // case...
118
119 void set_A(std::shared_ptr<iPEPS<Scalar, Symmetry, ENABLE_AD>> A_in)
120 {
121 A = A_in;
122 cell_ = A_in->cell();
123 if constexpr(TRank == 1) {
124 Ms.resize(cell_.pattern);
125 computeMs();
126 }
127 }
128
129 std::size_t fullChi() const { return C1s[0].uncoupledCodomain()[0].fullDim(); }
130
131 template <bool TRACK = ENABLE_AD>
132 void solve(std::size_t max_steps);
133
134 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.GROW_ALL>
135 void grow_all();
136
137 void init();
138 void loadFromMatlab(const std::filesystem::path& p, const std::string& root_name, int qn_scale = 1);
139
140 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.MOVE>
141 void left_move();
142 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.MOVE>
143 void right_move();
144 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.MOVE>
145 void top_move();
146 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.MOVE>
147 void bottom_move();
148 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.MOVE>
150
151 template <bool TRACK = ENABLE_AD>
152 void computeRDM();
153 bool RDM_COMPUTED() const { return HAS_RDM; }
154
155 void checkHermiticity() const;
156
157 auto info() const;
158
159 const UnitCell& cell() const { return cell_; }
160 const std::shared_ptr<iPEPS<Scalar, Symmetry, ENABLE_AD>>& Psi() const { return A; }
161
162 template <typename Ar>
163 void serialize(Ar& ar)
164 {
165 ar& YAS_OBJECT_NVP("CTM",
166 ("cell", cell_),
167 ("chi", chi_),
168 ("HAS_RDM", HAS_RDM),
169 ("C1s", C1s),
170 ("C2s", C2s),
171 ("C3s", C3s),
172 ("C4s", C4s),
173 ("T1s", T1s),
174 ("T2s", T2s),
175 ("T3s", T3s),
176 ("T4s", T4s),
177 // ("Ms", Ms),
178 ("rho_h", rho_h),
179 ("rho_v", rho_v),
180 ("rho1_h", rho1_h),
181 ("rho1_v", rho1_v));
182 }
183
184 std::size_t chi() const { return chi_; }
185
186 Opts::CTM_INIT const init_mode() { return init_m; }
187
188private:
189 std::shared_ptr<iPEPS<Scalar, Symmetry, ENABLE_AD>> A;
190 UnitCell cell_;
191 std::size_t chi_;
192 Opts::CTM_INIT init_m = Opts::CTM_INIT::FROM_A;
193 Opts::PROJECTION proj_m = Opts::PROJECTION::CORNER;
194 bool HAS_RDM = false;
195
204
206
208
213 TMatrix<double> rho_h_hermitian_check;
214 TMatrix<double> rho_v_hermitian_check;
215 TMatrix<double> rho1_h_hermitian_check;
216 TMatrix<double> rho1_v_hermitian_check;
217 // template <bool TRACK = ENABLE_AD>
218 // std::pair<Tensor<Scalar, 3, 3, Symmetry, TRACK>, Tensor<Scalar, 1, 1, Symmetry, TRACK>> get_projectors_left();
219
220 template <bool TRACK = ENABLE_AD>
221 void computeMs();
222
223 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.RDM>
224 void computeRDM_h();
225 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.RDM>
226 void computeRDM_v();
227
228 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.CORNER>
229 Tensor<Scalar, TRank + 1, TRank + 1, Symmetry, TRACK> contractCorner(const int x, const int y, const Opts::CORNER corner) XPED_CONST;
230
231 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.PROJECTORS>
232 std::pair<Tensor<Scalar, 1, TRank + 1, Symmetry, TRACK>, Tensor<Scalar, TRank + 1, 1, Symmetry, TRACK>>
233 get_projectors(const int x, const int y, const Opts::DIRECTION dir) XPED_CONST;
234
235 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.RENORMALIZE>
236 std::tuple<Tensor<Scalar, 0, 2, Symmetry, TRACK>, Tensor<Scalar, 1, TRank + 1, Symmetry, TRACK>, Tensor<Scalar, 1, 1, Symmetry, TRACK>>
237 renormalize_left(const int x,
238 const int y,
241 bool NORMALIZE = true) XPED_CONST;
242
243 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.RENORMALIZE>
244 std::tuple<Tensor<Scalar, 1, 1, Symmetry, TRACK>, Tensor<Scalar, TRank + 1, 1, Symmetry, TRACK>, Tensor<Scalar, 2, 0, Symmetry, TRACK>>
245 renormalize_right(const int x,
246 const int y,
247 XPED_CONST TMatrix<Tensor<Scalar, 1, TRank + 1, Symmetry, TRACK>>& P1,
248 XPED_CONST TMatrix<Tensor<Scalar, TRank + 1, 1, Symmetry, TRACK>>& P2,
249 bool NORMALIZE = true) XPED_CONST;
250
251 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.RENORMALIZE>
252 std::tuple<Tensor<Scalar, 0, 2, Symmetry, TRACK>, Tensor<Scalar, 1, TRank + 1, Symmetry, TRACK>, Tensor<Scalar, 1, 1, Symmetry, TRACK>>
253 renormalize_top(const int x,
254 const int y,
255 XPED_CONST TMatrix<Tensor<Scalar, 1, TRank + 1, Symmetry, TRACK>>& P1,
256 XPED_CONST TMatrix<Tensor<Scalar, TRank + 1, 1, Symmetry, TRACK>>& P2,
257 bool NORMALIZE = true) XPED_CONST;
258
259 template <bool TRACK = ENABLE_AD, bool CP = CPOpts.RENORMALIZE>
260 std::tuple<Tensor<Scalar, 1, 1, Symmetry, TRACK>, Tensor<Scalar, TRank + 1, 1, Symmetry, TRACK>, Tensor<Scalar, 2, 0, Symmetry, TRACK>>
261 renormalize_bottom(const int x,
262 const int y,
263 XPED_CONST TMatrix<Tensor<Scalar, 1, TRank + 1, Symmetry, TRACK>>& P1,
264 XPED_CONST TMatrix<Tensor<Scalar, TRank + 1, 1, Symmetry, TRACK>>& P2,
265 bool NORMALIZE = true) XPED_CONST;
266
267 bool checkConvergence(typename ScalarTraits<Scalar>::Real epsilon);
268};
269
270} // namespace Xped
271
272#ifndef XPED_COMPILED_LIB
273# include "PEPS/CTM.cpp"
274#endif
275
276#endif
Definition: CTM.hpp:62
const std::shared_ptr< iPEPS< Scalar, Symmetry, ENABLE_AD > > & Psi() const
Definition: CTM.hpp:160
void serialize(Ar &ar)
Definition: CTM.hpp:163
void left_move()
Definition: CTM.cpp:693
void symmetric_move()
friend class CTM
Definition: CTM.hpp:86
friend std::array< TMatrix< std::conditional_t< ENABLE_AD__, stan::math::var, typename TwoSiteObservable< OpScalar__, Symmetry__, HERMITIAN__ >::ObsScalar > >, 4 > avg(XPED_CONST CTM< Scalar__, Symmetry__, TRank__, ENABLE_AD__, CPOpts__ > &env, TwoSiteObservable< OpScalar__, Symmetry__, HERMITIAN__ > &op)
std::size_t chi() const
Definition: CTM.hpp:184
void right_move()
Definition: CTM.cpp:759
void set_A(std::shared_ptr< iPEPS< Scalar, Symmetry, ENABLE_AD > > A_in)
Definition: CTM.hpp:119
CTM(std::size_t chi, Opts::CTM_INIT init=Opts::CTM_INIT::FROM_A)
Definition: CTM.hpp:97
CTM(std::size_t chi, const UnitCell &cell, Opts::CTM_INIT init=Opts::CTM_INIT::FROM_A)
Definition: CTM.hpp:102
CTM()=default
auto info() const
Definition: CTM.cpp:376
void computeRDM()
Definition: CTM.cpp:367
Symmetry_ Symmetry
Definition: CTM.hpp:89
friend TMatrix< std::conditional_t< ENABLE_AD__, stan::math::var, typename OneSiteObservable< OpScalar__, Symmetry__, HERMITIAN__ >::ObsScalar > > avg(XPED_CONST CTM< Scalar__, Symmetry__, TRank__, ENABLE_AD__, CPOpts__ > &env, OneSiteObservable< OpScalar__, Symmetry__, HERMITIAN__ > &op)
std::size_t fullChi() const
Definition: CTM.hpp:129
Scalar_ Scalar
Definition: CTM.hpp:90
void grow_all()
Definition: CTM.cpp:333
void top_move()
Definition: CTM.cpp:824
const UnitCell & cell() const
Definition: CTM.hpp:159
void loadFromMatlab(const std::filesystem::path &p, const std::string &root_name, int qn_scale=1)
Definition: CTM.cpp:199
CTM(std::shared_ptr< iPEPS< Scalar, Symmetry, ENABLE_AD > > A, std::size_t chi, const Opts::CTM_INIT init=Opts::CTM_INIT::FROM_A)
Definition: CTM.hpp:108
void solve(std::size_t max_steps)
Definition: CTM.cpp:319
void bottom_move()
Definition: CTM.cpp:889
bool RDM_COMPUTED() const
Definition: CTM.hpp:153
void init()
Definition: CTM.cpp:45
void checkHermiticity() const
Definition: CTM.cpp:401
std::array< int, N > cdims
Definition: CTM.hpp:93
Opts::CTM_INIT const init_mode()
Definition: CTM.hpp:186
Definition: Tensor.hpp:40
Definition: iPEPS.hpp:39
Definition: bench.cpp:62
Definition: OneSiteObservable.hpp:21
Definition: CTMOpts.hpp:96
Definition: ScalarTraits.hpp:10
Definition: TMatrix.hpp:13
Definition: TwoSiteObservable.hpp:22
Definition: UnitCell.hpp:15
Pattern pattern
Definition: UnitCell.hpp:27