ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpstensor.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 MPSTENSOR_H
28 #define MPSTENSOR_H
29 
32 //#include "solver.h"
33 
34 #include <iostream>
35 #include <algorithm>
36 
39 // these are actually used in several places
41 enum DecompMethod {QR, SVD};
42 
43 static DecompMethod DefaultSolver() {return QR;} // QR or SVD
44 
45 template<class Matrix, class SymmGroup>
47 
48 template<class Matrix, class SymmGroup>
49 class MPSTensor
50 {
51 public:
54  typedef typename Matrix::value_type value_type;
55  typedef double magnitude_type; // should become future (todo: Matthias, 30.04.12 / scalar-value types)
56  typedef std::size_t size_type;
57 
59  Index<SymmGroup> const & ld = Index<SymmGroup>(),
60  Index<SymmGroup> const & rd = Index<SymmGroup>(),
61  bool fillrand = true,
62  value_type val = 0);
63 
64  MPSTensor(Index<SymmGroup> const& sd,
65  Index<SymmGroup> const& ld,
66  Index<SymmGroup> const& rd,
68  MPSStorageLayout layout);
69 
70  Index<SymmGroup> const & site_dim() const;
71  Index<SymmGroup> const & row_dim() const;
72  Index<SymmGroup> const & col_dim() const;
73  bool isobccompatible(Indicator) const;
74  std::size_t num_elements() const;
75 
78 
79  // these are not const because after a numerical test
80  // they may update the status
81  bool isleftnormalized(bool test = false) const;
82  bool isrightnormalized(bool test = false) const;
83  bool isnormalized(bool test = false) const;
84 
86  bool multiplied = true,
87  double truncation = 0,
88  Index<SymmGroup> bond_dim = Index<SymmGroup>());
90  bool multiplied = true,
91  double truncation = 0,
92  Index<SymmGroup> bond_dim = Index<SymmGroup>());
93 
94  void shift_aux_charges(typename SymmGroup::charge);
95 
98  void multiply_by_scalar(const scalar_type&);
99  void divide_by_scalar(const scalar_type&);
100 
101  scalar_type scalar_overlap(MPSTensor const &) const;
102  real_type scalar_norm() const;
103 
104  // this is completely useless in C++, only exists for consistency with Python
105  MPSTensor copy() const;
106 
108  block_matrix<Matrix, SymmGroup> const & data() const;
110 
111  std::vector<block_matrix<Matrix, SymmGroup> > to_list() const;
112 
113  template<class Matrix_, class SymmGroup_>
114  friend std::ostream& operator<<(std::ostream&, MPSTensor<Matrix_, SymmGroup_> const &);
115 
116  // math functions: these are not part of the Python code, but required by IETL
117  MPSTensor const & operator*=(const scalar_type&);
118  MPSTensor const & operator/=(const scalar_type&);
119 
120  MPSTensor const & operator+=(MPSTensor const &);
121  MPSTensor const & operator-=(MPSTensor const &);
122 
123  void make_left_paired() const;
124  void make_right_paired() const;
125 
126  void conjugate_inplace();
127  void swap_with(MPSTensor & b);
128  friend void swap(MPSTensor& a, MPSTensor& b){
129  a.swap_with(b);
130  }
131  template<class Matrix_, class SymmGroup_>
133 
134  template<class Archive> void load(Archive & ar);
135  template<class Archive> void save(Archive & ar) const;
136 
137  void check_equal(MPSTensor<Matrix, SymmGroup> const &) const;
138  bool reasonable() const;
139  bool num_check() const; // checks for nan or inf
140 
142 private:
143  mutable block_matrix<Matrix, SymmGroup> data_;
144  mutable MPSStorageLayout cur_storage;
145  Indicator cur_normalization;
146 };
147 
148 // this is also required by IETL
149 template<class Matrix, class SymmGroup>
152 {
153  m *= t;
154  return m;
155 }
156 template<class Matrix, class SymmGroup>
159 {
160  m *= t;
161  return m;
162 }
163 template<class Matrix, class SymmGroup>
166 {
167  m /= t;
168  return m;
169 }
170 
171 template<class Matrix, class SymmGroup>
173  MPSTensor<Matrix, SymmGroup> const & m2)
174 {
175  m -= m2;
176  return m;
177 }
178 template<class Matrix, class SymmGroup>
180  MPSTensor<Matrix, SymmGroup> const & m2)
181 {
182  m += m2;
183  return m;
184 }
185 
186 template<class Matrix, class SymmGroup>
188 {
189  m *= typename MPSTensor<Matrix, SymmGroup>::scalar_type(-1.0);
190  return m;
191 }
192 
193 
194 template<class Matrix, class SymmGroup>
195 std::size_t size_of(MPSTensor<Matrix, SymmGroup> const & m)
196 {
197  return size_of(m.data());
198 }
199 
201 
202 #endif
definition of the MPSTensor class
block_matrix< Matrix, SymmGroup > normalize_right(DecompMethod method=DefaultSolver(), bool multiplied=true, double truncation=0, Index< SymmGroup > bond_dim=Index< SymmGroup >())
Definition: mpstensor.hpp:245
void multiply_by_scalar(const scalar_type &)
Definition: mpstensor.hpp:316
real_type scalar_norm() const
Definition: mpstensor.hpp:339
void make_left_paired() const
Definition: mpstensor.hpp:173
double magnitude_type
Definition: mpstensor.h:55
bool isrightnormalized(bool test=false) const
Definition: mpstensor.hpp:404
Matrix::value_type value_type
Definition: mpstensor.h:54
Index< SymmGroup > const & col_dim() const
Definition: mpstensor.hpp:161
friend MPSTensor< Matrix_, SymmGroup_ > join(MPSTensor< Matrix_, SymmGroup_ > const &, MPSTensor< Matrix_, SymmGroup_ > const &, boundary_flag_t)
bool isobccompatible(Indicator) const
Definition: mpstensor.hpp:167
std::size_t size_type
Definition: mpstensor.h:56
T::value_type type
Definition: traits.hpp:8
MPSTensor const & operator/=(const scalar_type &)
Definition: mpstensor.hpp:454
void load(Archive &ar)
Definition: mpstensor.hpp:524
MPSTensor< Matrix, SymmGroup > operator-(MPSTensor< Matrix, SymmGroup > m, MPSTensor< Matrix, SymmGroup > const &m2)
Definition: mpstensor.h:172
maquis::traits::scalar_type< Matrix >::type scalar_type
Definition: mpstensor.h:52
void make_right_paired() const
Definition: mpstensor.hpp:188
void check_equal(MPSTensor< Matrix, SymmGroup > const &) const
Definition: mpstensor.hpp:596
scalar_type scalar_overlap(MPSTensor const &) const
Definition: mpstensor.hpp:356
declaration of block_matrix class
Index< SymmGroup > const & row_dim() const
Definition: mpstensor.hpp:155
std::size_t size_of(MPSTensor< Matrix, SymmGroup > const &m)
Definition: mpstensor.h:195
MPSTensor< Matrix, SymmGroup > operator/(MPSTensor< Matrix, SymmGroup > m, const typename MPSTensor< Matrix, SymmGroup >::scalar_type &t)
Definition: mpstensor.h:164
void save(Archive &ar) const
Definition: mpstensor.hpp:537
MPSTensor< Matrix, SymmGroup > operator+(MPSTensor< Matrix, SymmGroup > m, MPSTensor< Matrix, SymmGroup > const &m2)
Definition: mpstensor.h:179
void multiply_from_left(block_matrix< Matrix, SymmGroup > const &)
Definition: mpstensor.hpp:305
include one of the Index class definitions
void conjugate_inplace()
Definition: mpstensor.hpp:332
block_matrix< Matrix, SymmGroup > normalize_left(DecompMethod method=DefaultSolver(), bool multiplied=true, double truncation=0, Index< SymmGroup > bond_dim=Index< SymmGroup >())
Definition: mpstensor.hpp:204
DecompMethod
Definition: mpstensor.h:41
bool isnormalized(bool test=false) const
Definition: mpstensor.hpp:413
Index< SymmGroup > phys_i
Definition: mpstensor.h:141
void replace_left_paired(block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
Definition: mpstensor.hpp:113
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)
Definition: mpstensor.hpp:43
real_type< typename T::value_type >::type type
Definition: traits.hpp:9
void shift_aux_charges(typename SymmGroup::charge)
Definition: mpstensor.hpp:285
block_matrix< Matrix, SymmGroup > const & const_data() const
Definition: mpstensor.hpp:438
std::vector< block_matrix< Matrix, SymmGroup > > to_list() const
bool isleftnormalized(bool test=false) const
Definition: mpstensor.hpp:395
Definition: mpstensor.h:41
bool num_check() const
Definition: mpstensor.hpp:579
void multiply_from_right(block_matrix< Matrix, SymmGroup > const &)
Definition: mpstensor.hpp:294
std::size_t num_elements() const
Definition: mpstensor.hpp:639
Index< SymmGroup > const & site_dim() const
Definition: mpstensor.hpp:149
MPSTensor< Matrix, SymmGroup > operator*(const typename MPSTensor< Matrix, SymmGroup >::scalar_type &t, MPSTensor< Matrix, SymmGroup > m)
Definition: mpstensor.h:150
Index< SymmGroup > left_i
Definition: mpstensor.h:141
friend void swap(MPSTensor &a, MPSTensor &b)
Definition: mpstensor.h:128
MPSStorageLayout
Definition: mpstensor.h:38
MPSTensor const & operator+=(MPSTensor const &)
Definition: mpstensor.hpp:462
boundary_flag_t
Definition: mpstensor.h:37
void swap_with(MPSTensor &b)
Definition: mpstensor.hpp:511
Index< SymmGroup > right_i
Definition: mpstensor.h:141
Indicator
Definition: mpstensor.h:40
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
void replace_right_paired(block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
Definition: mpstensor.hpp:131
Definition: mpstensor.h:41
MPSTensor copy() const
MPSTensor const & operator*=(const scalar_type &)
Definition: mpstensor.hpp:446
bool reasonable() const
Definition: mpstensor.hpp:547
maquis::traits::real_type< Matrix >::type real_type
Definition: mpstensor.h:53
void divide_by_scalar(const scalar_type &)
Definition: mpstensor.hpp:324
MPSTensor const & operator-=(MPSTensor const &)
Definition: mpstensor.hpp:488