ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
MPSTensor< Matrix, SymmGroup > Class Template Reference

#include <mpstensor.h>

Public Types

typedef
maquis::traits::scalar_type
< Matrix >::type 
scalar_type
 
typedef
maquis::traits::real_type
< Matrix >::type 
real_type
 
typedef Matrix::value_type value_type
 
typedef double magnitude_type
 
typedef std::size_t size_type
 

Public Member Functions

 MPSTensor (Index< SymmGroup > const &sd=Index< SymmGroup >(), Index< SymmGroup > const &ld=Index< SymmGroup >(), Index< SymmGroup > const &rd=Index< SymmGroup >(), bool fillrand=true, value_type val=0)
 
 MPSTensor (Index< SymmGroup > const &sd, Index< SymmGroup > const &ld, Index< SymmGroup > const &rd, block_matrix< Matrix, SymmGroup > const &block, MPSStorageLayout layout)
 
Index< SymmGroup > const & site_dim () const
 
Index< SymmGroup > const & row_dim () const
 
Index< SymmGroup > const & col_dim () const
 
bool isobccompatible (Indicator) const
 
std::size_t num_elements () const
 
void replace_right_paired (block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
 
void replace_left_paired (block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
 
bool isleftnormalized (bool test=false) const
 
bool isrightnormalized (bool test=false) const
 
bool isnormalized (bool test=false) const
 
block_matrix< Matrix, SymmGroup > normalize_left (DecompMethod method=DefaultSolver(), bool multiplied=true, double truncation=0, Index< SymmGroup > bond_dim=Index< SymmGroup >())
 
block_matrix< Matrix, SymmGroup > normalize_right (DecompMethod method=DefaultSolver(), bool multiplied=true, double truncation=0, Index< SymmGroup > bond_dim=Index< SymmGroup >())
 
void shift_aux_charges (typename SymmGroup::charge)
 
void multiply_from_left (block_matrix< Matrix, SymmGroup > const &)
 
void multiply_from_right (block_matrix< Matrix, SymmGroup > const &)
 
void multiply_by_scalar (const scalar_type &)
 
void divide_by_scalar (const scalar_type &)
 
scalar_type scalar_overlap (MPSTensor const &) const
 
real_type scalar_norm () const
 
MPSTensor copy () const
 
block_matrix< Matrix, SymmGroup > & data ()
 
block_matrix< Matrix,
SymmGroup > const & 
data () const
 
block_matrix< Matrix,
SymmGroup > const & 
const_data () const
 
std::vector< block_matrix
< Matrix, SymmGroup > > 
to_list () const
 
MPSTensor const & operator*= (const scalar_type &)
 
MPSTensor const & operator/= (const scalar_type &)
 
MPSTensor const & operator+= (MPSTensor const &)
 
MPSTensor const & operator-= (MPSTensor const &)
 
void make_left_paired () const
 
void make_right_paired () const
 
void conjugate_inplace ()
 
void swap_with (MPSTensor &b)
 
template<class Archive >
void load (Archive &ar)
 
template<class Archive >
void save (Archive &ar) const
 
void check_equal (MPSTensor< Matrix, SymmGroup > const &) const
 
bool reasonable () const
 
bool num_check () const
 

Public Attributes

Index< SymmGroup > phys_i
 
Index< SymmGroup > left_i
 
Index< SymmGroup > right_i
 

Friends

template<class Matrix_ , class SymmGroup_ >
std::ostream & operator<< (std::ostream &, MPSTensor< Matrix_, SymmGroup_ > const &)
 
void swap (MPSTensor &a, MPSTensor &b)
 
template<class Matrix_ , class SymmGroup_ >
MPSTensor< Matrix_, SymmGroup_ > join (MPSTensor< Matrix_, SymmGroup_ > const &, MPSTensor< Matrix_, SymmGroup_ > const &, boundary_flag_t)
 

Detailed Description

template<class Matrix, class SymmGroup>
class MPSTensor< Matrix, SymmGroup >

Definition at line 49 of file mpstensor.h.

Member Typedef Documentation

template<class Matrix, class SymmGroup>
typedef double MPSTensor< Matrix, SymmGroup >::magnitude_type

Definition at line 55 of file mpstensor.h.

template<class Matrix, class SymmGroup>
typedef maquis::traits::real_type<Matrix>::type MPSTensor< Matrix, SymmGroup >::real_type

Definition at line 53 of file mpstensor.h.

template<class Matrix, class SymmGroup>
typedef maquis::traits::scalar_type<Matrix>::type MPSTensor< Matrix, SymmGroup >::scalar_type

Definition at line 52 of file mpstensor.h.

template<class Matrix, class SymmGroup>
typedef std::size_t MPSTensor< Matrix, SymmGroup >::size_type

Definition at line 56 of file mpstensor.h.

template<class Matrix, class SymmGroup>
typedef Matrix::value_type MPSTensor< Matrix, SymmGroup >::value_type

Definition at line 54 of file mpstensor.h.

Constructor & Destructor Documentation

template<class Matrix , class SymmGroup>
MPSTensor< Matrix, SymmGroup >::MPSTensor ( Index< SymmGroup > const &  sd = Index<SymmGroup>(),
Index< SymmGroup > const &  ld = Index<SymmGroup>(),
Index< SymmGroup > const &  rd = Index<SymmGroup>(),
bool  fillrand = true,
typename Matrix::value_type  val = 0 
)

Definition at line 43 of file mpstensor.hpp.

48 : phys_i(sd)
49 , left_i(ld)
50 , right_i(rd)
51 , cur_storage(LeftPaired)
52 , cur_normalization(Unorm)
53 {
54  Index<SymmGroup> lb = sd*ld, rb = rd;
55  common_subset(lb, rb);
56 
57  // remove blocks from the right index that may not be allowed by the left index
58  right_i = rb;
59  // remove blocks from the left index that may not be allowed by the right index
60  Index<SymmGroup> possible_rp = adjoin(phys_i)*right_i, ltemp = ld;
61  common_subset(ltemp, possible_rp);
62  left_i = ltemp;
63 
64  // this is safe, since sd \otimes ld = rd forces the block_matrix to be diagonal
65  lb.sort();
66  rb.sort();
67  left_i.sort();
68  right_i.sort();
69 
71 
72  if (fillrand)
73  data().generate(static_cast<dmrg_random::value_type(*)()>(&dmrg_random::uniform));
74  else
76 }
void sort()
double value_type
Definition: random.hpp:33
block_matrix< Matrix, SymmGroup > adjoin(block_matrix< Matrix, SymmGroup > const &m)
static value_type uniform()
Definition: random.hpp:47
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
Index< SymmGroup > common_subset(Index< SymmGroup > &a, Index< SymmGroup > &b)
template<class Matrix, class SymmGroup>
MPSTensor< Matrix, SymmGroup >::MPSTensor ( Index< SymmGroup > const &  sd,
Index< SymmGroup > const &  ld,
Index< SymmGroup > const &  rd,
block_matrix< Matrix, SymmGroup > const &  block,
MPSStorageLayout  layout 
)

Definition at line 79 of file mpstensor.hpp.

84 : phys_i(sd)
85 , left_i(ld)
86 , right_i(rd)
87 , data_(block)
88 , cur_storage(layout)
89 , cur_normalization(Unorm)
90 {
91  if (cur_storage == LeftPaired) {
92  Index<SymmGroup> new_right_i = data_.right_basis();
93  Index<SymmGroup> possible_left_i = adjoin(phys_i)*new_right_i;
94  Index<SymmGroup> old_left_i = left_i;
95 
96  common_subset(old_left_i, possible_left_i);
97 
98  swap(right_i, new_right_i);
99  swap(left_i, old_left_i);
100  } else {
101  Index<SymmGroup> new_left_i = data_.left_basis();
102  Index<SymmGroup> possible_right_i = phys_i*new_left_i;
103  Index<SymmGroup> old_right_i = right_i;
104 
105  common_subset(old_right_i, possible_right_i);
106 
107  swap(left_i, new_left_i);
108  swap(right_i, old_right_i);
109  }
110 }
block_matrix< Matrix, SymmGroup > adjoin(block_matrix< Matrix, SymmGroup > const &m)
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
Index< SymmGroup > right_i
Definition: mpstensor.h:141
Index< SymmGroup > common_subset(Index< SymmGroup > &a, Index< SymmGroup > &b)

Member Function Documentation

template<class Matrix, class SymmGroup>
void MPSTensor< Matrix, SymmGroup >::check_equal ( MPSTensor< Matrix, SymmGroup > const &  rhs) const

Definition at line 596 of file mpstensor.hpp.

597 {
598  std::string error;
599  // Indexes
600 
601  try {
602  reasonable();
603  } catch (std::exception & e) {
604  error += "I'm unreasonable. " + std::string(e.what());
605  }
606  try {
607  rhs.reasonable();
608  } catch (std::exception & e) {
609  error += "He's unreasonable. " + std::string(e.what());
610  }
611 
612  // Storage
613 // if (cur_storage != rhs.cur_storage)
614 // error += "Storage doesn't match. ";
615 
617  rhs.make_left_paired();
618 
619  // Data
620  if (data().n_blocks() != rhs.data().n_blocks())
621  error += "n_blocks doesn't match. ";
622  else {
623  for (int b=0; b < data().n_blocks(); ++b) {
624  if (data()[b].num_cols() != rhs.data()[b].num_cols() || data()[b].num_rows() != rhs.data()[b].num_rows())
625  error += "Size of block doesn't match. ";
626  for (int i=0; i < data()[b].num_rows() && error.empty(); ++i)
627  for (int j=0; j < data()[b].num_cols() && error.empty(); ++j)
628  if (data()[b](i,j) != rhs.data()[b](i,j))
629  error += "Data doesn't match. ";
630  }
631  }
632  // Finalize
633  if (!error.empty())
634  throw std::runtime_error(error);
635 
636 }
void make_left_paired() const
Definition: mpstensor.hpp:173
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
bool reasonable() const
Definition: mpstensor.hpp:547
template<class Matrix , class SymmGroup >
Index< SymmGroup > const & MPSTensor< Matrix, SymmGroup >::col_dim ( ) const

Definition at line 161 of file mpstensor.hpp.

162 {
163  return right_i;
164 }
Index< SymmGroup > right_i
Definition: mpstensor.h:141
template<class Matrix , class SymmGroup >
void MPSTensor< Matrix, SymmGroup >::conjugate_inplace ( )

Definition at line 332 of file mpstensor.hpp.

333 {
334  data() = data().inplace_conjugate();
335 }
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
block_matrix< Matrix, SymmGroup > const & MPSTensor< Matrix, SymmGroup >::const_data ( ) const

Definition at line 438 of file mpstensor.hpp.

439 {
440  return data_;
441 }
template<class Matrix, class SymmGroup>
MPSTensor MPSTensor< Matrix, SymmGroup >::copy ( ) const
template<class Matrix , class SymmGroup >
block_matrix< Matrix, SymmGroup > & MPSTensor< Matrix, SymmGroup >::data ( )

Definition at line 423 of file mpstensor.hpp.

424 {
425  cur_normalization = Unorm;
426  return data_;
427 }
template<class Matrix , class SymmGroup >
block_matrix< Matrix, SymmGroup > const & MPSTensor< Matrix, SymmGroup >::data ( ) const

Definition at line 431 of file mpstensor.hpp.

432 {
433  return const_data();
434 }
block_matrix< Matrix, SymmGroup > const & const_data() const
Definition: mpstensor.hpp:438
template<class Matrix , class SymmGroup >
void MPSTensor< Matrix, SymmGroup >::divide_by_scalar ( const scalar_type s)

Definition at line 324 of file mpstensor.hpp.

325 {
326  cur_normalization = Unorm;
327  *this /= s;
328 }
template<class Matrix , class SymmGroup >
bool MPSTensor< Matrix, SymmGroup >::isleftnormalized ( bool  test = false) const

Definition at line 395 of file mpstensor.hpp.

396 {
397  if (test)
398  throw std::runtime_error("Not implemented!");
399  else
400  return cur_normalization == Lnorm;
401 }
template<class Matrix , class SymmGroup >
bool MPSTensor< Matrix, SymmGroup >::isnormalized ( bool  test = false) const

Definition at line 413 of file mpstensor.hpp.

414 {
415  if (isleftnormalized(test) || isrightnormalized(test))
416  return true;
417  else
418  return false;
419 }
bool isrightnormalized(bool test=false) const
Definition: mpstensor.hpp:404
bool isleftnormalized(bool test=false) const
Definition: mpstensor.hpp:395
template<class Matrix , class SymmGroup >
bool MPSTensor< Matrix, SymmGroup >::isobccompatible ( Indicator  i) const

Definition at line 167 of file mpstensor.hpp.

168 {
169  return false;
170 }
template<class Matrix , class SymmGroup >
bool MPSTensor< Matrix, SymmGroup >::isrightnormalized ( bool  test = false) const

Definition at line 404 of file mpstensor.hpp.

405 {
406  if (test)
407  throw std::runtime_error("Not implemented!");
408  else
409  return cur_normalization == Rnorm;
410 }
template<class Matrix , class SymmGroup >
template<class Archive >
void MPSTensor< Matrix, SymmGroup >::load ( Archive &  ar)

Definition at line 524 of file mpstensor.hpp.

525 {
526  data_.clear();
528  ar["phys_i"] >> phys_i;
529  ar["left_i"] >> left_i;
530  ar["right_i"] >> right_i;
531  ar["data_"] >> data();
532  cur_normalization = Unorm;
533 }
void make_left_paired() const
Definition: mpstensor.hpp:173
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
void MPSTensor< Matrix, SymmGroup >::make_left_paired ( ) const

Definition at line 173 of file mpstensor.hpp.

174 {
175  if (cur_storage == LeftPaired)
176  return;
177 
179  reshape_right_to_left_new<Matrix>(phys_i, left_i, right_i,
180  data(), tmp);
181  cur_storage = LeftPaired;
182  swap(data_, tmp);
183 
184  assert( weak_equal(right_i, data().right_basis()) );
185 }
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
bool weak_equal(Index< SymmGroup > const &a, Index< SymmGroup > const &b)
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
void MPSTensor< Matrix, SymmGroup >::make_right_paired ( ) const

Definition at line 188 of file mpstensor.hpp.

189 {
190  if (cur_storage == RightPaired)
191  return;
192 
194  reshape_left_to_right_new<Matrix>(phys_i, left_i, right_i,
195  data(), tmp);
196  cur_storage = RightPaired;
197  swap(data_, tmp);
198 
199  assert( weak_equal(left_i, data().left_basis()) );
200 }
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
bool weak_equal(Index< SymmGroup > const &a, Index< SymmGroup > const &b)
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
void MPSTensor< Matrix, SymmGroup >::multiply_by_scalar ( const scalar_type s)

Definition at line 316 of file mpstensor.hpp.

317 {
318  cur_normalization = Unorm;
319  *this *= s;
320 }
template<class Matrix, class SymmGroup>
void MPSTensor< Matrix, SymmGroup >::multiply_from_left ( block_matrix< Matrix, SymmGroup > const &  N)

Definition at line 305 of file mpstensor.hpp.

306 {
307  cur_normalization = Unorm;
310  gemm(N, data(), tmp);
312 }
void make_right_paired() const
Definition: mpstensor.hpp:188
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
void replace_right_paired(block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
Definition: mpstensor.hpp:131
template<class Matrix, class SymmGroup>
void MPSTensor< Matrix, SymmGroup >::multiply_from_right ( block_matrix< Matrix, SymmGroup > const &  N)

Definition at line 294 of file mpstensor.hpp.

295 {
296  cur_normalization = Unorm;
299  gemm(data(), N, tmp);
300  replace_left_paired(tmp);
301 }
void make_left_paired() const
Definition: mpstensor.hpp:173
void replace_left_paired(block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
Definition: mpstensor.hpp:113
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup>
block_matrix< Matrix, SymmGroup > MPSTensor< Matrix, SymmGroup >::normalize_left ( DecompMethod  method = DefaultSolver(),
bool  multiplied = true,
double  truncation = 0,
Index< SymmGroup >  bond_dim = Index<SymmGroup>() 
)

Definition at line 204 of file mpstensor.hpp.

208 {
209  if (cur_normalization == Unorm || cur_normalization == Rnorm) {
210  if (method == QR) {
212 
214  qr(data(), Q, R);
215 
216  swap(data(), Q);
217  right_i = data().right_basis();
218  assert(right_i == R.left_basis());
219 
220  cur_normalization = Lnorm;
221  return R;
222  } else {
224 
227 
228  svd(data(), U, V, S);
229 
230  right_i = U.right_basis();
231  assert(data().left_basis() == U.left_basis());
232 
233  swap(data(), U);
234  gemm(S, V, U);
235 
236  cur_normalization = Lnorm;
237  return U;
238  }
239  }
240  return identity_matrix<Matrix>(data().right_basis());
241 }
void make_left_paired() const
Definition: mpstensor.hpp:173
void svd(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &U, block_matrix< Matrix, SymmGroup > &V, block_matrix< DiagMatrix, SymmGroup > &S)
Index< SymmGroup > const & right_basis() const
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
Index< SymmGroup > right_i
Definition: mpstensor.h:141
Index< SymmGroup > const & left_basis() const
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
void qr(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &Q, block_matrix< Matrix, SymmGroup > &R)
Definition: mpstensor.h:41
template<class Matrix , class SymmGroup>
block_matrix< Matrix, SymmGroup > MPSTensor< Matrix, SymmGroup >::normalize_right ( DecompMethod  method = DefaultSolver(),
bool  multiplied = true,
double  truncation = 0,
Index< SymmGroup >  bond_dim = Index<SymmGroup>() 
)

Definition at line 245 of file mpstensor.hpp.

249 {
250  if (cur_normalization == Unorm || cur_normalization == Lnorm) {
251  if (method == QR) { //enum QR but LQ decomposition
253 
255  lq(data(), L, Q);
256 
257  swap(data(), Q);
258  left_i = data().left_basis();
259  assert(left_i == L.right_basis());
260 
261  cur_normalization = Rnorm;
262  return L;
263  } else {
265 
268 
269  svd(data(), U, V, S);
270 
271  left_i = V.left_basis();
272  assert(data().right_basis() == V.right_basis());
273  swap(data(), V);
274 
275  gemm(U, S, V);
276 
277  cur_normalization = Rnorm;
278  return V;
279  }
280  }
281  return identity_matrix<Matrix>(data().left_basis());
282 }
void make_right_paired() const
Definition: mpstensor.hpp:188
void svd(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &U, block_matrix< Matrix, SymmGroup > &V, block_matrix< DiagMatrix, SymmGroup > &S)
Index< SymmGroup > const & right_basis() const
void lq(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &L, block_matrix< Matrix, SymmGroup > &Q)
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
Index< SymmGroup > const & left_basis() const
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
Definition: mpstensor.h:41
template<class Matrix , class SymmGroup >
bool MPSTensor< Matrix, SymmGroup >::num_check ( ) const

Definition at line 579 of file mpstensor.hpp.

580 {
581  for (std::size_t k = 0; k < data().n_blocks(); ++k)
582  {
583  for (size_t i = 0; i<num_rows(data()[k]); ++i)
584  for (size_t j = 0; j<num_cols(data()[k]); ++j)
585  {
586  if ( alps::numeric::isnan(data()[k](i,j)) )
587  throw std::runtime_error("NaN found!");
588  if ( alps::numeric::isinf(data()[k](i,j)) )
589  throw std::runtime_error("INF found!");
590  }
591  }
592  return true;
593 }
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:99
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:102
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
std::size_t MPSTensor< Matrix, SymmGroup >::num_elements ( ) const

Definition at line 639 of file mpstensor.hpp.

640 {
641  return data().num_elements();
642 }
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
MPSTensor< Matrix, SymmGroup > const & MPSTensor< Matrix, SymmGroup >::operator*= ( const scalar_type t)

Definition at line 446 of file mpstensor.hpp.

447 {
448  data() *= t;
449  return *this;
450 }
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
MPSTensor< Matrix, SymmGroup > const & MPSTensor< Matrix, SymmGroup >::operator+= ( MPSTensor< Matrix, SymmGroup > const &  rhs)

Definition at line 462 of file mpstensor.hpp.

463 {
464  assert( weak_equal(left_i, rhs.left_i) );
465  assert( weak_equal(right_i, rhs.right_i) );
466  assert( phys_i == rhs.phys_i );
467 
468  // what if both are right_paired?
470  rhs.make_left_paired();
471 
472  cur_normalization = Unorm;
473 
474  for (std::size_t i = 0; i < data().n_blocks(); ++i)
475  {
476  typename SymmGroup::charge lc = data().left_basis()[i].first, rc = data().right_basis()[i].first;
477  std::size_t matched_block = rhs.data().find_block(lc,rc);
478  if (matched_block < rhs.data().n_blocks()) {
479  data()[i] += rhs.data()[matched_block];
480  }
481  }
482 
483  return *this;
484 }
void make_left_paired() const
Definition: mpstensor.hpp:173
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
bool weak_equal(Index< SymmGroup > const &a, Index< SymmGroup > const &b)
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
MPSTensor< Matrix, SymmGroup > const & MPSTensor< Matrix, SymmGroup >::operator-= ( MPSTensor< Matrix, SymmGroup > const &  rhs)

Definition at line 488 of file mpstensor.hpp.

489 {
490  assert( weak_equal(left_i, rhs.left_i) );
491  assert( weak_equal(right_i, rhs.right_i) );
492  assert( phys_i == rhs.phys_i );
493 
495  rhs.make_left_paired();
496 
497  cur_normalization = Unorm;
498 
499  for (std::size_t i = 0; i < data().n_blocks(); ++i)
500  {
501  typename SymmGroup::charge lc = data().left_basis()[i].first, rc = data().right_basis()[i].first;
502  if (rhs.data().has_block(lc,rc)) {
503  data()[i] -= rhs.data()(lc,rc);
504  }
505  }
506 
507  return *this;
508 }
void make_left_paired() const
Definition: mpstensor.hpp:173
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
bool weak_equal(Index< SymmGroup > const &a, Index< SymmGroup > const &b)
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
MPSTensor< Matrix, SymmGroup > const & MPSTensor< Matrix, SymmGroup >::operator/= ( const scalar_type t)

Definition at line 454 of file mpstensor.hpp.

455 {
456  data() /= t;
457  return *this;
458 }
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
bool MPSTensor< Matrix, SymmGroup >::reasonable ( ) const

Definition at line 547 of file mpstensor.hpp.

548 {
549  {
551  if ( !weak_equal(right_i, data().right_basis()) )
552  throw std::runtime_error("right basis is wrong");
553 
554 // maquis::cout << "** reasonable left_paired **" << std::endl;
555 // maquis::cout << "reasonable::left_i: " << left_i << std::endl;
556 // maquis::cout << "reasonable::right_i: " << right_i << std::endl;
557 // maquis::cout << "reasonable::data_:" << std::endl << data() << std::endl;
559  if ( !weak_equal(left_i, data().left_basis()) )
560  throw std::runtime_error("left basis is wrong");
561 
562 // maquis::cout << "** reasonable right_paired **" << std::endl;
563 // maquis::cout << "reasonable::left_i: " << left_i << std::endl;
564 // maquis::cout << "reasonable::right_i: " << right_i << std::endl;
565 // maquis::cout << "reasonable::data_:" << std::endl << data() << std::endl;
566  }
567 
568  {
569  for (std::size_t i = 0; i < data().n_blocks(); ++i)
570  {
571  if (data().left_basis()[i].first != data().right_basis()[i].first)
572  throw std::runtime_error("particle number is wrong");
573  }
574  }
575  return true;
576 }
void make_left_paired() const
Definition: mpstensor.hpp:173
void make_right_paired() const
Definition: mpstensor.hpp:188
bool weak_equal(Index< SymmGroup > const &a, Index< SymmGroup > const &b)
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix, class SymmGroup>
void MPSTensor< Matrix, SymmGroup >::replace_left_paired ( block_matrix< Matrix, SymmGroup > const &  rhs,
Indicator  normalization = Unorm 
)

Definition at line 113 of file mpstensor.hpp.

114 {
116 
117  Index<SymmGroup> new_right_i = rhs.right_basis();
118  Index<SymmGroup> possible_left_i = adjoin(phys_i)*new_right_i;
119  Index<SymmGroup> old_left_i = left_i;
120 
121  common_subset(old_left_i, possible_left_i);
122 
123  swap(right_i, new_right_i);
124  swap(left_i, old_left_i);
125 
126  data() = rhs;
127  cur_normalization = normalization;
128 }
void make_left_paired() const
Definition: mpstensor.hpp:173
block_matrix< Matrix, SymmGroup > adjoin(block_matrix< Matrix, SymmGroup > const &m)
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > const & right_basis() const
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
Index< SymmGroup > common_subset(Index< SymmGroup > &a, Index< SymmGroup > &b)
template<class Matrix, class SymmGroup>
void MPSTensor< Matrix, SymmGroup >::replace_right_paired ( block_matrix< Matrix, SymmGroup > const &  rhs,
Indicator  normalization = Unorm 
)

Definition at line 131 of file mpstensor.hpp.

132 {
134 
135  Index<SymmGroup> new_left_i = rhs.left_basis();
136  Index<SymmGroup> possible_right_i = phys_i*new_left_i;
137  Index<SymmGroup> old_right_i = right_i;
138 
139  common_subset(old_right_i, possible_right_i);
140 
141  swap(left_i, new_left_i);
142  swap(right_i, old_right_i);
143 
144  data() = rhs;
145  cur_normalization = normalization;
146 }
void make_right_paired() const
Definition: mpstensor.hpp:188
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
Index< SymmGroup > right_i
Definition: mpstensor.h:141
Index< SymmGroup > const & left_basis() const
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
Index< SymmGroup > common_subset(Index< SymmGroup > &a, Index< SymmGroup > &b)
template<class Matrix , class SymmGroup >
Index< SymmGroup > const & MPSTensor< Matrix, SymmGroup >::row_dim ( ) const

Definition at line 155 of file mpstensor.hpp.

156 {
157  return left_i;
158 }
Index< SymmGroup > left_i
Definition: mpstensor.h:141
template<class Matrix , class SymmGroup >
template<class Archive >
void MPSTensor< Matrix, SymmGroup >::save ( Archive &  ar) const

Definition at line 537 of file mpstensor.hpp.

538 {
540  ar["phys_i"] << phys_i;
541  ar["left_i"] << left_i;
542  ar["right_i"] << right_i;
543  ar["data_"] << data();
544 }
void make_left_paired() const
Definition: mpstensor.hpp:173
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
MPSTensor< Matrix, SymmGroup >::real_type MPSTensor< Matrix, SymmGroup >::scalar_norm ( ) const

Definition at line 339 of file mpstensor.hpp.

340 {
341  return data().norm();
342 }
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
MPSTensor< Matrix, SymmGroup >::scalar_type MPSTensor< Matrix, SymmGroup >::scalar_overlap ( MPSTensor< Matrix, SymmGroup > const &  rhs) const

Definition at line 356 of file mpstensor.hpp.

357 {
359  rhs.make_left_paired();
360 
361  // verbose_assert(left_i, rhs.left_i);
362  // verbose_assert(right_i, rhs.right_i);
363  // verbose_assert(phys_i, rhs.phys_i);
364  // verbose_assert(rhs.data_.left_basis(), data_.left_basis());
365  // verbose_assert(rhs.data_.right_basis(), data_.right_basis());
366  // verbose_assert(rhs.data_.n_blocks(), data_.n_blocks());
367 
368  // Bela says: this is a workaround for the very rare condition that site_hamil2 removes blocks
369  // This shouldn't be necessary, but as of Rev. 1702, is necessary in some cases
370  // If I haven't fixed this by the end of Feb 2012, remind me
371  Index<SymmGroup> i1 = data().left_basis(), i2 = rhs.data().left_basis();
372  common_subset(i1, i2);
373  std::vector<scalar_type> vt; vt.reserve(i1.size());
374 
375  semi_parallel_for (/*locale::compact(i1.size())*/, std::size_t b = 0; b < i1.size(); ++b) {
376  typename SymmGroup::charge c = i1[b].first;
377  assert( data().has_block(c,c) && rhs.data().has_block(c,c) );
378  vt.push_back(overlap(data()(c,c), rhs.data()(c,c)));
379  } // should be reformulated in terms of reduction (todo: Matthias, 30.04.12 / scalar-value types)
380 
381  return maquis::accumulate(vt.begin(), vt.end(), scalar_type(0.));
382 }
void make_left_paired() const
Definition: mpstensor.hpp:173
maquis::traits::scalar_type< Matrix >::type scalar_type
Definition: mpstensor.h:52
#define semi_parallel_for(constraint,...)
MPS< Matrix, SymmGroup >::scalar_type overlap(MPS< Matrix, SymmGroup > const &mps1, MPS< Matrix, SymmGroup > const &mps2)
Definition: mps_mpo_ops.h:136
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Definition: bindings.hpp:44
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
std::size_t size() const
Index< SymmGroup > common_subset(Index< SymmGroup > &a, Index< SymmGroup > &b)
template<class Matrix , class SymmGroup>
void MPSTensor< Matrix, SymmGroup >::shift_aux_charges ( typename SymmGroup::charge  diff)

Definition at line 285 of file mpstensor.hpp.

286 {
287  left_i.shift(diff);
288  right_i.shift(diff);
289  data().shift_basis(diff);
290 }
Index< SymmGroup > left_i
Definition: mpstensor.h:141
Index< SymmGroup > right_i
Definition: mpstensor.h:141
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
template<class Matrix , class SymmGroup >
Index< SymmGroup > const & MPSTensor< Matrix, SymmGroup >::site_dim ( ) const

Definition at line 149 of file mpstensor.hpp.

150 {
151  return phys_i;
152 }
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
template<class Matrix , class SymmGroup >
void MPSTensor< Matrix, SymmGroup >::swap_with ( MPSTensor< Matrix, SymmGroup > &  b)

Definition at line 511 of file mpstensor.hpp.

512 {
513  using std::swap;
514  swap(this->phys_i, b.phys_i);
515  swap(this->left_i, b.left_i);
516  swap(this->right_i, b.right_i);
517  swap(this->data_, b.data_);
518  swap(this->cur_storage, b.cur_storage);
519  swap(this->cur_normalization, b.cur_normalization);
520 }
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
Index< SymmGroup > right_i
Definition: mpstensor.h:141
template<class Matrix, class SymmGroup>
std::vector<block_matrix<Matrix, SymmGroup> > MPSTensor< Matrix, SymmGroup >::to_list ( ) const

Friends And Related Function Documentation

template<class Matrix, class SymmGroup>
template<class Matrix_ , class SymmGroup_ >
MPSTensor<Matrix_, SymmGroup_> join ( MPSTensor< Matrix_, SymmGroup_ > const &  ,
MPSTensor< Matrix_, SymmGroup_ > const &  ,
boundary_flag_t   
)
friend
template<class Matrix, class SymmGroup>
template<class Matrix_ , class SymmGroup_ >
std::ostream& operator<< ( std::ostream &  ,
MPSTensor< Matrix_, SymmGroup_ > const &   
)
friend
template<class Matrix, class SymmGroup>
void swap ( MPSTensor< Matrix, SymmGroup > &  a,
MPSTensor< Matrix, SymmGroup > &  b 
)
friend

Definition at line 128 of file mpstensor.h.

128  {
129  a.swap_with(b);
130  }
void swap_with(MPSTensor &b)
Definition: mpstensor.hpp:511

Member Data Documentation

template<class Matrix, class SymmGroup>
Index<SymmGroup> MPSTensor< Matrix, SymmGroup >::left_i

Definition at line 141 of file mpstensor.h.

template<class Matrix, class SymmGroup>
Index<SymmGroup> MPSTensor< Matrix, SymmGroup >::phys_i

Definition at line 141 of file mpstensor.h.

template<class Matrix, class SymmGroup>
Index<SymmGroup> MPSTensor< Matrix, SymmGroup >::right_i

Definition at line 141 of file mpstensor.h.


The documentation for this class was generated from the following files: