Xped
Loading...
Searching...
No Matches
iPEPS.hpp
Go to the documentation of this file.
1#ifndef XPED_IPEPS_H_
2#define XPED_IPEPS_H_
3
4#include "yas/serialize.hpp"
5#include "yas/std_types.hpp"
6
10#include "Xped/PEPS/TMatrix.hpp"
14
15namespace Xped {
16
17template <typename, typename, bool>
18struct OneSiteObservable;
19template <typename, typename, bool>
20struct TwoSiteObservable;
21
22template <typename, typename, std::size_t, bool, Opts::CTMCheckpoint>
23class CTM;
37template <typename Scalar_, typename Symmetry_, bool ENABLE_AD_ = false>
38class iPEPS
39{
40 template <typename Scalar__,
41 typename Symmetry__,
42 std::size_t TRank__,
43 bool ENABLE_AD__,
44 Opts::CTMCheckpoint CPOpts__,
45 typename OpScalar__,
46 bool HERMITIAN__>
49
50 template <typename Scalar__,
51 typename Symmetry__,
52 std::size_t TRank__,
53 bool ENABLE_AD__,
54 Opts::CTMCheckpoint CPOpts__,
55 typename OpScalar__,
56 bool HERMITIAN__>
57 friend std::array<
59 4>
61
62 template <typename, typename, std::size_t, bool, Opts::CTMCheckpoint>
63 friend class CTM;
64
65 template <typename, typename, typename>
66 friend class TimePropagator;
67
68 friend class iPEPS<Scalar_, Symmetry_, true>;
69
70public:
71 typedef Symmetry_ Symmetry;
72 typedef Scalar_ Scalar;
73 static constexpr bool ENABLE_AD = ENABLE_AD_;
75 typedef typename Symmetry::qType qType;
76
77 iPEPS() = default;
78
79 iPEPS(const UnitCell& cell, std::size_t D, const Qbasis<Symmetry, 1>& auxBasis, const Qbasis<Symmetry, 1>& physBasis);
80
81 iPEPS(const UnitCell& cell,
82 std::size_t D,
83 const TMatrix<Qbasis<Symmetry, 1>>& leftBasis,
84 const TMatrix<Qbasis<Symmetry, 1>>& topBasis,
85 const TMatrix<Qbasis<Symmetry, 1>>& physBasis);
86
87 iPEPS(const UnitCell& cell,
88 std::size_t D,
89 const TMatrix<Qbasis<Symmetry, 1>>& leftBasis,
90 const TMatrix<Qbasis<Symmetry, 1>>& topBasis,
91 const TMatrix<Qbasis<Symmetry, 1>>& physBasis,
92 const TMatrix<qType>& charges);
93
95
96 void setRandom(std::size_t seed = 0ul);
97 void setZero();
98
99 void set_As(const std::vector<Tensor<Scalar, 2, 3, Symmetry, ENABLE_AD>>& As_in)
100 {
101 As.fill(As_in);
102 for(auto i = 0ul; i < As.size(); ++i) { Adags[i] = As[i].adjoint().eval().template permute<0, 3, 4, 2, 0, 1>(); }
103 }
104
105 Qbasis<Symmetry, 1> ketBasis(const int x, const int y, const Opts::LEG leg) const;
106 Qbasis<Symmetry, 1> braBasis(const int x, const int y, const Opts::LEG leg) const;
107
108 std::string info() const;
109 void debug_info() const;
110
111 std::vector<Scalar> data();
112
113 void set_data(const Scalar* data, bool NORMALIZE = true);
114
115 std::size_t plainSize() const;
116
118 {
119 iPEPSIterator<Scalar, Symmetry, ENABLE_AD> out(&As, /*ITER_GRAD=*/false);
120 return out;
121 }
123 {
124 iPEPSIterator<Scalar, Symmetry, ENABLE_AD> out(&As, /*ITER_GRAD=*/false, As.size());
125 return out;
126 }
127
129 {
130 iPEPSIterator<Scalar, Symmetry, ENABLE_AD> out(&As, /*ITER_GRAD=*/true);
131 return out;
132 }
134 {
135 iPEPSIterator<Scalar, Symmetry, ENABLE_AD> out(&As, /*ITER_GRAD=*/true, As.size());
136 return out;
137 }
138
139 const UnitCell& cell() const { return cell_; }
140
141 const TMatrix<qType>& charges() const { return charges_; }
142
143 template <typename Ar>
144 void serialize(Ar& ar)
145 {
146 ar& YAS_OBJECT_NVP("iPEPS", ("D", D), ("cell", cell_), ("As", As), ("Adags", Adags), ("charges", charges_));
147 }
148
149 void loadFromMatlab(const std::filesystem::path& p, const std::string& root_name, int qn_scale = 1);
150
151 bool checkConsistency() const;
152
153 void initWeightTensors();
154 void updateAtensors();
155
158
159 std::tuple<std::size_t, std::size_t, double, double> calc_Ds() const;
160
161 std::size_t D;
162
163private:
164 void
165 init(const TMatrix<Qbasis<Symmetry, 1>>& leftBasis, const TMatrix<Qbasis<Symmetry, 1>>& topBasis, const TMatrix<Qbasis<Symmetry, 1>>& physBasis);
166
167 UnitCell cell_;
172
174 TMatrix<qType> charges_;
175};
176
177} // namespace Xped
178
179#ifndef XPED_COMPILED_LIB
180# include "PEPS/iPEPS.cpp"
181#endif
182
183#endif
Definition: CTM.hpp:62
Definition: Qbasis.hpp:39
Definition: Tensor.hpp:40
Definition: TimePropagator.hpp:25
Definition: iPEPSIterator.hpp:15
Definition: iPEPS.hpp:39
void updateAtensors()
Definition: iPEPS.cpp:341
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)
void initWeightTensors()
Definition: iPEPS.cpp:323
Qbasis< Symmetry, 1 > braBasis(const int x, const int y, const Opts::LEG leg) const
Definition: iPEPS.cpp:310
const TMatrix< qType > & charges() const
Definition: iPEPS.hpp:141
ScalarTraits< Scalar >::Real RealScalar
Definition: iPEPS.hpp:74
const UnitCell & cell() const
Definition: iPEPS.hpp:139
Tensor< Scalar, 1, 1, Symmetry > Id_weight_h(int x, int y) const
Definition: iPEPS.cpp:353
Symmetry::qType qType
Definition: iPEPS.hpp:75
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)
void debug_info() const
Definition: iPEPS.cpp:382
iPEPSIterator< Scalar, Symmetry, ENABLE_AD > gradbegin()
Definition: iPEPS.hpp:128
void setRandom(std::size_t seed=0ul)
Definition: iPEPS.cpp:217
std::string info() const
Definition: iPEPS.cpp:365
void set_data(const Scalar *data, bool NORMALIZE=true)
Definition: iPEPS.cpp:250
bool checkConsistency() const
Definition: iPEPS.cpp:177
iPEPSIterator< Scalar, Symmetry, ENABLE_AD > end()
Definition: iPEPS.hpp:122
void loadFromMatlab(const std::filesystem::path &p, const std::string &root_name, int qn_scale=1)
Definition: iPEPS.cpp:134
static constexpr bool ENABLE_AD
Definition: iPEPS.hpp:73
std::vector< Scalar > data()
Definition: iPEPS.cpp:241
std::tuple< std::size_t, std::size_t, double, double > calc_Ds() const
Definition: iPEPS.cpp:272
std::size_t D
Definition: iPEPS.hpp:161
Symmetry_ Symmetry
Definition: iPEPS.hpp:71
iPEPSIterator< Scalar, Symmetry, ENABLE_AD > gradend()
Definition: iPEPS.hpp:133
Tensor< Scalar, 1, 1, Symmetry > Id_weight_v(int x, int y) const
Definition: iPEPS.cpp:359
void setZero()
Definition: iPEPS.cpp:204
void set_As(const std::vector< Tensor< Scalar, 2, 3, Symmetry, ENABLE_AD > > &As_in)
Definition: iPEPS.hpp:99
iPEPSIterator< Scalar, Symmetry, ENABLE_AD > begin()
Definition: iPEPS.hpp:117
void serialize(Ar &ar)
Definition: iPEPS.hpp:144
Scalar_ Scalar
Definition: iPEPS.hpp:72
Qbasis< Symmetry, 1 > ketBasis(const int x, const int y, const Opts::LEG leg) const
Definition: iPEPS.cpp:297
std::size_t plainSize() const
Definition: iPEPS.cpp:233
iPEPS()=default
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