ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
mpo_ops.h File Reference
#include "mpo.h"
#include "mpotensor.h"

Go to the source code of this file.

Functions

template<class Matrix , class SymmGroup >
std::string identify_op (block_matrix< Matrix, SymmGroup > const &m)
 
template<class Matrix , class SymmGroup >
void follow_mpo (MPO< Matrix, SymmGroup > const &mpo, std::string s=std::string(), int p=0, int start=0)
 
template<class Matrix , class SymmGroup >
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.)
 
template<class Matrix , class SymmGroup >
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)
 
template<class Matrix , class SymmGroup >
MPO< Matrix, SymmGroup > cleanup_mpo (MPO< Matrix, SymmGroup > const &mpo)
 
template<class Matrix , class SymmGroup >
MPO< Matrix, SymmGroup > square_mpo (MPO< Matrix, SymmGroup > const &mpo)
 
template<class Matrix , class SymmGroup >
MPO< Matrix, SymmGroup > zero_after (MPO< Matrix, SymmGroup > mpo, int p0)
 

Function Documentation

template<class Matrix , class SymmGroup >
MPO<Matrix, SymmGroup> cleanup_mpo ( MPO< Matrix, SymmGroup > const &  mpo)

Definition at line 134 of file mpo_ops.h.

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 }
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
Definition: mpo.h:36
template<class Matrix , class SymmGroup >
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 at line 102 of file mpo_ops.h.

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 }
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
template<class Matrix , class SymmGroup >
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 at line 75 of file mpo_ops.h.

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 }
boost::numeric::ublas::matrix_column< const CSCMatrix > col_proxy
Definition: mpotensor.h:72
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
template<class Matrix , class SymmGroup >
void follow_mpo ( MPO< Matrix, SymmGroup > const &  mpo,
std::string  s = std::string(),
int  p = 0,
int  start = 0 
)

Definition at line 54 of file mpo_ops.h.

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 }
std::string identify_op(block_matrix< Matrix, SymmGroup > const &m)
Definition: mpo_ops.h:34
void follow_mpo(MPO< Matrix, SymmGroup > const &mpo, std::string s=std::string(), int p=0, int start=0)
Definition: mpo_ops.h:54
template<class Matrix , class SymmGroup >
std::string identify_op ( block_matrix< Matrix, SymmGroup > const &  m)

Definition at line 34 of file mpo_ops.h.

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 }
size_type n_blocks() const
Index< SymmGroup > const & right_basis() const
Index< SymmGroup > const & left_basis() const
template<class Matrix , class SymmGroup >
MPO<Matrix, SymmGroup> square_mpo ( MPO< Matrix, SymmGroup > const &  mpo)

Definition at line 147 of file mpo_ops.h.

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 }
MPO< Matrix, SymmGroup > cleanup_mpo(MPO< Matrix, SymmGroup > const &mpo)
Definition: mpo_ops.h:134
index_type row_dim() const
Definition: mpotensor.hpp:179
row_proxy row(index_type row_i) const
Definition: mpotensor.hpp:139
Definition: mpo.h:36
MPOTensor_detail::const_term_descriptor< Matrix, SymmGroup > at(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:120
std::size_t index_type
Definition: mpotensor.h:52
bool has(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:95
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
index_type col_dim() const
Definition: mpotensor.hpp:185
template<class Matrix , class SymmGroup >
MPO<Matrix, SymmGroup> zero_after ( MPO< Matrix, SymmGroup >  mpo,
int  p0 
)

Definition at line 202 of file mpo_ops.h.

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 }