ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
local_at.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  * 2011-2013 Michele Dolfi <dolfim@phys.ethz.ch>
8  *
9  * This software is part of the ALPS Applications, published under the ALPS
10  * Application License; you can use, redistribute it and/or modify it under
11  * the terms of the license, either version 1 or (at your option) any later
12  * version.
13  *
14  * You should have received a copy of the ALPS Application License along with
15  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
16  * available from http://alps.comp-phys.org/.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  *****************************************************************************/
27 
28 #ifndef MEASUREMENTS_LOCAL_AT_H
29 #define MEASUREMENTS_LOCAL_AT_H
30 
33 
34 namespace measurements {
35 
36  template <class Matrix, class SymmGroup>
37  class local_at : public measurement<Matrix, SymmGroup> {
39  typedef std::size_t size_type;
40  typedef std::vector<block_matrix<Matrix, SymmGroup> > op_vec;
41  typedef std::vector<std::vector<size_type> > positions_type;
42 
43  public:
44  local_at(std::string const& name_, const Lattice & lat,
45  positions_type const& positions_,
46  op_vec const & identities_, op_vec const & fillings_,
47  std::vector<std::pair<op_vec, bool> > const& ops_)
48  : base(name_)
49  , lattice(lat)
50  , positions(positions_)
51  , identities(identities_)
52  , fillings(fillings_)
53  , ops(ops_)
54  {
55  this->labels = label_strings(lattice, positions);
56  this->cast_to_real = false;
57  }
58 
59  void evaluate(MPS<Matrix, SymmGroup> const& mps, boost::optional<reduced_mps<Matrix, SymmGroup> const&> rmps = boost::none)
60  {
61  this->vector_results.clear();
62  this->vector_results.reserve(positions.size());
63  for (std::size_t p = 0; p < positions.size(); ++p)
64  {
65  assert( positions[p].size() == ops.size() );
66  for (std::size_t i=1; i<ops.size(); ++i)
67  if (positions[p][i-1] >= positions[p][i])
68  throw std::runtime_error("measure_local_at requires i1<i2<...<in.");
69 
70  generate_mpo::MPOMaker<Matrix, SymmGroup> mpom(lattice, identities, fillings);
72 
73  bool with_sign = false;
74  for (std::size_t i=0; i<ops.size(); ++i) {
75  std::size_t pos = positions[p][i];
76 
77  block_matrix<Matrix, SymmGroup> const& fill = fillings[lattice.get_prop<int>("type", pos)];
78  block_matrix<Matrix, SymmGroup> const& op = ops[i].first[lattice.get_prop<int>("type", pos)];
79 
81  op_t tmp;
82  if (!with_sign && ops[i].second) gemm(fill, op, tmp);
83  else tmp = op;
84  hterm.operators.push_back( std::make_pair(pos, tmp) );
85 
86  pos++;
87  with_sign = (ops[i].second) ? !with_sign : with_sign;
88  if (i != ops.size()-1)
89  for (; pos<positions[p][i+1]; ++pos) {
90  block_matrix<Matrix, SymmGroup> const& fill = fillings[lattice.get_prop<int>("type", pos)];
91  block_matrix<Matrix, SymmGroup> const& ident = identities[lattice.get_prop<int>("type", pos)];
92  hterm.operators.push_back( std::make_pair(pos, (with_sign) ? fill : ident) );
93  }
94  }
95  hterm.with_sign = false; // filling already taken care above
96  mpom.add_term(hterm);
98 
99  if (!this->is_super_meas){
100  typename MPS<Matrix, SymmGroup>::scalar_type val = expval(mps, mpo);
101  this->vector_results.push_back(val);
102  } else {
103  typename MPS<Matrix, SymmGroup>::scalar_type nn = dm_trace(mps, this->phys_psi);
104  MPS<Matrix, SymmGroup> super_mpo = mpo_to_smps(mpo, this->phys_psi);
105  // static_cast needed for icpc 12.x
106  typedef typename MPS<Matrix, SymmGroup>::scalar_type (*overlap_func)(MPS<Matrix, SymmGroup> const &, MPS<Matrix, SymmGroup> const &);
107  typename MPS<Matrix, SymmGroup>::scalar_type val = ::overlap(super_mpo, mps);
108  this->vector_results.push_back(val/nn);
109  }
110  }
111  }
112 
113  protected:
115  {
116  return new local_at(*this);
117  }
118 
119  private:
120  Lattice lattice;
121  positions_type positions;
122  op_vec identities, fillings;
123  std::vector<std::pair<op_vec, bool> > ops;
124  };
125 
126 }
127 
128 #endif
std::vector< std::string > labels
Definition: measurement.h:78
double expval(MPS< Matrix, SymmGroup > const &mps, MPO< Matrix, SymmGroup > const &mpo, int d)
Definition: mps_mpo_ops.h:72
bool is_super_meas
Definition: measurement.h:77
std::vector< std::string > label_strings(const Lattice &lat, const std::vector< std::vector< std::size_t > > &labels)
Definition: measurement.h:190
void evaluate(MPS< Matrix, SymmGroup > const &mps, boost::optional< reduced_mps< Matrix, SymmGroup > const & > rmps=boost::none)
Definition: local_at.h:59
local_at(std::string const &name_, const Lattice &lat, positions_type const &positions_, op_vec const &identities_, op_vec const &fillings_, std::vector< std::pair< op_vec, bool > > const &ops_)
Definition: local_at.h:44
measurement< Matrix, SymmGroup > * do_clone() const
Definition: local_at.h:114
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > vector_results
Definition: measurement.h:80
Definition: mpo.h:36
definition of Measurement base class
MPS< Matrix, SymmGroup >::scalar_type overlap(MPS< Matrix, SymmGroup > const &mps1, MPS< Matrix, SymmGroup > const &mps2)
Definition: mps_mpo_ops.h:136
Definition: mps.h:40
T get_prop(std::string property, pos_t site) const
Definition: lattice.h:103
MPSTensor< Matrix, SymmGroup >::scalar_type scalar_type
Definition: mps.h:51
std::vector< op_pair_t > operators
Definition: utils.hpp:118
MPS< Matrix, SymmGroup > mpo_to_smps(MPO< Matrix, SymmGroup > const &mpo, Index< SymmGroup > const &phys_i)
Definition: super_mpo.h:60
functions to operate on MPS and MPO (compute expectation values, etc.)
void add_term(Operator_Term< Matrix, SymmGroup > const &term)
Definition: mpo_maker.hpp:78
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
MPO< Matrix, SymmGroup > create_mpo()
Definition: mpo_maker.hpp:121
Index< SymmGroup > phys_psi
Definition: measurement.h:82
bool cast_to_real
Definition: measurement.h:77
pimpl resolved Lattice
Definition: lattice.h:84
MPS< Matrix, SymmGroup >::scalar_type dm_trace(MPS< Matrix, SymmGroup > const &mps, Index< SymmGroup > const &phys_psi)
Definition: mps_mpo_ops.h:258