ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
average.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_AVERAGE_H
29 #define MEASUREMENTS_AVERAGE_H
30 
35 
36 namespace measurements {
37 
38  template <class Matrix, class SymmGroup>
39  class average : public measurement<Matrix, SymmGroup> {
42  typedef std::vector<block_matrix<Matrix, SymmGroup> > op_vec;
43  typedef std::vector<std::pair<op_vec, bool> > bond_element;
44  public:
45 
46  /// Site term
47  average(std::string const& name_,
48  const Lattice & lattice,
49  op_vec const & identities, op_vec const & fillings,
50  op_vec const& ops)
51  : base(name_)
52  {
53  generator mpom(lattice, identities, fillings);
54 
55  for (std::size_t p = 0; p < lattice.size(); ++p)
56  {
58  term.operators.push_back( std::make_pair(p, ops[lattice.get_prop<int>("type", p)]) );
59  mpom.add_term(term);
60  }
61  mpo = mpom.create_mpo();
62 
63  this->cast_to_real = is_hermitian_meas(ops);
64  }
65 
66  /// Bond term
67  average(std::string const& name_,
68  const Lattice & lattice,
69  op_vec const & identities, op_vec const & fillings,
70  std::vector<bond_element> const& ops)
71  : base(name_)
72  {
73  generator mpom(lattice, identities, fillings);
74 
75  for (std::size_t i = 0; i < ops.size(); ++i) {
76  for (std::size_t p = 0; p < lattice.size(); ++p) {
78  term.operators.push_back( std::make_pair(p, ops[i][0].first[lattice.get_prop<int>("type", p)]) );
79  term.with_sign = ops[i][0].second;
80  std::vector<Lattice::pos_t> neighs = lattice.forward(p);
81  for (typename std::vector<Lattice::pos_t>::const_iterator hopto = neighs.begin();
82  hopto != neighs.end(); ++hopto)
83  {
85  term2.operators.push_back( std::make_pair(*hopto, ops[i][1].first[lattice.get_prop<int>("type", p)]) );
86  mpom.add_term(term2);
87  }
88  }
89  }
90  mpo = mpom.create_mpo();
91 
92  /// TODO: this doesn't really work
93  this->cast_to_real = all_true(ops.begin(), ops.end(), static_cast<bool (*)(bond_element const&)>(&is_hermitian_meas));
94  }
95 
96  void evaluate(MPS<Matrix, SymmGroup> const& mps, boost::optional<reduced_mps<Matrix, SymmGroup> const&> rmps = boost::none)
97  {
98  if (!this->is_super_meas){
99  this->result = expval(mps, mpo);
100  } else {
101  typename MPS<Matrix, SymmGroup>::scalar_type nn = dm_trace(mps, this->phys_psi);
102  MPS<Matrix, SymmGroup> super_mpo = mpo_to_smps(mpo, this->phys_psi);
103  // static_cast needed for icpc 12.x
104 #ifdef __INTEL_COMPILER
105  typedef typename MPS<Matrix, SymmGroup>::scalar_type (*overlap_func)(MPS<Matrix, SymmGroup> const &, MPS<Matrix, SymmGroup> const &);
106  this->result = static_cast<overlap_func>(&overlap)(super_mpo, mps) / nn;
107 #else
108  this->result =::overlap<Matrix,SymmGroup>(super_mpo, mps) / nn;
109 #endif
110  }
111  }
112 
113  protected:
115  {
116  return new average(*this);
117  }
118 
119  private:
121  };
122 
123 }
124 
125 #endif
include all MPO generator
double expval(MPS< Matrix, SymmGroup > const &mps, MPO< Matrix, SymmGroup > const &mpo, int d)
Definition: mps_mpo_ops.h:72
average(std::string const &name_, const Lattice &lattice, op_vec const &identities, op_vec const &fillings, std::vector< bond_element > const &ops)
Bond term.
Definition: average.h:67
value_type result
Definition: measurement.h:79
bool is_super_meas
Definition: measurement.h:77
bool all_true(InputIterator first, InputIterator last, Predicate pred)
Definition: utils.hpp:53
Definition: mpo.h:36
measurement< Matrix, SymmGroup > * do_clone() const
Definition: average.h:114
definition of Measurement base class
average(std::string const &name_, const Lattice &lattice, op_vec const &identities, op_vec const &fillings, op_vec const &ops)
Site term.
Definition: average.h:47
bool is_hermitian_meas(std::vector< block_matrix< Matrix, SymmGroup > > const &ops)
UTILITIES.
Definition: measurement.h:175
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
void evaluate(MPS< Matrix, SymmGroup > const &mps, boost::optional< reduced_mps< Matrix, SymmGroup > const & > rmps=boost::none)
Definition: average.h:96
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
std::vector< pos_t > forward(pos_t site) const
Definition: lattice.h:100
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
pos_t size() const
Definition: lattice.h:115
MPS< Matrix, SymmGroup >::scalar_type dm_trace(MPS< Matrix, SymmGroup > const &mps, Index< SymmGroup > const &phys_psi)
Definition: mps_mpo_ops.h:258