ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions
te_utils.hpp File Reference
#include "dmrg/models/model.h"
#include "dmrg/models/lattice.h"
#include "utils/traits.hpp"
#include "dmrg/block_matrix/block_matrix.h"
#include "dmrg/block_matrix/multi_index.h"
#include "dmrg/mp_tensors/reshapes.h"
#include "dmrg/mp_tensors/mpo_manip.h"
#include "dmrg/mp_tensors/compression.h"
#include "dmrg/models/generate_mpo/utils.hpp"
#include <vector>
#include <set>
#include <algorithm>

Go to the source code of this file.

Classes

class  exp_mpo_maker< Matrix, SymmGroup >
 

Functions

template<typename T >
std::vector< std::vector
< term_descriptor< T > > > 
separate_hamil_terms (std::vector< term_descriptor< T > > const &hamil_terms)
 
template<class Matrix , class SymmGroup >
block_matrix< Matrix, SymmGroup > term2block (typename Matrix::value_type const &scale, block_matrix< Matrix, SymmGroup > const &op1, Index< SymmGroup > const &phys1_i, block_matrix< Matrix, SymmGroup > const &op2, Index< SymmGroup > const &phys2_i)
 
template<class Matrix , class SymmGroup >
std::vector< block_matrix
< Matrix, SymmGroup > > 
hamil_to_blocks (Lattice const &lat, Model< Matrix, SymmGroup > const &model)
 
template<class Matrix , class SymmGroup >
MPO< Matrix, SymmGroup > make_exp_mpo (Lattice const &lat, Model< Matrix, SymmGroup > const &model, std::vector< term_descriptor< typename Matrix::value_type > > const &hamil_terms, typename Matrix::value_type const &alpha=1)
 

Function Documentation

template<class Matrix , class SymmGroup >
std::vector<block_matrix<Matrix, SymmGroup> > hamil_to_blocks ( Lattice const &  lat,
Model< Matrix, SymmGroup > const &  model 
)

Definition at line 130 of file te_utils.hpp.

131 {
132  std::size_t L = lat.size();
133  std::vector<block_matrix<Matrix, SymmGroup> > ret_blocks(L-1);
134 
135  typename Model<Matrix, SymmGroup>::table_ptr tag_handler = model.operators_table();
136 
138  std::vector<term_t> const& hamil_terms = model.hamiltonian_terms();
139  for (int i=0; i<hamil_terms.size(); ++i)
140  {
141  term_t term = hamil_terms[i];
142  term.canonical_order(); // TODO: check and fix for fermions!!
143  std::size_t pos1 = term.position(0);
144  int type = lat.get_prop<int>("type", pos1);
145  int type_p1, type_m1;
146  if (pos1 < L-1) type_p1 = lat.get_prop<int>("type", pos1+1);
147  if (pos1 > 0) type_m1 = lat.get_prop<int>("type", pos1-1);
148  if (term.size() == 1) {
149  if (pos1 != 0 && pos1 != L-1)
150  term.coeff /= 2.;
151  if (pos1 < L-1)
152  ret_blocks[pos1] += term2block(term.coeff,
153  tag_handler->get_op(term.operator_tag(0)), model.phys_dim(type),
154  model.identity_matrix(type_p1), model.phys_dim(type_p1));
155  if (pos1 > 0)
156  ret_blocks[pos1-1] += term2block(term.coeff,
157  model.identity_matrix(type_m1), model.phys_dim(type_m1),
158  tag_handler->get_op(term.operator_tag(0)), model.phys_dim(type));
159  } else if (term.size() == 2) {
160  assert( std::abs(term.position(0)-term.position(1)) == 1 );
161  ret_blocks[pos1] += term2block(term.coeff,
162  tag_handler->get_op(term.operator_tag(0)), model.phys_dim(type),
163  tag_handler->get_op(term.operator_tag(1)), model.phys_dim(type_p1));
164  }
165  }
166 
167  return ret_blocks;
168 }
terms_type const & hamiltonian_terms() const
Definition: model.h:131
impl_type::table_ptr table_ptr
Definition: model.h:103
op_t const & identity_matrix(size_t type=0) const
Definition: model.h:124
block_matrix< Matrix, SymmGroup > term2block(typename Matrix::value_type const &scale, block_matrix< Matrix, SymmGroup > const &op1, Index< SymmGroup > const &phys1_i, block_matrix< Matrix, SymmGroup > const &op2, Index< SymmGroup > const &phys2_i)
Definition: te_utils.hpp:119
table_ptr operators_table() const
Definition: model.h:137
Index< SymmGroup > const & phys_dim(size_t type=0) const
Definition: model.h:123
template<class Matrix , class SymmGroup >
MPO<Matrix, SymmGroup> make_exp_mpo ( Lattice const &  lat,
Model< Matrix, SymmGroup > const &  model,
std::vector< term_descriptor< typename Matrix::value_type > > const &  hamil_terms,
typename Matrix::value_type const &  alpha = 1 
)

Definition at line 331 of file te_utils.hpp.

334 {
336  typedef OPTable<Matrix, SymmGroup> op_table_t;
337  typedef boost::shared_ptr<op_table_t> op_table_ptr;
338  typedef typename op_table_t::tag_type tag_type;
339  typedef boost::tuple<std::size_t, std::size_t, tag_type, typename Matrix::value_type> pretensor_value;
340  typedef std::vector<pretensor_value> pretensor_t;
341 
342  op_table_ptr original_op_table = model.operators_table()->get_operator_table();
343  op_table_ptr new_op_table( new op_table_t() );
344 
345  size_t length = lat.size();
346 
347  std::vector<tag_type> ident(lat.maximum_vertex_type()+1), fill(lat.maximum_vertex_type()+1);
348  for (int type=0; type<ident.size(); ++type) {
349  ident[type] = new_op_table->register_op( model.identity_matrix(type) );
350  fill[type] = new_op_table->register_op( model.filling_matrix(type) );
351  }
352 
353  MPO<Matrix, SymmGroup> mpo(length);
354  std::vector<bool> used_p(length, false);
355 
356  for (int n=0; n<hamil_terms.size(); )
357  {
358  if (hamil_terms[n].size() != 2) throw std::runtime_error("hamiltonian terms have to be sorted with two-site bond terms before site terms.");
359  int pos1 = hamil_terms[n].position(0);
360  int pos2 = hamil_terms[n].position(1);
361 
362  int type1 = lat.get_prop<int>("type", pos1);
363  int type2 = lat.get_prop<int>("type", pos2);
364 
365  exp_mpo_maker<Matrix, SymmGroup> maker(model.phys_dim(type1), model.phys_dim(type2), pos1, pos2, lat);
366 
367  maker.add_term(hamil_terms[n], model);
368 
369  int k = n+1;
370  for (; k<hamil_terms.size() && hamil_terms[n].site_match(hamil_terms[k]); ++k)
371  maker.add_term(hamil_terms[k], model);
372 
373  MPO<Matrix, SymmGroup> block_mpo = maker.exp_mpo(alpha, ident, fill, new_op_table);
374  for (size_t p=0; p<pos2-pos1+1; ++p) {
375  using std::swap;
376  swap(mpo[pos1+p], block_mpo[p]);
377  used_p[pos1+p] = true;
378  }
379 
380  n = k;
381  }
382 
383 
384  // Filling missing identities
385  for (std::size_t p=0; p<length; ++p) {
386  if (!used_p[p]) {
387  pretensor_t preident(1, pretensor_value(0, 0, ident[lat.get_prop<int>("type", p)], 1.) );
388  MPOTensor<Matrix, SymmGroup> r(1, 1, preident, new_op_table);
389  using std::swap;
390  swap(mpo[p], r);
391  used_p[p] = true;
392  }
393  }
394 
395  return mpo;
396 }
op_t const & filling_matrix(size_t type=0) const
Definition: model.h:126
void add_term(term_t const &term, Model< Matrix, SymmGroup > const &model)
Definition: te_utils.hpp:194
op_t const & identity_matrix(size_t type=0) const
Definition: model.h:124
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
Definition: mpo.h:36
table_ptr operators_table() const
Definition: model.h:137
Index< SymmGroup > const & phys_dim(size_t type=0) const
Definition: model.h:123
unsigned tag_type
Definition: tag_detail.h:36
template<typename T >
std::vector<std::vector<term_descriptor<T> > > separate_hamil_terms ( std::vector< term_descriptor< T > > const &  hamil_terms)

Definition at line 49 of file te_utils.hpp.

50 {
51  typedef std::map<std::size_t, std::set<std::size_t> > pos_where_t;
52  typedef term_descriptor<T> term_t;
53  typedef std::map<std::size_t, std::vector<term_t> > pos_terms_t;
54 
55  std::vector<std::vector<term_t> > ret;
56  pos_where_t pos_where;
57  pos_terms_t pos_terms;
58 
59  for (int i=0; i<hamil_terms.size(); ++i)
60  {
61  if (hamil_terms[i].size() == 1) {
62  pos_terms[hamil_terms[i].position(0)].push_back(hamil_terms[i]);
63  continue;
64  }
65 
66  term_t term = hamil_terms[i];
67  term.canonical_order(); // TODO: check and fix for fermions!!
68  bool used = false;
69  for (int n=0; n<ret.size() && !used; ++n)
70  {
71  bool overlap = false;
72  for (int j=0; j<ret[n].size() && !overlap; ++j)
73  {
74  if ( ret[n][j].site_match(term) ) break;
75  overlap = ret[n][j].overlap(term);
76  }
77 
78  if (!overlap) {
79  ret[n].push_back(term);
80  for (int k=0; k<term.size(); ++k)
81  pos_where[term.position(k)].insert(n);
82  used = true;
83  }
84  }
85 
86  if (!used) {
87  ret.push_back( std::vector<term_t>(1, term) );
88 
89  for (int k=0; k<term.size(); ++k)
90  pos_where[term.position(k)].insert(ret.size()-1);
91  }
92  }
93 
94  // Adding site terms to all Hamiltonians acting on site i
95  for (typename pos_terms_t::const_iterator it = pos_terms.begin();
96  it != pos_terms.end(); ++it)
97  {
98  double coeff = 1. / pos_where[it->first].size();
99 
100  for (typename std::set<std::size_t>::const_iterator it2 = pos_where[it->first].begin();
101  it2 != pos_where[it->first].end(); ++it2)
102  for (int k=0; k<it->second.size(); ++k)
103  {
104  term_t tmp_term = it->second[k];
105  tmp_term.coeff *= coeff;
106  ret[*it2].push_back(tmp_term);
107  }
108  }
109 
110  // Sorting individual Hamiltonians
111  for (int n=0; n<ret.size(); ++n)
112  std::sort(ret[n].begin(), ret[n].end());
113 
114  return ret;
115 }
MPS< Matrix, SymmGroup >::scalar_type overlap(MPS< Matrix, SymmGroup > const &mps1, MPS< Matrix, SymmGroup > const &mps2)
Definition: mps_mpo_ops.h:136
template<class Matrix , class SymmGroup >
block_matrix<Matrix, SymmGroup> term2block ( typename Matrix::value_type const &  scale,
block_matrix< Matrix, SymmGroup > const &  op1,
Index< SymmGroup > const &  phys1_i,
block_matrix< Matrix, SymmGroup > const &  op2,
Index< SymmGroup > const &  phys2_i 
)

Definition at line 119 of file te_utils.hpp.

122 {
124  op_kron(phys1_i, phys2_i, op1, op2, bond_op);
125  bond_op *= scale;
126  return bond_op;
127 }
void op_kron(Index< SymmGroup > const &phys_A, Index< SymmGroup > const &phys_B, block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix1, SymmGroup > const &B, block_matrix< Matrix2, SymmGroup > &C)