ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpo_ops.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 MPO_OPS_H
28 #define MPO_OPS_H
29 
30 #include "mpo.h"
31 #include "mpotensor.h"
32 
33 template<class Matrix, class SymmGroup>
35 {
36  if (m.n_blocks() == 2)
37  return "I";
38  else {
39  typename SymmGroup::charge c1 = m.left_basis()[0].first, c2 = m.right_basis()[0].first;
40  if (c1 == 1 && c2 == 0)
41  return "c";
42  else if (c1 == 0 && c2 == 1)
43  return "d";
44  else if (c1 == 1 && c2 == 1)
45  return "cd";
46  else if (c1 == 0 && c2 == 0)
47  return "dc";
48  }
49 
50  return "wtf?";
51 }
52 
53 template<class Matrix, class SymmGroup>
55  std::string s = std::string(),
56  int p = 0, int start = 0)
57 {
58  for (size_t k = 0; k < mpo[p].col_dim(); ++k)
59  {
60  if (mpo[p].at(start,k).op.n_blocks() == 0)
61  continue;
62 
63  std::ostringstream oss;
64 // oss << mpo[p](start, k) << std::endl;
65 // oss << "(" << start << "," << k << ") ";
66  oss << " " << identify_op(mpo[p].at(start, k).op) << " ";
67  if (p+1 < mpo.length())
68  follow_mpo(mpo, s+oss.str(), p+1, k);
69  else
70  maquis::cout << s+oss.str() << std::endl;
71  }
72 }
73 
74 template<class Matrix, class SymmGroup>
75 void follow_and_print_terms(MPO<Matrix, SymmGroup> const& mpo, int p, int b1, int b2, std::string s="", typename MPOTensor<Matrix,SymmGroup>::value_type scale=1.)
76 {
77  std::stringstream ss;
78  ss << s;
79 
80  if (p > -1) {
82  scale *= access.scale;
83  ss << " {" << mpo[p].tag_number(b1,b2) << "}(" << p << ")";
84  }
85 
86  if (p == mpo.size()-1) {
87  maquis::cout << "---" << std::endl;
88  maquis::cout << "scale: " << scale << std::endl;
89  maquis::cout << "term: " << ss.str() << std::endl;
90  return;
91  }
92 
93  typedef typename MPOTensor<Matrix, SymmGroup>::row_proxy row_proxy;
94  typedef typename MPOTensor<Matrix, SymmGroup>::col_proxy col_proxy;
95  row_proxy myrow = mpo[p+1].row(b2);
96  for (typename row_proxy::const_iterator row_it = myrow.begin(); row_it != myrow.end(); ++row_it)
97  follow_and_print_terms(mpo, p+1, b2, row_it.index(), ss.str(), scale);
98 }
99 
100 
101 template<class Matrix, class SymmGroup>
103  MPO<Matrix, SymmGroup> & out_mpo,
104  std::vector<boost::tuple<int, int, block_matrix<Matrix, SymmGroup> > > & ops,
105  int p, int start)
106 {
107  for (std::size_t k = 0; k < in_mpo[p].col_dim(); ++k)
108  {
109  if (!in_mpo[p].has(start,k))
110  continue;
111  if (in_mpo[p].at(start,k).op.n_blocks() == 0)
112  continue;
113 
114  ops[p] = boost::make_tuple(start, k, in_mpo[p].at(start, k).op * in_mpo[p].at(start, k).scale);
115 
116  if (p+1 < in_mpo.length())
117  cleanup_mpo_(in_mpo, out_mpo, ops, p+1, k);
118  else
119  {
120  assert( ops.size() == out_mpo.length() );
121  using boost::tuples::get;
122  for (std::size_t t = 0; t < in_mpo.length(); ++t) {
123  MPOTensor_detail::term_descriptor<Matrix, SymmGroup> o = out_mpo[t].at(get<0>(ops[t]), get<1>(ops[t]));
124  if (o.op.n_blocks() == 0) {
125  o.op = get<2>(ops[t]);
126  o.scale = 1.;
127  }
128  }
129  }
130  }
131 }
132 
133 template<class Matrix, class SymmGroup>
135 {
136  MPO<Matrix, SymmGroup> ret(mpo.length());
137  for (std::size_t p = 0; p < ret.length(); ++p)
138  ret[p] = MPOTensor<Matrix, SymmGroup>(mpo[p].row_dim(), mpo[p].col_dim());
139 
140  std::vector<boost::tuple<int, int, block_matrix<Matrix, SymmGroup> > > prempo(mpo.length());
141  cleanup_mpo_(mpo, ret, prempo, 0, 0);
142  return ret;
143 }
144 
145 template<class Matrix, class SymmGroup>
148 {
149  typedef typename SymmGroup::charge charge;
150  typedef typename MPOTensor<Matrix, SymmGroup>::row_proxy row_proxy;
151  typedef typename MPOTensor<Matrix, SymmGroup>::index_type index_type;
152 
153  size_t L = mpo.length();
154 
156 
157  for (size_t p = 0; p < L; ++p)
158  {
159  MPOTensor<Matrix, SymmGroup> const & inp = mpo[p];
160  maquis::cout << "MPOTensor " << inp.row_dim()*inp.row_dim() << " " << inp.col_dim()*inp.col_dim() << std::endl;
162  inp.col_dim()*inp.col_dim());
163 
164  for (index_type r1 = 0; r1 < inp.row_dim(); ++r1)
165  {
166  row_proxy row1 = inp.row(r1);
167  for (index_type r2 = 0; r2 < inp.row_dim(); ++r2)
168  {
169  row_proxy row2 = inp.row(r2);
170  for (typename row_proxy::const_iterator it1 = row1.begin(); it1 != row1.end(); ++it1)
171  {
172  index_type c1 = it1.index();
173  for (typename row_proxy::const_iterator it2 = row2.begin(); it2 != row2.end(); ++it2) {
174  index_type c2 = it2.index();
175 
176  assert(inp.has(r1, c1));
177  assert(inp.has(r2, c2));
178 
180  gemm(inp.at(r1, c1).op, inp.at(r2, c2).op, t);
181  if (t.n_blocks() > 0)
182  ret.set(r1*inp.row_dim()+r2, c1*inp.col_dim()+c2,
183  t * (inp.at(r1, c1).scale * inp.at(r2, c2).scale));
184  }
185  }
186  }
187  }
188 
189  sq[p] = ret;
190  }
191 
192  maquis::cout << "Done squaring." << std::endl;
193 
194  sq = cleanup_mpo(sq);
195  maquis::cout << "Done cleaning up." << std::endl;
196 
197  return sq;
198 }
199 
200 template<class Matrix, class SymmGroup>
203 {
204  typedef typename MPOTensor<Matrix, SymmGroup>::CSRMatrix CSRMatrix;
205  typedef typename MPOTensor<Matrix, SymmGroup>::CSCMatrix CSCMatrix;
206 
207  maquis::cout << "Zeroing out MPO after site " << p0 << std::endl;
208 
209  for (int p = p0+1; p < mpo.size(); ++p) {
210  for (int k = 2; k < mpo[p].row_dim(); ++k)
211  for (int l = 2; l < mpo[p].col_dim(); ++l)
212  if (mpo[p].has(k,l))
213  mpo[p].set(k,l, mpo[p].at(k,l).op, 0.0);
214 
215  if (mpo[p].has(0,1))
216  mpo[p].set(0,1, mpo[p].at(0,1).op, 0.0);
217  }
218 
219  return mpo;
220 }
221 
222 #endif
std::string identify_op(block_matrix< Matrix, SymmGroup > const &m)
Definition: mpo_ops.h:34
MPO< Matrix, SymmGroup > cleanup_mpo(MPO< Matrix, SymmGroup > const &mpo)
Definition: mpo_ops.h:134
index_type row_dim() const
Definition: mpotensor.hpp:179
size_type n_blocks() const
void cleanup_mpo_(MPO< Matrix, SymmGroup > const &in_mpo, MPO< Matrix, SymmGroup > &out_mpo, std::vector< boost::tuple< int, int, block_matrix< Matrix, SymmGroup > > > &ops, int p, int start)
Definition: mpo_ops.h:102
row_proxy row(index_type row_i) const
Definition: mpotensor.hpp:139
Definition: mpo.h:36
void follow_mpo(MPO< Matrix, SymmGroup > const &mpo, std::string s=std::string(), int p=0, int start=0)
Definition: mpo_ops.h:54
MPOTensor_detail::const_term_descriptor< Matrix, SymmGroup > at(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:120
MPO< Matrix, SymmGroup > zero_after(MPO< Matrix, SymmGroup > mpo, int p0)
Definition: mpo_ops.h:202
std::size_t index_type
Definition: mpotensor.h:52
definition of MPO class (vector of MPOTensor)
bool has(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:95
MPO< Matrix, SymmGroup > square_mpo(MPO< Matrix, SymmGroup > const &mpo)
Definition: mpo_ops.h:147
declaration of MPOTensor object
Index< SymmGroup > const & right_basis() const
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
boost::numeric::ublas::matrix_column< const CSCMatrix > col_proxy
Definition: mpotensor.h:72
Index< SymmGroup > const & left_basis() const
index_type col_dim() const
Definition: mpotensor.hpp:185
void follow_and_print_terms(MPO< Matrix, SymmGroup > const &mpo, int p, int b1, int b2, std::string s="", typename MPOTensor< Matrix, SymmGroup >::value_type scale=1.)
Definition: mpo_ops.h:75
Matrix::value_type value_type
Definition: mpotensor.h:53