1#ifndef UMPS_COMPRESSOR_H_
2#define UMPS_COMPRESSOR_H_
5#include "termcolor.hpp"
21template<
typename Symmetry,
typename Scalar,
typename MpoScalar=
double>
38 double memory (MEMUNIT memunit=GB)
const;
54 size_t Dinit_input,
size_t Qinit_input,
double tol_input,
size_t max_iterations=100ul,
size_t min_iterations=10ul);
62 vector<PivotOverlap1<Symmetry,Scalar> >
Env;
83template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
88 ss <<
"UmpsCompressor: ";
89 ss <<
"Dinit=" << Dinit <<
", ";
100 ss <<
"|AL*C-AC/λ|^2=";
101 if (err_var <= tol) {ss << termcolor::colorize << termcolor::green;}
102 else {ss << termcolor::colorize << termcolor::red;}
103 ss << err_var << termcolor::reset <<
", ";
104 ss <<
"iterations=" << N_iterations <<
", ";
105 ss <<
"mem=" << round(memory(GB),3) <<
"GB";
109template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
111memory (MEMUNIT memunit)
const
114 for (
size_t l=0; l<Env.size(); ++l)
116 res += Env[l].L.memory(memunit);
117 res += Env[l].R.memory(memunit);
119 for (
size_t l=0; l<Env.size(); ++l)
121 res += Env[l].L.memory(memunit);
122 res += Env[l].R.memory(memunit);
127template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
130 size_t Dinit_input,
size_t Qinit_input,
double tol_input,
size_t max_iterations,
size_t min_iterations)
148 Env[N_sites-1].R.setRandom(Vin.
outBasis(N_sites-1), Vout.
outBasis(N_sites-1));
149 for (
size_t l=0; l<N_sites; ++l)
155 while ((err_var > tol and N_iterations < max_iterations) or N_iterations < min_iterations or N_iterations%2 != 0)
157 optimize_parallel(Vin,Vout);
161template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
169 for (
size_t l=1; l<N_sites; ++l)
173 Env[l-1].qloc, Env[l].L);
176 for (
int l=N_sites-2; l>=0; --l)
180 Env[l+1].qloc, Env[l].R);
185template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
189 vector<vector<qarray<Symmetry::Nq> > > qloc_complete(N_sites);
190 for (
size_t loc=0; loc<N_sites; loc++) { qloc_complete[loc] = Env[loc].qloc; }
193 Scalar eigval_dump=0.;
194 Scalar eigval_used=0.;
199 t_fixedR = FixedR.time();
202 t_fixedL = FixedL.time();
205 lout <<
"right fixed point (t=" << round(t_fixedR,2) <<
"): " << John.info() << endl;
206 lout <<
"left fixed point (t=" << round(t_fixedL,2) <<
"): " << Lucy.info() << endl;
212 Env[0].L = xL.
data[0];
213 Env[N_sites-1].R = xR.
data[0];
214 lambdaL = eigval_used;
217template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
221 Stopwatch<> IterationTimer;
223 build_cellEnv(Vin, Vout);
224 for (
size_t loc=0; loc<N_sites; ++loc)
227 for(
size_t s=0; s<Env[loc].qloc.size(); s++)
232 Vout.
C[loc] = Env[loc].L * Vin.
C[loc] * Env[loc].R;
236 for (
size_t loc=0; loc<N_sites; ++loc)
249 size_t standard_precision = cout.precision();
251 lout <<
"S=" << Vout.
entropy().transpose() << endl;
252 lout << info() << endl;
253 lout << Vout.
info() << endl;
254 lout << IterationTimer.info(
"full parallel iteration") << endl;
259template<
typename Symmetry,
typename Scalar,
typename MpoScalar>
264 for (
size_t loc=0; loc<N_sites; loc++)
265 for (
size_t s=0; s<Env[loc].qloc.size(); s++)
267 err_var += (Vout.
A[
GAUGE::L][loc][s] * Vout.
C[loc] - ( (1./lambdaL) * Vout.
A[
GAUGE::C][loc][s] )).
norm().sum();
double norm(const PivotMatrix0< Symmetry, Scalar, MpoScalar > &H)
void build_LR(const Umps< Symmetry, Scalar > &Vbra, const Umps< Symmetry, Scalar > &Vket)
UmpsCompressor(DMRG::VERBOSITY::OPTION VERBOSITY=DMRG::VERBOSITY::SILENT)
DMRG::VERBOSITY::OPTION CHOSEN_VERBOSITY
void stateCompress(const Umps< Symmetry, Scalar > &Vin, Umps< Symmetry, Scalar > &Vout, size_t Dinit_input, size_t Qinit_input, double tol_input, size_t max_iterations=100ul, size_t min_iterations=10ul)
void build_cellEnv(const Umps< Symmetry, Scalar > &Vbra, const Umps< Symmetry, Scalar > &Vket)
double memory(MEMUNIT memunit=GB) const
complex< double > lambdaL
vector< PivotOverlap1< Symmetry, Scalar > > Env
void optimize_parallel(const Umps< Symmetry, Scalar > &Vin, Umps< Symmetry, Scalar > &Vout)
void calc_error(const Umps< Symmetry, Scalar > &Vout)
size_t minus1modL(size_t l) const
vector< qarray< Symmetry::Nq > > locBasis(size_t loc) const
Qbasis< Symmetry > inBasis(size_t loc) const
void svdDecompose(size_t loc, GAUGE::OPTION gauge=GAUGE::C)
void polarDecompose(size_t loc, GAUGE::OPTION gauge=GAUGE::C)
void calc_entropy(size_t loc, bool PRINT=false)
qarray< Nq > Qtarget() const
Qbasis< Symmetry > outBasis(size_t loc) const
string test_ortho(double tol=1e-6) const
std::array< vector< vector< Biped< Symmetry, MatrixType > > >, 3 > A
vector< Biped< Symmetry, MatrixType > > C
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={})
Biped< Symmetry, Matrix< Scalar_, Dynamic, Dynamic > > data