ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compression.h
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 Bela Bauer <bauerb@phys.ethz.ch>
7  *
8  * This software is part of the ALPS Applications, published under the ALPS
9  * Application License; you can use, redistribute it and/or modify it under
10  * the terms of the license, either version 1 or (at your option) any later
11  * version.
12  *
13  * You should have received a copy of the ALPS Application License along with
14  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
15  * available from http://alps.comp-phys.org/.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  *****************************************************************************/
26 
27 #ifndef COMPRESSION_H
28 #define COMPRESSION_H
29 
30 #include "dmrg/mp_tensors/mps.h"
31 
34 
35 struct compression {
36  template<class Matrix, class SymmGroup>
37  static truncation_results
39  std::size_t Mmax, double cutoff,
41  std::size_t p)
42  {
44 
45  typedef typename alps::numeric::associated_real_diagonal_matrix<Matrix>::type dmt;
46 
48 
49  truncation_results trunc = svd_truncate(t, u, v, s,
50  cutoff, Mmax, true);
51 
52  mps[p].replace_left_paired(u, Lnorm);
53 
54  gemm(s, v, u);
55  mps[p+1].replace_right_paired(u);
56 
57  return trunc;
58  }
59 
60  template<class Matrix, class SymmGroup>
61  static truncation_results
63  std::size_t Mmax, double cutoff,
65  std::size_t p)
66  {
68 
69  typedef typename alps::numeric::associated_real_diagonal_matrix<Matrix>::type dmt;
70 
72 
73  truncation_results trunc = svd_truncate(t, u, v, s,
74  cutoff, Mmax, true);
75 
76  mps[p+1].replace_right_paired(v, Rnorm);
77 
78  gemm(u, s, v);
79  mps[p].replace_left_paired(v);
80 
81  return trunc;
82  }
83 
84  template<class Matrix, class SymmGroup>
86  std::size_t Mmax, double cutoff,
87  std::size_t p)
88  {
90 
91  mps[p].make_left_paired();
92  mps[p+1].make_right_paired();
93 
94  gemm(mps[p].data(), mps[p+1].data(), t);
95 
96  replace_two_sites_l2r(mps, Mmax, cutoff, t, p);
97  }
98 
99  template<class Matrix, class SymmGroup>
102  std::size_t Mmax, double cutoff,
103  bool verbose = false)
104  {
105  std::size_t L = mps.length();
106  std::vector<double> ret;
107 
109 
110  mps.canonize(1);
111 
112  if (verbose) maquis::cout << "Compressing @ ";
113  for (std::size_t p = 1; p < L; ++p)
114  {
115  if (verbose) {
116  maquis::cout << p << " ";
117  maquis::cout.flush();
118  }
119 
120  compress_two_sites(mps, Mmax, cutoff, p-1);
121 
122  t = mps[p].normalize_left(DefaultSolver());
123 
124  if (p+1 < L)
125  mps[p+1].multiply_from_left(t);
126  else
127  maquis::cout << "Norm reduction: " << trace(t) << std::endl;
128  }
129 
130  return mps;
131  }
132 
133  template<class Matrix, class SymmGroup>
136  std::size_t Mmax, double cutoff,
137  bool verbose = false)
138  {
139  std::size_t L = mps.length();
140  std::vector<double> ret;
141 
143 
144  mps.canonize(L-1);
145 
146  if (verbose) maquis::cout << "Compressing @ ";
147  for (std::size_t p = L-1; p > 0; --p)
148  {
149  if (verbose) {
150  maquis::cout << p << " ";
151  maquis::cout.flush();
152  }
153 
154  compress_two_sites(mps, Mmax, cutoff, p-1);
155 
156  t = mps[p-1].normalize_right(DefaultSolver());
157 
158  if (p > 1)
159  mps[p-2].multiply_from_right(t);
160  else
161  maquis::cout << "Norm reduction: " << trace(t) << std::endl;
162  }
163 
164  return mps;
165  }
166 };
167 
168 #endif
void normalize_left()
Definition: mps.hpp:124
static void compress_two_sites(MPS< Matrix, SymmGroup > &mps, std::size_t Mmax, double cutoff, std::size_t p)
Definition: compression.h:85
declaration of the MPS class (vector of MPSTensor)
static truncation_results replace_two_sites_l2r(MPS< Matrix, SymmGroup > &mps, std::size_t Mmax, double cutoff, block_matrix< Matrix, SymmGroup > const &t, std::size_t p)
Definition: compression.h:38
static MPS< Matrix, SymmGroup > r2l_compress(MPS< Matrix, SymmGroup > mps, std::size_t Mmax, double cutoff, bool verbose=false)
Definition: compression.h:135
data_type data
block_matrix< Matrix, SymmGroup >::scalar_type trace(block_matrix< Matrix, SymmGroup > const &m)
include one of the Index class definitions
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)
Definition: mps.h:40
void normalize_right()
Definition: mps.hpp:134
size_t length() const
Definition: mps.h:58
static truncation_results replace_two_sites_r2l(MPS< Matrix, SymmGroup > &mps, std::size_t Mmax, double cutoff, block_matrix< Matrix, SymmGroup > const &t, std::size_t p)
Definition: compression.h:62
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)
void canonize(size_t center, DecompMethod method=DefaultSolver())
Definition: mps.hpp:147
static MPS< Matrix, SymmGroup > l2r_compress(MPS< Matrix, SymmGroup > mps, std::size_t Mmax, double cutoff, bool verbose=false)
Definition: compression.h:101