ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
twositetensor.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * ALPS MPS DMRG Project
4  *
5  * Copyright (C) 2013 Institute for Theoretical Physics, ETH Zurich
6  * 2011-2011 by Sebastian Keller <sebkelle@phys.ethz.ch>
7  * Michele Dolfi <dolfim@phys.ethz.ch>
8  *
9  * This software is part of the ALPS Applications, published under the ALPS
10  * Application License; you can use, redistribute it and/or modify it under
11  * the terms of the license, either version 1 or (at your option) any later
12  * version.
13  *
14  * You should have received a copy of the ALPS Application License along with
15  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
16  * available from http://alps.comp-phys.org/.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  *****************************************************************************/
27 
30 
33 
34 #include "dmrg/utils/random.hpp"
35 #include <alps/numeric/real.hpp>
36 
37 #include <vector>
38 #include <utility>
39 
40 #include "ts_reshape.h"
41 
42 template<class Matrix, class SymmGroup>
44  MPSTensor<Matrix, SymmGroup> const & mps2)
45 : phys_i( mps1.site_dim()*mps2.site_dim() )
46 , phys_i_left( mps1.site_dim() )
47 , phys_i_right( mps2.site_dim() )
48 , left_i( mps1.row_dim() )
49 , right_i( mps2.col_dim() )
50 , cur_storage(TSBothPaired)
51 , cur_normalization(Unorm)
52 {
53  mps1.make_left_paired();
54  mps2.make_right_paired();
55  gemm(mps1.data(), mps2.data(), data_);
56 
57 }
58 
59 
60 template<class Matrix, class SymmGroup>
62 {
63  return phys_i;
64 }
65 
66 template<class Matrix, class SymmGroup>
68 {
69  return left_i;
70 }
71 
72 template<class Matrix, class SymmGroup>
74 {
75  return right_i;
76 }
77 
78 template<class Matrix, class SymmGroup>
80 {
81  if (cur_storage == TSLeftPaired)
82  return;
83 
85  if (cur_storage == TSBothPaired) {
86  ts_reshape::reshape_both_to_left<Matrix, SymmGroup>(phys_i_left, phys_i_right, left_i, right_i, data_, tmp);
87  } else {
88  // direct left to right reshape should not be needed
89  make_both_paired();
90  ts_reshape::reshape_both_to_left<Matrix, SymmGroup>(phys_i_left, phys_i_right, left_i, right_i, data_, tmp);
91  }
92 
93  swap(data_, tmp);
94  cur_storage = TSLeftPaired;
95 
96  // assert( right_i == data_.right_basis() );
97 }
98 
99 template<class Matrix, class SymmGroup>
101 {
102  if (cur_storage == TSBothPaired)
103  return;
104 
106  if (cur_storage == TSRightPaired) {
107  ts_reshape::reshape_right_to_both<Matrix, SymmGroup>(phys_i_left, phys_i_right, left_i, right_i, data_, tmp);
108  }
109  else {
110  ts_reshape::reshape_left_to_both<Matrix, SymmGroup>(phys_i_left, phys_i_right, left_i, right_i, data_, tmp);
111  }
112 
113  swap(data_, tmp);
114  cur_storage = TSBothPaired;
115 }
116 
117 template<class Matrix, class SymmGroup>
119 {
120  if (cur_storage == TSRightPaired)
121  return;
122 
124  if (cur_storage == TSBothPaired)
125  ts_reshape::reshape_both_to_right<Matrix, SymmGroup>(phys_i_left, phys_i_right, left_i, right_i, data_, tmp);
126  else {
127  // direct left to right reshape should not be needed
128  make_both_paired();
129  ts_reshape::reshape_both_to_right<Matrix, SymmGroup>(phys_i_left, phys_i_right, left_i, right_i, data_, tmp);
130  }
131 
132  swap(data_, tmp);
133  cur_storage = TSRightPaired;
134 
135  // assert( left_i == data_.left_basis() );
136 }
137 
138 template<class Matrix, class SymmGroup>
140 {
141  make_left_paired();
142  return MPSTensor<Matrix, SymmGroup>(phys_i, left_i, right_i, data_, LeftPaired);
143 }
144 
145 template<class Matrix, class SymmGroup>
146 boost::tuple<MPSTensor<Matrix, SymmGroup>, MPSTensor<Matrix, SymmGroup>, truncation_results>
147 TwoSiteTensor<Matrix, SymmGroup>::split_mps_l2r(std::size_t Mmax, double cutoff) const
148 {
149  make_both_paired();
150 
151  typedef typename alps::numeric::associated_real_diagonal_matrix<Matrix>::type dmt;
154 
155  truncation_results trunc = svd_truncate(data_, u, v, s, cutoff, Mmax, true);
156 
157  MPSTensor<Matrix, SymmGroup> mps_tensor1(phys_i_left, left_i, u.right_basis(), u, LeftPaired);
158  assert( mps_tensor1.reasonable() );
159  gemm(s, v, u);
160  MPSTensor<Matrix, SymmGroup> mps_tensor2(phys_i_right, u.left_basis(), right_i, u, RightPaired);
161  assert( mps_tensor2.reasonable() );
162 
163  return boost::make_tuple(mps_tensor1, mps_tensor2, trunc);
164 }
165 
166 template<class Matrix, class SymmGroup>
167 boost::tuple<MPSTensor<Matrix, SymmGroup>, MPSTensor<Matrix, SymmGroup>, truncation_results>
168 TwoSiteTensor<Matrix, SymmGroup>::split_mps_r2l(std::size_t Mmax, double cutoff) const
169 {
170  make_both_paired();
171 
172  typedef typename alps::numeric::associated_real_diagonal_matrix<Matrix>::type dmt;
175 
176  truncation_results trunc = svd_truncate(data_, u, v, s, cutoff, Mmax, true);
177 
178  MPSTensor<Matrix, SymmGroup> mps_tensor2(phys_i_right, v.left_basis(), right_i, v, RightPaired);
179 
180  gemm(u, s, v);
181  MPSTensor<Matrix, SymmGroup> mps_tensor1(phys_i_left, left_i, u.right_basis(), v, LeftPaired);
182 
183  return boost::make_tuple(mps_tensor1, mps_tensor2, trunc);
184 }
185 
186 template<class Matrix, class SymmGroup>
187 std::ostream& operator<<(std::ostream& os, TwoSiteTensor<Matrix, SymmGroup> const & mps)
188 {
189  os << "Physical space: " << mps.phys_i << std::endl;
190  os << "Left space: " << mps.left_i << std::endl;
191  os << "Right space: " << mps.right_i << std::endl;
192  os << mps.data_;
193  return os;
194 }
195 
196 template<class Matrix, class SymmGroup>
199 {
200  return data_;
201 }
202 
203 template<class Matrix, class SymmGroup>
206 {
207  return data_;
208 }
209 
210 template<class Matrix, class SymmGroup>
212 {
213  swap(this->phys_i, b.phys_i);
214  swap(this->phys_i_left, b.phys_i_left);
215  swap(this->phys_i_right, b.phys_i_right);
216  swap(this->left_i, b.left_i);
217  swap(this->right_i, b.right_i);
218  swap(this->data_, b.data_);
219  swap(this->cur_storage, b.cur_storage);
220  swap(this->cur_normalization, b.cur_normalization);
221 }
222 
223 template<class Matrix, class SymmGroup>
225 {
226  this->make_left_paired();
227  rhs.make_left_paired();
228 
229  // Precondition: rhs.data() and this->data() have same shape if both are left_paired
230  // assert( rhs.row_dim() == this->row_dim() &&
231  // rhs.col_dim() == this->col_dim() &&
232  // rhs.site_dim() == this->site_dim() );
233  // assert( rhs.data().left_basis() == this->data().left_basis() &&
234  // rhs.data().right_basis() == this->data().right_basis() );
235 
236  left_i = rhs.row_dim();
237  right_i = rhs.col_dim();
238  this->data() = rhs.data();
239 
240  return *this;
241 
242 }
243 
244 
functions to reshape the representation of data in TwoSiteTensor
Index< SymmGroup > const & site_dim() const
void make_left_paired() const
Definition: mpstensor.hpp:173
Index< SymmGroup > const & col_dim() const
Definition: mpstensor.hpp:161
void swap_with(TwoSiteTensor &b)
Index< SymmGroup > const & row_dim() const
void make_right_paired() const
Definition: mpstensor.hpp:188
MPSTensor< Matrix, SymmGroup > make_mps() const
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
void make_right_paired() const
data_type data
Index< SymmGroup > const & row_dim() const
Definition: mpstensor.hpp:155
friend std::ostream & operator<<(std::ostream &, TwoSiteTensor< Matrix_, SymmGroup_ > const &)
block_matrix< Matrix, SymmGroup > & data()
TwoSiteTensor(MPSTensor< Matrix, SymmGroup > const &mps1, MPSTensor< Matrix, SymmGroup > const &mps2)
truncation_results svd_truncate(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &U, block_matrix< Matrix, SymmGroup > &V, block_matrix< DiagMatrix, SymmGroup > &S, double rel_tol, std::size_t Mmax, bool verbose=true)
void make_left_paired() const
Index< SymmGroup > const & col_dim() const
declaration of the TwoSiteTensor class
declaration of the MPSTensor class
boost::tuple< MPSTensor< Matrix, SymmGroup >, MPSTensor< Matrix, SymmGroup >, truncation_results > split_mps_l2r(std::size_t Mmax, double cutoff) const
Index< SymmGroup > const & right_basis() const
algorithms for block_matrix (gemm, svd, etc.)
functions to reshape the representation of data in MPSTensor
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
boost::tuple< MPSTensor< Matrix, SymmGroup >, MPSTensor< Matrix, SymmGroup >, truncation_results > split_mps_r2l(std::size_t Mmax, double cutoff) const
void make_both_paired() const
Index< SymmGroup > const & left_basis() const
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423