1#ifndef VANILLA_VUMPS_MPO_TRANSFERMATRIX
2#define VANILLA_VUMPS_MPO_TRANSFERMATRIX
5#include "termcolor.hpp"
19template<
typename Symmetry,
typename Scalar>
25 const vector<vector<
Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > > &Abra_input,
26 const vector<vector<
Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > > &Aket_input,
27 const Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > &LReigen_input,
28 const vector<vector<vector<vector<
Biped<Symmetry,SparseMatrix<Scalar> > > > > > &W_input,
33 const vector<pair<qarray<Symmetry::Nq>,
size_t> > &basis_order_imput={})
41 vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > >
Abra;
42 vector<vector<Biped<Symmetry,Matrix<Scalar,Dynamic,Dynamic> > > >
Aket;
43 vector<vector<vector<vector<Biped<Symmetry, SparseMatrix<Scalar> > > > > >
W;
52 vector<vector<qarray<Symmetry::Nq> > >
qloc;
53 vector<vector<qarray<Symmetry::Nq> > >
qOp;
60template<
typename Symmetry,
typename Scalar_>
74 for (
size_t q=0; q<
data.dim; ++q)
76 if (
data.mid(q) ==
ab.first)
78 data.block[q][
ab.second][0] -= LRdotY * Matrix<Scalar,Dynamic,Dynamic>::Identity(
data.block[q][
ab.second][0].rows(),
data.block[q][
ab.second][0].cols());
85 pair<qarray<Symmetry::Nq>,
size_t>
ab;
98template<
typename Symmetry,
typename Scalar1,
typename Scalar2>
103 size_t Lcell = H.
W.size();
112 for (
int l=Lcell-1; l>=0; --l)
117 contract_R(R, H.
Abra[l], H.
W[l], H.
Aket[l], H.
qloc[l], H.
qOp[l], Rnext,
false, make_pair(
CONTRACT_LR_MODE::FIXED_ROWS,H.
ab), H.
basis_order_map);
121 contract_R(R, H.
Abra[l], H.
W[l], H.
Aket[l], H.
qloc[l], H.
qOp[l], Rnext,
false, make_pair(
CONTRACT_LR_MODE::FIXED_COLS,H.
ab), H.
basis_order_map);
139 for (
size_t l=0; l<Lcell; ++l)
144 contract_L(L, H.
Abra[l], H.
W[l], H.
Aket[l], H.
qloc[l], H.
qOp[l], Lnext,
false, make_pair(
CONTRACT_LR_MODE::FIXED_COLS,H.
ab), H.
basis_order_map);
148 contract_L(L, H.
Abra[l], H.
W[l], H.
Aket[l], H.
qloc[l], H.
qOp[l], Lnext,
false, make_pair(
CONTRACT_LR_MODE::FIXED_ROWS,H.
ab), H.
basis_order_map);
164 pair<qarray<Symmetry::Nq>,
size_t> ab_blocked = H.
basis_order[H.
ab];
175 for (
size_t q=0; q<TxV.
data.dim; ++q)
178 auto it = Vin.
data.dict.find(quple);
180 Matrix<Scalar2,Dynamic,Dynamic> Mtmp;
181 if (it != Vin.
data.dict.end())
183 Mtmp = Vin.
data.block[it->second][ab_blocked.second][0] - TxV.
data.block[q][ab_blocked.second][0];
184 Mtmp += LdotR * Matrix<Scalar2,Dynamic,Dynamic>::Identity(Vin.
data.block[it->second][ab_blocked.second][0].rows(),
185 Vin.
data.block[it->second][ab_blocked.second][0].cols());
188 if (Mtmp.size() != 0)
190 auto ip = Vout.
data.dict.find(quple);
191 if (ip != Vout.
data.dict.end())
193 if (Vout.
data.block[ip->second][ab_blocked.second][0].rows() != Mtmp.rows() or
194 Vout.
data.block[ip->second][ab_blocked.second][0].cols() != Mtmp.cols())
196 Vout.
data.block[ip->second][ab_blocked.second][0] = Mtmp;
200 Vout.
data.block[ip->second][ab_blocked.second][0] += Mtmp;
205 cout << termcolor::red <<
"push_back that shouldn't be" << termcolor::reset << endl;
206 boost::multi_array<Matrix<Scalar2,Dynamic,Dynamic>,
LEGLIMIT> Mtmpvec(boost::extents[H.
W[0][0][0][0].block[0].cols()][1]);
207 Mtmpvec[ab_blocked.second][0] = Mtmp;
208 Vout.
data.push_back(quple, Mtmpvec);
214template<
typename Symmetry,
typename Scalar1,
typename Scalar2>
222template<
typename Symmetry,
typename Scalar>
228template<
typename Symmetry,
typename Scalar>
232 for (
size_t q=0; q<V.
data.dim; ++q)
234 if (V.
data.mid(q) != V.
ab.first) {
continue;}
235 out += V.
data.block[q][V.
ab.second][0].size();
240template<
typename Symmetry,
typename Scalar>
246template<
typename Symmetry,
typename Scalar>
252template<
typename Symmetry,
typename Scalar>
258template<
typename Symmetry,
typename Scalar>
262 for (
size_t q=0; q<V1.
data.size(); ++q)
264 if (V1.
data.mid(q) != V1.
ab.first) {
continue;}
267 auto it = V2.
data.dict.find(quple);
268 if (it != V2.
data.dict.end())
270 if (V2.
data.mid(it->second) != V2.
ab.first) {
continue;}
271 res += (V1.
data.block[q][V1.
ab.second][0].adjoint() * V2.
data.block[it->second][V2.
ab.second][0]).trace() * Symmetry::coeff_dot(V2.
data.out(q));
277template<
typename Symmetry,
typename Scalar>
281 data.addScale(1.,Vrhs.
data);
296template<
typename Symmetry,
typename Scalar>
300 data.addScale(-1.,Vrhs.
data);
315template<
typename Symmetry,
typename Scalar>
316template<
typename OtherScalar>
320 for (
size_t q=0; q<data.dim; ++q)
322 if (data.mid(q) != ab.first) {
continue;}
323 data.block[q][ab.second][0] *= alpha;
328template<
typename Symmetry,
typename Scalar>
329template<
typename OtherScalar>
333 for (
size_t q=0; q<data.dim; ++q)
335 if (data.mid(q) != ab.first) {
continue;}
336 data.block[q][ab.second][0] /= alpha;
341template<
typename Symmetry,
typename Scalar,
typename OtherScalar>
347template<
typename Symmetry,
typename Scalar,
typename OtherScalar>
353template<
typename Symmetry,
typename Scalar,
typename OtherScalar>
361template<
typename Symmetry,
typename Scalar,
typename OtherScalar>
369template<
typename Symmetry,
typename Scalar>
375template<
typename Symmetry,
typename Scalar,
typename OtherScalar>
382template<
typename Symmetry,
typename Scalar>
387 for (
size_t q=0; q<Vout.
data.dim; ++q)
389 if (Vout.
data.mid(q) != Vout.
ab.first) {
continue;}
390 for (
size_t i=0; i<Vout.
data.block[q][Vout.
ab.second][0].rows(); ++i)
391 for (
size_t j=0; j<Vout.
data.block[q][Vout.
ab.second][0].cols(); ++j)
393 Vout.
data.block[q][Vout.
ab.second][0](i,j) = threadSafeRandUniform<Scalar>(-1.,1.);
void normalize(PivotVector< Symmetry, Scalar_ > &V)
void addScale(const OtherScalar alpha, const MpoTransferVector< Symmetry, Scalar > &Vin, MpoTransferVector< Symmetry, Scalar > &Vout)
MpoTransferVector< Symmetry, Scalar > operator*(const OtherScalar &alpha, MpoTransferVector< Symmetry, Scalar > V)
Scalar dot(const MpoTransferVector< Symmetry, Scalar > &V1, const MpoTransferVector< Symmetry, Scalar > &V2)
double squaredNorm(const MpoTransferVector< Symmetry, Scalar > &V)
MpoTransferVector< Symmetry, Scalar > operator/(MpoTransferVector< Symmetry, Scalar > V, const OtherScalar &alpha)
double norm(const MpoTransferVector< Symmetry, Scalar > &V)
MpoTransferVector< Symmetry, Scalar > operator+(const MpoTransferVector< Symmetry, Scalar > &V1, const MpoTransferVector< Symmetry, Scalar > &V2)
void normalize(MpoTransferVector< Symmetry, Scalar > &V)
void setZero(MpoTransferVector< Symmetry, Scalar > &V)
size_t dim(const MpoTransferMatrix< Symmetry, Scalar > &H)
MpoTransferVector< Symmetry, Scalar > operator-(const MpoTransferVector< Symmetry, Scalar > &V1, const MpoTransferVector< Symmetry, Scalar > &V2)
void contract_R(const Tripod< Symmetry, MatrixType2 > &Rold, const vector< Biped< Symmetry, MatrixType > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, MatrixType > > &Aket, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp, Tripod< Symmetry, MatrixType2 > &Rnew, bool RANDOMIZE=false, tuple< CONTRACT_LR_MODE, size_t > MODE_input=make_pair(FULL, 0), const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map={})
void contract_L(const Tripod< Symmetry, MatrixType2 > &Lold, const vector< Biped< Symmetry, MatrixType > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, MatrixType > > &Aket, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp, Tripod< Symmetry, MatrixType2 > &Lnew, bool RANDOMIZE=false, tuple< CONTRACT_LR_MODE, size_t > MODE_input=make_pair(FULL, 0), const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map={})
Scalar contract_LR(const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &L, const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &Aket, const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &R, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp)
void HxV(const MpoTransferMatrix< Symmetry, Scalar1 > &H, const MpoTransferVector< Symmetry, Scalar2 > &Vin, MpoTransferVector< Symmetry, Scalar2 > &Vout)
std::array< qarray< Nq >, 3 > qarray3
static void fill(size_t N, MpoTransferVector< Symmetry, Scalar > &Vout)
vector< pair< qarray< Symmetry::Nq >, size_t > > basis_order
vector< vector< vector< vector< Biped< Symmetry, SparseMatrix< Scalar > > > > > > W
vector< vector< qarray< Symmetry::Nq > > > qOp
MpoTransferMatrix(VMPS::DIRECTION::OPTION DIR_input, const vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > &Abra_input, const vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > &Aket_input, const Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &LReigen_input, const vector< vector< vector< vector< Biped< Symmetry, SparseMatrix< Scalar > > > > > > &W_input, const vector< vector< qarray< Symmetry::Nq > > > &qloc_input, const vector< vector< qarray< Symmetry::Nq > > > &qOp_input, size_t ab_input, const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map_input={}, const vector< pair< qarray< Symmetry::Nq >, size_t > > &basis_order_imput={})
VMPS::DIRECTION::OPTION DIR
vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > Abra
std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > basis_order_map
vector< vector< qarray< Symmetry::Nq > > > qloc
vector< vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > > Aket
Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > LReigen
MpoTransferVector< Symmetry, Scalar > & operator-=(const MpoTransferVector< Symmetry, Scalar > &Vrhs)
MpoTransferVector< Symmetry, Scalar > & operator/=(const OtherScalar &alpha)
Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > data
pair< qarray< Symmetry::Nq >, size_t > ab
MpoTransferVector< Symmetry, Scalar > & operator*=(const OtherScalar &alpha)
MpoTransferVector< Symmetry, Scalar > & operator+=(const MpoTransferVector< Symmetry, Scalar > &Vrhs)
MpoTransferVector(const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &T, const pair< qarray< Symmetry::Nq >, size_t > &ab_input, const Scalar &LRdotY=0.)