ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mps.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 MPS_H
28 #define MPS_H
29 
33 
34 #include <limits>
35 
36 template<class Matrix, class SymmGroup>
38 
39 template<class Matrix, class SymmGroup>
40 class MPS
41 {
42  typedef std::vector<MPSTensor<Matrix, SymmGroup> > data_t;
43 public:
44  typedef std::size_t size_t;
45 
46  // reproducing interface of std::vector
47  typedef typename data_t::size_type size_type;
48  typedef typename data_t::value_type value_type;
49  typedef typename data_t::iterator iterator;
50  typedef typename data_t::const_iterator const_iterator;
52 
53  MPS();
54  MPS(size_t L);
55  MPS(size_t L, mps_initializer<Matrix, SymmGroup> & init);
56 
57  size_t size() const { return data_.size(); }
58  size_t length() const { return size(); }
59  Index<SymmGroup> const & site_dim(size_t i) const { return data_[i].site_dim(); }
60  Index<SymmGroup> const & row_dim(size_t i) const { return data_[i].row_dim(); }
61  Index<SymmGroup> const & col_dim(size_t i) const { return data_[i].col_dim(); }
62 
63  value_type const & operator[](size_t i) const;
64  value_type& operator[](size_t i);
65 
66  void resize(size_t L);
67 
68  const_iterator begin() const {return data_.begin();}
69  const_iterator end() const {return data_.end();}
70  const_iterator const_begin() const {return data_.begin();}
71  const_iterator const_end() const {return data_.end();}
72  iterator begin() {return data_.begin();}
73  iterator end() {return data_.end();}
74 
75  size_t canonization(bool=false) const;
76  void canonize(size_t center, DecompMethod method = DefaultSolver());
77 
78  void normalize_left();
79  void normalize_right();
80 
81  void move_normalization_l2r(size_t p1, size_t p2, DecompMethod method=DefaultSolver());
82  void move_normalization_r2l(size_t p1, size_t p2, DecompMethod method=DefaultSolver());
83 
84  std::string description() const;
85 
86  template<class OtherMatrix>
90  std::size_t l, double alpha,
91  double cutoff, std::size_t Mmax);
92  template<class OtherMatrix>
96  std::size_t l, double alpha,
97  double cutoff, std::size_t Mmax);
98 
101 
104 
105  friend void swap(MPS& a, MPS& b)
106  {
107  using std::swap;
108  swap(a.data_, b.data_);
109  swap(a.canonized_i, b.canonized_i);
110  }
111 
112 private:
113 
114  data_t data_;
115  mutable size_t canonized_i;
116 };
117 
118 template<class Matrix, class SymmGroup>
119 void load(std::string const& dirname, MPS<Matrix, SymmGroup> & mps);
120 template<class Matrix, class SymmGroup>
121 void save(std::string const& dirname, MPS<Matrix, SymmGroup> const& mps);
122 
123 template<class Matrix, class SymmGroup>
124 struct mps_initializer
125 {
126  virtual ~mps_initializer() {}
127  virtual void operator()(MPS<Matrix, SymmGroup> & mps) = 0;
128 };
129 
130 template<class Matrix, class SymmGroup>
132  MPS<Matrix, SymmGroup> const & b,
133  double alpha=1., double beta=1.)
134 {
135  assert( a.length() == b.length() );
136 
137  MPSTensor<Matrix, SymmGroup> aright=a[a.length()-1], bright=b[a.length()-1];
138  aright.multiply_by_scalar(alpha);
139  bright.multiply_by_scalar(beta);
140 
142  ret[0] = join(a[0],b[0],l_boundary_f);
143  ret[a.length()-1] = join(aright,bright,r_boundary_f);
144  for (std::size_t p = 1; p < a.length()-1; ++p)
145  ret[p] = join(a[p], b[p]);
146  return ret;
147 }
148 
149 #include "dmrg/mp_tensors/mps.hpp"
150 
151 #endif
void move_normalization_l2r(size_t p1, size_t p2, DecompMethod method=DefaultSolver())
Definition: mps.hpp:167
definition of the MPS object
definition of Boundary object
std::size_t size_t
Definition: mps.h:44
data_t::iterator iterator
Definition: mps.h:49
void normalize_left()
Definition: mps.hpp:124
void move_normalization_r2l(size_t p1, size_t p2, DecompMethod method=DefaultSolver())
Definition: mps.hpp:190
virtual void operator()(MPS< Matrix, SymmGroup > &mps)=0
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)
Definition: mps.hpp:233
maquis::traits::scalar_type< Matrix >::type scalar_type
Definition: mpstensor.h:52
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
const_iterator const_end() const
Definition: mps.h:71
virtual ~mps_initializer()
Definition: mps.h:126
void load(std::string const &dirname, MPS< Matrix, SymmGroup > &mps)
Definition: mps.hpp:315
iterator end()
Definition: mps.h:73
Boundary< Matrix, SymmGroup > left_boundary() const
Definition: mps.hpp:253
data_t::const_iterator const_iterator
Definition: mps.h:50
size_t canonization(bool=false) const
Definition: mps.hpp:99
data_t::size_type size_type
Definition: mps.h:47
const_iterator end() const
Definition: mps.h:69
Boundary< Matrix, SymmGroup > right_boundary() const
Definition: mps.hpp:266
Index< SymmGroup > const & row_dim(size_t i) const
Definition: mps.h:60
Index< SymmGroup > const & col_dim(size_t i) const
Definition: mps.h:61
DecompMethod
Definition: mpstensor.h:41
size_t size() const
Definition: mps.h:57
data_t::value_type value_type
Definition: mps.h:48
MPS()
Definition: mps.hpp:50
iterator begin()
Definition: mps.h:72
Definition: mps.h:40
declaration of the MPSTensor class
void apply(block_matrix< Matrix, SymmGroup > const &, size_type)
MPS< Matrix, SymmGroup > join(MPS< Matrix, SymmGroup > const &a, MPS< Matrix, SymmGroup > const &b, double alpha=1., double beta=1.)
Definition: mps.h:131
MPSTensor< Matrix, SymmGroup >::scalar_type scalar_type
Definition: mps.h:51
void normalize_right()
Definition: mps.hpp:134
const_iterator const_begin() const
Definition: mps.h:70
declaration of MPOTensor object
size_t length() const
Definition: mps.h:58
std::string description() const
Definition: mps.hpp:35
void canonize(size_t center, DecompMethod method=DefaultSolver())
Definition: mps.hpp:147
Index< SymmGroup > const & site_dim(size_t i) const
Definition: mps.h:59
void resize(size_t L)
Definition: mps.hpp:91
value_type const & operator[](size_t i) const
Definition: mps.hpp:79
void save(std::string const &dirname, MPS< Matrix, SymmGroup > const &mps)
Definition: mps.hpp:333
friend void swap(MPS &a, MPS &b)
Definition: mps.h:105
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)
Definition: mps.hpp:212
const_iterator begin() const
Definition: mps.h:68