ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpo_contractor_ss.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 MP_TENSORS_MPO_CONTRACTOR_SS_H
28 #define MP_TENSORS_MPO_CONTRACTOR_SS_H
29 
30 #include <boost/random.hpp>
31 
34 #ifdef HAVE_ARPACK
35 #include "dmrg/optimize/arpackpp_solver.h"
36 #endif
37 
39 
40 
41 template<class Matrix, class SymmGroup>
43 {
45  Boundary<typename storage::constrained<Matrix>::type, SymmGroup> const & left_,
46  Boundary<typename storage::constrained<Matrix>::type, SymmGroup> const & right_,
47  MPOTensor<Matrix, SymmGroup> const & mpo_)
48  : ket_tensor(ket_tensor_)
49  , left(left_)
50  , right(right_)
51  , mpo(mpo_) { }
52 
57 };
58 
59 #define BEGIN_TIMING(name) \
60 now = boost::chrono::high_resolution_clock::now();
61 #define END_TIMING(name) \
62 then = boost::chrono::high_resolution_clock::now(); \
63  maquis::cout << "Time elapsed in " << name << ": " << boost::chrono::duration<double>(then-now).count() << std::endl;
64 
65 
66 /// TODO: 1) implement two-site time evolution. (single-site is stuck in initial MPS structure)
67 /// 2) implement zip-up compression. E. M. Stoudenmire and S. R. White, New Journal of Physics 12, 055026 (2010).
68 
69 template<class Matrix, class SymmGroup, class Storage>
71 {
72 public:
74  MPO<Matrix, SymmGroup> const & mpo_,
75  BaseParameters & parms_)
76  : mps(mps_)
77  , mpsp(mps_)
78  , mpo(mpo_)
79  , parms(parms_)
80  {
81  mps.canonize(0);
82  init_left_right(mpo);
83 
84  mpsp = mps;
85  }
86 
87  std::pair<double,double> sweep(int sweep)
88  {
89  boost::chrono::high_resolution_clock::time_point sweep_now = boost::chrono::high_resolution_clock::now();
90 
91  std::size_t L = mps.length();
92 
93  std::pair<double,double> eps;
95  norm_boudary.insert_block(Matrix(1, 1, 1), SymmGroup::IdentityCharge, SymmGroup::IdentityCharge);
96 
97  for (int _site = 0; _site < 2*L; ++_site)
98  {
99  int site, lr;
100  if (_site < L) {
101  site = _site;
102  lr = 1;
103  } else {
104  site = 2*L-_site-1;
105  lr = -1;
106  }
107 
108  SiteProblem<Matrix, SymmGroup> sp(mps[site], left_[site], right_[site+1], mpo[site]);
109  ietl::mult(sp, mps[site], mpsp[site]);
110 
111  if (lr == +1) {
112  if (site < L-1) {
114  t = mpsp[site].normalize_left(DefaultSolver());
115  mpsp[site+1].multiply_from_left(t);
116  }
117 
118  left_[site+1] = contraction::overlap_mpo_left_step(mpsp[site], mps[site], left_[site], mpo[site]);
119  norm_boudary = contraction::overlap_left_step(mpsp[site], MPSTensor<Matrix,SymmGroup>(mpsp[site]), norm_boudary);
120  } else if (lr == -1) {
121  if (site > 0) {
123  t = mpsp[site].normalize_right(DefaultSolver());
124  mpsp[site-1].multiply_from_right(t);
125  }
126 
127  right_[site] = contraction::overlap_mpo_right_step(mpsp[site], mps[site], right_[site+1], mpo[site]);
128  norm_boudary = contraction::overlap_right_step(mpsp[site], MPSTensor<Matrix,SymmGroup>(mpsp[site]), norm_boudary);
129  }
130 
131  if (_site == L-1) {
132  double nn = maquis::real( norm_boudary.trace() );
133  eps.first = nn - 2.*maquis::real(left_[L][0].trace());
134 
135  /// prepare backward sweep
136  norm_boudary = block_matrix<Matrix, SymmGroup>();
137  norm_boudary.insert_block(Matrix(1, 1, 1), mps[L-1].col_dim()[0].first, mps[L-1].col_dim()[0].first);
138  }
139 
140  if (_site == 2*L-1) {
141  double nn = maquis::real( norm_boudary.trace() );
142  eps.second = nn - 2.*maquis::real(right_[0][0].trace());
143  }
144 
145  }
146 
147  return eps; /// note: the actual eps contain a constant, which is not important here.
148  }
149 
150  void finalize()
151  {
152  mpsp[0].normalize_right(DefaultSolver());
153  }
154 
155  MPS<Matrix, SymmGroup> get_original_mps() const { return mps; }
156  MPS<Matrix, SymmGroup> get_current_mps() const { return mpsp; }
157 
158 private:
159  void init_left_right(MPO<Matrix, SymmGroup> const & mpo)
160  {
161  std::size_t L = mps.length();
162 
163  left_.resize(mpo.length()+1);
164  right_.resize(mpo.length()+1);
165 
166  Storage::drop(left_[0]);
167  left_[0] = mps.left_boundary();
168  Storage::evict(left_[0]);
169 
170  for (int i = 0; i < L; ++i) {
171  Storage::drop(left_[i+1]);
172  left_[i+1] = contraction::overlap_mpo_left_step(mpsp[i], mps[i], left_[i], mpo[i]);
173  Storage::evict(left_[i+1]);
174  }
175 
176  Storage::drop(right_[L]);
177  right_[L] = mps.right_boundary();
178  Storage::evict(right_[L]);
179 
180  for(int i = L-1; i >= 0; --i) {
181  Storage::drop(right_[i]);
182  right_[i] = contraction::overlap_mpo_right_step(mpsp[i], mps[i], right_[i+1], mpo[i]);
183  Storage::evict(right_[i]);
184  }
185  }
186 
187  MPS<Matrix, SymmGroup> mps, mpsp;
188  MPO<Matrix, SymmGroup> const& mpo;
189 
190  BaseParameters & parms;
191  std::vector<Boundary<typename storage::constrained<Matrix>::type, SymmGroup> > left_, right_;
192 };
193 
194 #endif
195 
MPSTensor< Matrix, SymmGroup > const & ket_tensor
MPOTensor< Matrix, SymmGroup > const & mpo
call IETL Lanczos solver
static block_matrix< OtherMatrix, SymmGroup > overlap_right_step(MPSTensor< Matrix, SymmGroup > const &bra_tensor, MPSTensor< Matrix, SymmGroup > const &ket_tensor, block_matrix< OtherMatrix, SymmGroup > const &right, block_matrix< OtherMatrix, SymmGroup > *localop=NULL)
Definition: contractions.h:71
call IETL Jacobi-Davidson solver
size_type insert_block(Matrix const &, charge, charge)
static Boundary< OtherMatrix, SymmGroup > overlap_mpo_right_step(MPSTensor< Matrix, SymmGroup > const &bra_tensor, MPSTensor< Matrix, SymmGroup > const &ket_tensor, Boundary< OtherMatrix, SymmGroup > const &right, MPOTensor< Matrix, SymmGroup > const &mpo)
Definition: contractions.h:386
SiteProblem(MPSTensor< Matrix, SymmGroup > const &ket_tensor_, Boundary< typename storage::constrained< Matrix >::type, SymmGroup > const &left_, Boundary< typename storage::constrained< Matrix >::type, SymmGroup > const &right_, MPOTensor< Matrix, SymmGroup > const &mpo_)
Boundary< typename storage::constrained< Matrix >::type, SymmGroup > const & left
Definition: mpo.h:36
scalar_type trace() const
static block_matrix< OtherMatrix, SymmGroup > overlap_left_step(MPSTensor< Matrix, SymmGroup > const &bra_tensor, MPSTensor< Matrix, SymmGroup > const &ket_tensor, block_matrix< OtherMatrix, SymmGroup > const &left, block_matrix< OtherMatrix, SymmGroup > *localop=NULL)
Definition: contractions.h:41
block_matrix< Matrix, SymmGroup >::scalar_type trace(block_matrix< Matrix, SymmGroup > const &m)
mpo_contractor_ss(MPS< Matrix, SymmGroup > const &mps_, MPO< Matrix, SymmGroup > const &mpo_, BaseParameters &parms_)
Definition: mps.h:40
MPS< Matrix, SymmGroup > get_current_mps() const
std::pair< double, double > sweep(int sweep)
static Boundary< OtherMatrix, SymmGroup > overlap_mpo_left_step(MPSTensor< Matrix, SymmGroup > const &bra_tensor, MPSTensor< Matrix, SymmGroup > const &ket_tensor, Boundary< OtherMatrix, SymmGroup > const &left, MPOTensor< Matrix, SymmGroup > const &mpo)
Definition: contractions.h:340
Boundary< typename storage::constrained< Matrix >::type, SymmGroup > const & right
void mult(SiteProblem< Matrix, SymmGroup > const &H, MPSTensor< Matrix, SymmGroup > const &x, MPSTensor< Matrix, SymmGroup > &y)
alps::numeric::real_type< T >::type real(T f)
Definition: bindings.hpp:38
MPS< Matrix, SymmGroup > get_original_mps() const