ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ietl_lanczos_solver.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 IETL_LANCZOS_SOLVER_H
28 #define IETL_LANCZOS_SOLVER_H
29 
31 
32 namespace ietl
33 {
34  template<class Matrix, class SymmGroup, class Generator> void generate(MPSTensor<Matrix, SymmGroup> & m, Generator g)
35  {
36  m.data().generate(g);
37  }
38 
39  template<class Matrix, class SymmGroup> void generate(MPSTensor<Matrix, SymmGroup> & m, MPSTensor<Matrix, SymmGroup> const & m2)
40  {
41  m = m2;
42  }
43 
44  template<class Matrix, class SymmGroup> void swap(MPSTensor<Matrix, SymmGroup> & x, MPSTensor<Matrix, SymmGroup> & y)
45  {
46  x.swap_with(y);
47  }
48 
49  template<class Matrix, class SymmGroup>
52  {
53  return x.scalar_overlap(y);
54  }
55 
56  template<class Matrix, class SymmGroup>
59  {
60  return x.scalar_norm();
61  }
62 }
63 
64 template<class Matrix, class SymmGroup> struct SiteProblem;
65 
66 template<class Matrix, class SymmGroup>
68 {
69 public:
71  std::vector<MPSTensor<Matrix, SymmGroup> > const & ortho_vecs)
72  : instance(m)
73  , ortho_vecs(ortho_vecs)
74  {
75  for (std::size_t k = 0; k < m.data().n_blocks(); ++k)
76  N += num_rows(m.data()[k]) * num_cols(m.data()[k]);
77  }
78 
80  {
81  return vs.instance;
82  }
83 
84  friend std::size_t vec_dimension(SingleSiteVS const & vs)
85  {
86  return vs.N;
87  }
88 
90  {
91  for (typename std::vector<MPSTensor<Matrix, SymmGroup> >::const_iterator it = ortho_vecs.begin();
92  it != ortho_vecs.end(); ++it)
93  t -= ietl::dot(*it,t)/ietl::dot(*it,*it)**it;
94  }
95 
96 private:
98  std::vector<MPSTensor<Matrix, SymmGroup> > ortho_vecs;
99 
100  std::size_t N;
101 };
102 
103 #include <ietl/vectorspace.h>
104 
105 namespace ietl
106 {
107  template<class Matrix, class SymmGroup>
111  {
112  y = contraction::site_hamil2(x, H.left, H.right, H.mpo);
113  x.make_left_paired();
114  }
115 
116  template<class Matrix, class SymmGroup>
117  struct vectorspace_traits<SingleSiteVS<Matrix, SymmGroup> >
118  {
122  typedef std::size_t size_type;
123  };
124 }
125 
126 #include <ietl/lanczos.h>
127 
128 template<class Matrix, class SymmGroup>
129 std::pair<double, MPSTensor<Matrix, SymmGroup> >
131  MPSTensor<Matrix, SymmGroup> const & initial,
132  BaseParameters & params)
133 {
134  typedef MPSTensor<Matrix, SymmGroup> Vector;
135 
137 
138  typedef ietl::vectorspace<Vector> Vecspace;
139  typedef boost::lagged_fibonacci607 Gen;
140 
141  ietl::lanczos<SiteProblem<Matrix, SymmGroup>, SingleSiteVS<Matrix, SymmGroup> > lanczos(sp, vs);
142 
143  // Vector test;
144  // ietl::mult(sp, mps[site], test);
145  // test.divide_by_scalar(test.scalar_norm());
146  // test -= mps[site];
147  // maquis::cout << "How close to eigenstate? " << test.scalar_norm() << std::endl;
148 
149  double rel_tol = sqrt(std::numeric_limits<double>::epsilon());
150  double abs_tol = rel_tol;
151  int n_evals = 1;
152  ietl::lanczos_iteration_nlowest<double>
153  iter(100, n_evals, rel_tol, abs_tol);
154 
155  std::vector<double> eigen, err;
156  std::vector<int> multiplicity;
157 
158  try{
159  lanczos.calculate_eigenvalues(iter, initial);
160  eigen = lanczos.eigenvalues();
161  err = lanczos.errors();
162  multiplicity = lanczos.multiplicities();
163  maquis::cout << "IETL used " << iter.iterations() << " iterations." << std::endl;
164  }
165  catch (std::runtime_error& e) {
166  maquis::cout << "Error in eigenvalue calculation: " << std::endl;
167  maquis::cout << e.what() << std::endl;
168  exit(1);
169  }
170 
171 // maquis::cout << "Energies: ";
172 // std::copy(eigen.begin(), eigen.begin()+n_evals, std::ostream_iterator<double>(maquis::cout, " "));
173 // maquis::cout << std::endl;
174  // maquis::cout << "Energy: " << eigen[0] << std::endl;
175 
176  std::vector<double>::iterator start = eigen.begin();
177  std::vector<double>::iterator end = eigen.begin()+1;
178  std::vector<Vector> eigenvectors; // for storing the eigenvectors.
179  ietl::Info<double> info; // (m1, m2, ma, eigenvalue, residualm, status).
180 
181  try {
182  lanczos.eigenvectors(start, end, std::back_inserter(eigenvectors), info, initial, 100);
183  }
184  catch (std::runtime_error& e) {
185  maquis::cout << "Error in eigenvector calculation: " << std::endl;
186  maquis::cout << e.what() << std::endl;
187  exit(1);
188  }
189 
190  // for(int i = 0; i < info.size(); i++)
191  // maquis::cout << " m1(" << i+1 << "): " << info.m1(i) << ", m2(" << i+1 << "): "
192  // << info.m2(i) << ", ma(" << i+1 << "): " << info.ma(i) << " eigenvalue("
193  // << i+1 << "): " << info.eigenvalue(i) << " residual(" << i+1 << "): "
194  // << info.residual(i) << " error_info(" << i+1 << "): "
195  // << info.error_info(i) << "\n\n";
196 
197  assert( eigenvectors[0].scalar_norm() > 1e-8 );
198  assert( info.error_info(0) == 0 );
199 
200  return std::make_pair(*eigen.begin(), eigenvectors[0]);
201 }
202 
203 #endif
real_type scalar_norm() const
Definition: mpstensor.hpp:339
void make_left_paired() const
Definition: mpstensor.hpp:173
MPSTensor< Matrix, SymmGroup >::value_type scalar_type
double magnitude_type
Definition: mpstensor.h:55
MPOTensor< Matrix, SymmGroup > const & mpo
Matrix::value_type value_type
Definition: mpstensor.h:54
friend MPSTensor< Matrix, SymmGroup > new_vector(SingleSiteVS const &vs)
std::pair< double, MPSTensor< Matrix, SymmGroup > > solve_ietl_lanczos(SiteProblem< Matrix, SymmGroup > &sp, MPSTensor< Matrix, SymmGroup > const &initial, BaseParameters &params)
maquis::traits::scalar_type< Matrix >::type scalar_type
Definition: mpstensor.h:52
SingleSiteVS(MPSTensor< Matrix, SymmGroup > const &m, std::vector< MPSTensor< Matrix, SymmGroup > > const &ortho_vecs)
scalar_type scalar_overlap(MPSTensor const &) const
Definition: mpstensor.hpp:356
friend std::size_t vec_dimension(SingleSiteVS const &vs)
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
static MPSTensor< Matrix, SymmGroup > site_hamil2(MPSTensor< Matrix, SymmGroup > ket_tensor, Boundary< OtherMatrix, SymmGroup > const &left, Boundary< OtherMatrix, SymmGroup > const &right, MPOTensor< Matrix, SymmGroup > const &mpo)
Definition: contractions.h:431
Boundary< typename storage::constrained< Matrix >::type, SymmGroup > const & left
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:99
block_matrix< Matrix, SymmGroup > sqrt(block_matrix< Matrix, SymmGroup > m)
MPSTensor< Matrix, SymmGroup >::magnitude_type magnitude_type
MPSTensor< Matrix, SymmGroup >::scalar_type dot(MPSTensor< Matrix, SymmGroup > const &x, MPSTensor< Matrix, SymmGroup > const &y)
void generate(MPSTensor< Matrix, SymmGroup > &m, Generator g)
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:102
void project(MPSTensor< Matrix, SymmGroup > &t) const
Boundary< typename storage::constrained< Matrix >::type, SymmGroup > const & right
void swap_with(MPSTensor &b)
Definition: mpstensor.hpp:511
MPSTensor< Matrix, SymmGroup >::real_type two_norm(MPSTensor< Matrix, SymmGroup > const &x)
void mult(SiteProblem< Matrix, SymmGroup > const &H, MPSTensor< Matrix, SymmGroup > const &x, MPSTensor< Matrix, SymmGroup > &y)
block_matrix< Matrix, SymmGroup > & data()
Definition: mpstensor.hpp:423
maquis::traits::real_type< Matrix >::type real_type
Definition: mpstensor.h:53