ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
mpo_manip.h File Reference
#include "dmrg/block_matrix/block_matrix.h"
#include "dmrg/block_matrix/block_matrix_algorithms.h"
#include "dmrg/block_matrix/multi_index.h"
#include "dmrg/mp_tensors/mpotensor.h"
#include "dmrg/mp_tensors/mpo.h"

Go to the source code of this file.

Functions

template<class Matrix , class SymmGroup >
MPO< Matrix, SymmGroup > block_to_mpo (Index< SymmGroup > const &phys_i, block_matrix< Matrix, SymmGroup > block, std::size_t length)
 

Function Documentation

template<class Matrix , class SymmGroup >
MPO<Matrix, SymmGroup> block_to_mpo ( Index< SymmGroup > const &  phys_i,
block_matrix< Matrix, SymmGroup >  block,
std::size_t  length 
)

Definition at line 39 of file mpo_manip.h.

42 {
43  MPO<Matrix, SymmGroup> mpo(length);
44 
45  typedef typename MultiIndex<SymmGroup>::index_id index_id;
46  typedef typename MultiIndex<SymmGroup>::set_id set_id;
47 
48 
49  Index<SymmGroup> alpha_i, beta_i;
50  alpha_i.insert( std::make_pair(SymmGroup::IdentityCharge,1) );
51  beta_i.insert( std::make_pair(SymmGroup::IdentityCharge,1) );
52 
53 
55  index_id alpha, beta;
56  std::vector<std::pair<index_id, bool> > in_left, in_right;
57  std::vector<std::pair<index_id, index_id> > phys_ids;
58 
59  alpha = midx.insert_index(alpha_i);
60  for (size_t i=0; i<length; ++i) {
61  index_id id1 = midx.insert_index(phys_i);
62  index_id id2 = midx.insert_index(phys_i);
63  phys_ids.push_back( std::make_pair(id1, id2) );
64 
65  in_left.push_back( std::make_pair(id1, true) );
66  in_right.push_back( std::make_pair(id2, true) );
67  }
68  beta = midx.insert_index(beta_i);
69  in_left.push_back( std::make_pair(beta, true) );
70  in_right.push_back( std::make_pair(alpha, true) );
71 
72  set_id curr_s = midx.create_set(in_left, in_right);
73 
74 
75  for (size_t p=0; p<length; ++p) {
76  assert( phys_ids.size() == length-p );
77 
78 
80 
81  // Reshape & SVD
82  if (p < length-1) {
83  std::vector<std::pair<index_id, bool> > svd_left, svd_right;
84 
85  for (size_t i=0; i<length-p; ++i) {
86  if (i == 0) {
87  svd_left.push_back( std::make_pair(phys_ids[i].first, true) );
88  svd_left.push_back( std::make_pair(phys_ids[i].second, false) );
89  } else {
90  svd_right.push_back( std::make_pair(phys_ids[i].first, false) );
91  svd_right.push_back( std::make_pair(phys_ids[i].second, true) );
92  }
93  }
94  svd_left.push_back( std::make_pair(alpha, false) );
95  svd_right.push_back( std::make_pair(beta, false) );
96 
97  set_id svd_s = midx.create_set(svd_left, svd_right);
98 
99  reshape(midx, curr_s, svd_s, block, btmp);
100 
103  svd(btmp, U, V, S);
104  Ssqrt = sqrt(S);
105  gemm(U, Ssqrt, btmp);
106  gemm(Ssqrt, V, block);
107  } else {
108  assert( phys_ids.size() == 1 );
109  std::vector<std::pair<index_id, bool> > vec_left, vec_right;
110  index_id id1 = phys_ids[0].first;
111  index_id id2 = phys_ids[0].second;
112  vec_left.push_back( std::make_pair(id1, true) );
113  vec_left.push_back( std::make_pair(id2, false) );
114  vec_left.push_back( std::make_pair(alpha, false) );
115  vec_right.push_back( std::make_pair(beta, false) );
116 
117  set_id new_s = midx.create_set(vec_left, vec_right);
118 
119  reshape(midx, curr_s, new_s, block, btmp);
120  }
121 
122  // Reshaping btmp in MPOTensor
123  Index<SymmGroup> const & aux_left_i = alpha_i;
124  Index<SymmGroup> const & aux_right_i = adjoin(btmp.right_basis());
125  MultiIndex<SymmGroup> midx_mpo;
126  index_id aux_left = midx_mpo.insert_index(aux_left_i);
127  index_id phys_mpo1 = midx_mpo.insert_index(phys_i);
128  index_id phys_mpo2 = midx_mpo.insert_index(phys_i);
129  index_id aux_right = midx_mpo.insert_index(aux_right_i);
130 
131  std::vector<std::pair<index_id, bool> > vec_curr_mpo_l, vec_curr_mpo_r;
132  vec_curr_mpo_l.push_back( std::make_pair(phys_mpo1, true) );
133  vec_curr_mpo_l.push_back( std::make_pair(phys_mpo2, false) );
134  vec_curr_mpo_l.push_back( std::make_pair(aux_left, false) );
135  vec_curr_mpo_r.push_back( std::make_pair(aux_right, false) );
136 
137  set_id curr_mpo_s = midx_mpo.create_set(vec_curr_mpo_l, vec_curr_mpo_r);
138  mpo[p] = MPOTensor<Matrix, SymmGroup>(aux_left_i.sum_of_sizes(), aux_right_i.sum_of_sizes());
139  for (short run=0; run<2; ++run) {
140 
141  if (run == 1)
142  for (size_t r=0; r<mpo[p].row_dim(); ++r)
143  for (size_t c=0; c<mpo[p].col_dim(); ++c)
144  if (mpo[p].has(r, c))
145  mpo[p](r, c).allocate_blocks();
146 
147  for (index_product_iterator<SymmGroup> it = midx_mpo.begin();
148  it != midx_mpo.end();
149  it++)
150  {
151  typename MultiIndex<SymmGroup>::coord_t lc, rc;
152  boost::tie(lc, rc) = midx_mpo.get_coords(curr_mpo_s, *it);
153  if (!btmp.has_block(lc.first, rc.first))
154  continue;
155 
156  size_t li = aux_left_i.position( (*it)[aux_left] );
157  size_t ri = aux_right_i.position( (*it)[aux_right] );
158 
159  if (btmp(lc, rc) != 0.) {
160  if (run == 0)
161  mpo[p](li, ri).reserve((*it)[phys_mpo1].first, (*it)[phys_mpo2].first,
162  phys_i.size_of_block((*it)[phys_mpo1].first), phys_i.size_of_block((*it)[phys_mpo2].first));
163  else
164  mpo[p](li, ri)((*it)[phys_mpo1], (*it)[phys_mpo2]) = btmp(lc, rc);
165  }
166  }
167  }
168 
169 
170  // Preparing new loop
171  if (p < length-1) {
172  midx.clear();
173  phys_ids.clear();
174  std::vector<std::pair<index_id, bool> > out_left, out_right;
175 
176  alpha_i = adjoin(block.left_basis());
177  alpha = midx.insert_index(alpha_i);
178  for (size_t i=p+1; i<length; ++i) {
179  index_id id1 = midx.insert_index(phys_i);
180  index_id id2 = midx.insert_index(phys_i);
181  phys_ids.push_back( std::make_pair(id1, id2) );
182 
183  out_right.push_back( std::make_pair(id1, false) );
184  out_right.push_back( std::make_pair(id2, true) );
185  }
186  beta = midx.insert_index(beta_i);
187  out_left.push_back( std::make_pair(alpha, false) );
188  out_right.push_back( std::make_pair(beta, false) );
189 
190  curr_s = midx.create_set(out_left, out_right);
191  }
192  }
193 
194  return mpo;
195 }
void run(std::string const &chkp1, std::string const &chkp2)
Definition: main.cpp:52
std::size_t set_id
Definition: multi_index.h:150
std::pair< charge, elem_id > coord_t
Definition: multi_index.h:148
std::size_t size_of_block(charge c) const
Definition: mpo.h:36
block_matrix< Matrix, SymmGroup > sqrt(block_matrix< Matrix, SymmGroup > m)
index_id insert_index(index_t const &idx)
Definition: multi_index.h:157
set_id create_set(std::vector< std::pair< index_id, bool > > const &vec_left, std::vector< std::pair< index_id, bool > > const &vec_right)
Definition: multi_index.h:314
block_matrix< Matrix, SymmGroup > adjoin(block_matrix< Matrix, SymmGroup > const &m)
void svd(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &U, block_matrix< Matrix, SymmGroup > &V, block_matrix< DiagMatrix, SymmGroup > &S)
std::size_t position(charge c) const
std::size_t index_id
Definition: multi_index.h:143
std::size_t insert(std::pair< charge, std::size_t > const &x)
void clear()
Definition: multi_index.h:194
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
Index< SymmGroup > const & left_basis() const
std::size_t sum_of_sizes() const