34 template<
class Matrix,
class SymmGroup>
37 std::ostringstream oss;
38 for (
int i = 0; i < length(); ++i)
40 oss <<
"MPS site " << i << std::endl;
41 oss << (*this)[i].row_dim() << std::endl;
42 oss <<
"Sum: " << (*this)[i].row_dim().sum_of_sizes() << std::endl;
43 oss << (*this)[i].col_dim() << std::endl;
44 oss <<
"Sum: " << (*this)[i].col_dim().sum_of_sizes() << std::endl;
49 template<
class Matrix,
class SymmGroup>
51 : canonized_i(std::numeric_limits<
size_t>::max())
54 template<
class Matrix,
class SymmGroup>
57 , canonized_i(std::numeric_limits<
size_t>::max())
60 template<
class Matrix,
class SymmGroup>
63 , canonized_i(std::numeric_limits<
size_t>::max())
78 template<
class Matrix,
class SymmGroup>
82 template<
class Matrix,
class SymmGroup>
86 canonized_i=std::numeric_limits<size_t>::max();
90 template<
class Matrix,
class SymmGroup>
94 canonized_i=std::numeric_limits<size_t>::max();
98 template<
class Matrix,
class SymmGroup>
104 size_t center = ((*this)[0].isleftnormalized()) ? 1 : 0;
105 for (
size_t i=1; i<length(); ++i) {
106 if (!(*
this)[i].isnormalized() && center != i) {
107 canonized_i = std::numeric_limits<size_t>::max();
109 }
else if ((*
this)[i].isleftnormalized() && center == i)
111 else if ((*
this)[i].isleftnormalized()) {
112 canonized_i = std::numeric_limits<size_t>::max();
116 if (center == length())
119 canonized_i = center;
123 template<
class Matrix,
class SymmGroup>
126 canonize(length()-1);
130 canonized_i = length()-1;
133 template<
class Matrix,
class SymmGroup>
146 template<
class Matrix,
class SymmGroup>
149 if (canonized_i == center)
152 if (canonized_i < center)
153 move_normalization_l2r(canonized_i, center, method);
154 else if (canonized_i < length())
155 move_normalization_r2l(canonized_i, center, method);
157 move_normalization_l2r(0, center, method);
158 move_normalization_r2l(length()-1, center, method);
160 canonized_i = center;
166 template<
class Matrix,
class SymmGroup>
169 size_t tmp_i = canonized_i;
170 for (
int i = p1; i < std::min(p2, length()); ++i)
172 if ((*
this)[i].isleftnormalized())
175 if (i < length()-1) {
176 (*this)[i+1].multiply_from_left(t);
177 (*this)[i+1].divide_by_scalar((*
this)[i+1].scalar_norm());
183 canonized_i = std::numeric_limits<size_t>::max();
189 template<
class Matrix,
class SymmGroup>
192 size_t tmp_i = canonized_i;
193 for (
int i = p1; i >
static_cast<int>(std::max(p2,
size_t(0))); --i)
195 if ((*
this)[i].isrightnormalized())
199 (*this)[i-1].multiply_from_right(t);
200 (*this)[i-1].divide_by_scalar((*
this)[i-1].scalar_norm());
206 canonized_i = std::numeric_limits<size_t>::max();
209 template<
class Matrix,
class SymmGroup>
210 template<
class OtherMatrix>
215 std::size_t l,
double alpha,
216 double cutoff, std::size_t Mmax)
221 boost::tie(new_mps, trunc) =
225 (*
this)[l], new_mps);
226 (*this)[l] = new_mps;
230 template<
class Matrix,
class SymmGroup>
231 template<
class OtherMatrix>
236 std::size_t l,
double alpha,
237 double cutoff, std::size_t Mmax)
242 boost::tie(new_mps, trunc) =
246 (*
this)[l], new_mps);
247 (*this)[l] = new_mps;
251 template<
class Matrix,
class SymmGroup>
258 for(std::size_t k(0); k < ret[0].n_blocks(); ++k)
264 template<
class Matrix,
class SymmGroup>
275 for(std::size_t k(0); k < ret[0].n_blocks(); ++k)
281 template<
class Matrix,
class SymmGroup>
284 typedef typename SymmGroup::charge charge;
288 charge diff = SymmGroup::IdentityCharge;
291 for (
size_t n=0; n< op.
n_blocks(); ++n) {
293 throw std::runtime_error(
"Operator not allowed. All non-zero blocks have to provide same `diff`.");
300 for (
size_t i=p+1; i<length(); ++i) {
301 (*this)[i].shift_aux_charges(diff);
305 template<
class Matrix,
class SymmGroup>
308 for (
size_t i=0; i<p; ++i) {
314 template<
class Matrix,
class SymmGroup>
319 while (boost::filesystem::exists( dirname +
"/mps" + boost::lexical_cast<std::string>(++L) +
".h5" ));
323 size_t loop_max = tmp.
length();
325 std::string fname = dirname+
"/mps"+boost::lexical_cast<std::string>((size_t)k)+
".h5";
327 ar[
"/tensor"] >> tmp[k];
332 template<
class Matrix,
class SymmGroup>
335 size_t loop_max = mps.
length();
337 const std::string fname = dirname+
"/mps"+boost::lexical_cast<std::string>((size_t)k)+
".h5.new";
339 ar[
"/tensor"] << mps[k];
342 const std::string fname = dirname+
"/mps"+boost::lexical_cast<std::string>((size_t)k)+
".h5";
343 boost::filesystem::rename(fname+
".new", fname);
347 template <
class Matrix,
class SymmGroup>
352 throw std::runtime_error(
"Length doesn't match.");
354 for (
int i=0; i<mps1.
length(); ++i)
356 mps1[i].check_equal(mps2[i]);
357 }
catch (std::exception & e) {
358 maquis::cerr <<
"Problem on site " << i <<
":" << e.what() << std::endl;
void move_normalization_l2r(size_t p1, size_t p2, DecompMethod method=DefaultSolver())
static MPSTensor< Matrix, SymmGroup > predict_lanczos_l2r_sweep(MPSTensor< Matrix, SymmGroup > B, MPSTensor< Matrix, SymmGroup > const &psi, MPSTensor< Matrix, SymmGroup > const &A)
void move_normalization_r2l(size_t p1, size_t p2, DecompMethod method=DefaultSolver())
truncation_results grow_r2l_sweep(MPOTensor< Matrix, SymmGroup > const &mpo, Boundary< OtherMatrix, SymmGroup > const &left, Boundary< OtherMatrix, SymmGroup > const &right, std::size_t l, double alpha, double cutoff, std::size_t Mmax)
size_type n_blocks() const
declaration of the MPS class (vector of MPSTensor)
void check_equal_mps(MPS< Matrix, SymmGroup > const &mps1, MPS< Matrix, SymmGroup > const &mps2)
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
void save(std::string const &dirname, MPS< Matrix, SymmGroup > const &mps)
Boundary< Matrix, SymmGroup > left_boundary() const
size_t canonization(bool=false) const
data_t::size_type size_type
Boundary< Matrix, SymmGroup > right_boundary() const
#define semi_parallel_for(constraint,...)
static std::pair< MPSTensor< Matrix, SymmGroup >, truncation_results > predict_new_state_l2r_sweep(MPSTensor< Matrix, SymmGroup > const &mps, MPOTensor< Matrix, SymmGroup > const &mpo, Boundary< OtherMatrix, SymmGroup > const &left, Boundary< OtherMatrix, SymmGroup > const &right, double alpha, double cutoff, std::size_t Mmax)
data_t::value_type value_type
#define parallel_for(constraint,...)
void apply(block_matrix< Matrix, SymmGroup > const &, size_type)
void left_right_boundary_init(alps::numeric::matrix< T, A > &M)
static MPSTensor< Matrix, SymmGroup > multiply_with_op(MPSTensor< Matrix, SymmGroup > const &mps, block_matrix< Matrix, SymmGroup > const &op)
static std::pair< MPSTensor< Matrix, SymmGroup >, truncation_results > predict_new_state_r2l_sweep(MPSTensor< Matrix, SymmGroup > const &mps, MPOTensor< Matrix, SymmGroup > const &mpo, Boundary< OtherMatrix, SymmGroup > const &left, Boundary< OtherMatrix, SymmGroup > const &right, double alpha, double cutoff, std::size_t Mmax)
Index< SymmGroup > const & right_basis() const
std::string description() const
void canonize(size_t center, DecompMethod method=DefaultSolver())
void load(std::string const &dirname, MPS< Matrix, SymmGroup > &mps)
value_type const & operator[](size_t i) const
static MPSTensor< Matrix, SymmGroup > predict_lanczos_r2l_sweep(MPSTensor< Matrix, SymmGroup > B, MPSTensor< Matrix, SymmGroup > const &psi, MPSTensor< Matrix, SymmGroup > const &A)
Index< SymmGroup > const & left_basis() const
truncation_results grow_l2r_sweep(MPOTensor< Matrix, SymmGroup > const &mpo, Boundary< OtherMatrix, SymmGroup > const &left, Boundary< OtherMatrix, SymmGroup > const &right, std::size_t l, double alpha, double cutoff, std::size_t Mmax)
functions to contract tensor network states
T fuse(const A &ind, T d)
Fuse indices n[i] into one p = n[i] d^i.