ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
measurements::local< Matrix, SymmGroup > Class Template Reference

#include <local.h>

Inheritance diagram for measurements::local< Matrix, SymmGroup >:
measurement< Matrix, SymmGroup >

Public Types

typedef Matrix::value_type value_type
 

Public Member Functions

 local (std::string const &name_, const Lattice &lat, op_vec const &identities_, op_vec const &fillings_, std::vector< bond_element > const &terms)
 
 local (std::string const &name_, const Lattice &lat, op_vec const &identities_, op_vec const &fillings_, op_vec const &op)
 
void evaluate (MPS< Matrix, SymmGroup > const &mps, boost::optional< reduced_mps< Matrix, SymmGroup > const & > rmps=boost::none)
 
template<class Archive >
void save (Archive &) const
 
void write_xml (alps::oxstream &) const
 
virtual void print (std::ostream &os) const
 
std::string const & name () const
 
int & eigenstate_index ()
 
int eigenstate_index () const
 
void set_super_meas (Index< SymmGroup > const &phys_psi_)
 
measurementclone () const
 

Protected Member Functions

measurement< Matrix, SymmGroup > * do_clone () const
 
void evaluate_with_mpo (MPS< Matrix, SymmGroup > const &mps)
 

Protected Attributes

bool cast_to_real
 
bool is_super_meas
 
std::vector< std::string > labels
 
value_type result
 
std::vector< typename MPS
< Matrix, SymmGroup >
::scalar_type > 
vector_results
 
Index< SymmGroup > phys_psi
 

Detailed Description

template<class Matrix, class SymmGroup>
class measurements::local< Matrix, SymmGroup >

Definition at line 39 of file local.h.

Member Typedef Documentation

template<class Matrix, class SymmGroup>
typedef Matrix::value_type measurement< Matrix, SymmGroup >::value_type
inherited

Definition at line 55 of file measurement.h.

Constructor & Destructor Documentation

template<class Matrix , class SymmGroup >
measurements::local< Matrix, SymmGroup >::local ( std::string const &  name_,
const Lattice lat,
op_vec const &  identities_,
op_vec const &  fillings_,
std::vector< bond_element > const &  terms 
)
inline

Definition at line 46 of file local.h.

49  : base(name_)
50  , lattice(lat)
51  , identities(identities_)
52  , fillings(fillings_)
53  , is_bond(true)
54  , mpo_terms(terms)
55  {
56  this->cast_to_real = all_true(mpo_terms.begin(), mpo_terms.end(), static_cast<bool (*)(bond_element const&)>(&is_hermitian_meas));
57  }
bool all_true(InputIterator first, InputIterator last, Predicate pred)
Definition: utils.hpp:53
bool is_hermitian_meas(std::vector< block_matrix< Matrix, SymmGroup > > const &ops)
UTILITIES.
Definition: measurement.h:175
bool cast_to_real
Definition: measurement.h:77
template<class Matrix , class SymmGroup >
measurements::local< Matrix, SymmGroup >::local ( std::string const &  name_,
const Lattice lat,
op_vec const &  identities_,
op_vec const &  fillings_,
op_vec const &  op 
)
inline

Definition at line 59 of file local.h.

62  : base(name_)
63  , lattice(lat)
64  , identities(identities_)
65  , fillings(fillings_)
66  , is_bond(false)
67  , site_term(op)
68  , mpo_terms(std::vector<bond_element>(1, bond_element(1, std::make_pair(op, false)) ))
69  {
70  this->cast_to_real = is_hermitian_meas(site_term);
71  }
bool is_hermitian_meas(std::vector< block_matrix< Matrix, SymmGroup > > const &ops)
UTILITIES.
Definition: measurement.h:175
bool cast_to_real
Definition: measurement.h:77

Member Function Documentation

template<class Matrix, class SymmGroup>
measurement* measurement< Matrix, SymmGroup >::clone ( ) const
inlineinherited

Definition at line 72 of file measurement.h.

72 { return do_clone(); }
virtual measurement * do_clone() const =0
template<class Matrix , class SymmGroup >
measurement<Matrix, SymmGroup>* measurements::local< Matrix, SymmGroup >::do_clone ( ) const
inlineprotectedvirtual

Implements measurement< Matrix, SymmGroup >.

Definition at line 106 of file local.h.

107  {
108  return new local(*this);
109  }
local(std::string const &name_, const Lattice &lat, op_vec const &identities_, op_vec const &fillings_, std::vector< bond_element > const &terms)
Definition: local.h:46
template<class Matrix, class SymmGroup>
int& measurement< Matrix, SymmGroup >::eigenstate_index ( )
inlineinherited

Definition at line 67 of file measurement.h.

67 { return eigenstate; }
template<class Matrix, class SymmGroup>
int measurement< Matrix, SymmGroup >::eigenstate_index ( ) const
inlineinherited

Definition at line 68 of file measurement.h.

68 { return eigenstate; }
template<class Matrix , class SymmGroup >
void measurements::local< Matrix, SymmGroup >::evaluate ( MPS< Matrix, SymmGroup > const &  mps,
boost::optional< reduced_mps< Matrix, SymmGroup > const & >  rmps = boost::none 
)
inlinevirtual

Implements measurement< Matrix, SymmGroup >.

Definition at line 73 of file local.h.

74  {
75  this->vector_results.clear();
76  this->labels.clear();
77 
78  typedef typename SymmGroup::subcharge subcharge;
79  if (!rmps || this->is_super_meas || is_bond)
80  return evaluate_with_mpo(mps);
81 
82  int L = mps.size();
83  this->vector_results.reserve(this->vector_results.size() + L);
84  this->labels.reserve(this->labels.size() + L);
85 
86  for (typename Lattice::pos_t p = 0; p < L; ++p) {
87  subcharge type = lattice.get_prop<subcharge>("type", p);
88  typename Matrix::value_type res = 0.;
89  bool evaluated = false;
90  if (site_term[type].n_blocks() > 0) {
92  temp.set(0, 0, site_term[type]);
93 
94  MPSTensor<Matrix, SymmGroup> vec2 = contraction::site_hamil2(mps[p], rmps.get().left(p), rmps.get().right(p), temp);
95  res += mps[p].scalar_overlap(vec2);
96  evaluated = true;
97  }
98  if (evaluated) {
99  this->vector_results.push_back(res);
100  this->labels.push_back( lattice.get_prop<std::string>("label", p) );
101  }
102  }
103  }
void set(index_type li, index_type ri, op_t const &op, value_type scale_=1.0)
Definition: mpotensor.hpp:106
void evaluate_with_mpo(MPS< Matrix, SymmGroup > const &mps)
Definition: local.h:111
std::vector< std::string > labels
Definition: measurement.h:78
bool is_super_meas
Definition: measurement.h:77
static MPSTensor< Matrix, SymmGroup > site_hamil2(MPSTensor< Matrix, SymmGroup > ket_tensor, Boundary< OtherMatrix, SymmGroup > const &left, Boundary< OtherMatrix, SymmGroup > const &right, MPOTensor< Matrix, SymmGroup > const &mpo)
Definition: contractions.h:431
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > vector_results
Definition: measurement.h:80
size_t size() const
Definition: mps.h:57
T get_prop(std::string property, pos_t site) const
Definition: lattice.h:103
impl_type::pos_t pos_t
Definition: lattice.h:88
template<class Matrix , class SymmGroup >
void measurements::local< Matrix, SymmGroup >::evaluate_with_mpo ( MPS< Matrix, SymmGroup > const &  mps)
inlineprotected

Definition at line 111 of file local.h.

112  {
113  typedef typename SymmGroup::subcharge subcharge;
114  typedef std::map<std::string, typename Matrix::value_type> result_type;
115  result_type res;
116 
118  if (this->is_super_meas)
119  nn = dm_trace(mps, this->phys_psi);
120 
121  /// collect results from all mpo terms
122  for (typename std::vector<bond_element>::const_iterator it = mpo_terms.begin(); it != mpo_terms.end(); ++it) {
123  typedef std::map<std::string, MPO<Matrix, SymmGroup> > mpo_map;
124  mpo_map mpos = meas_prepare::local(lattice, identities, fillings, *it);
125 
126  /// measure the value at each site / bond
127  for (typename mpo_map::const_iterator mit = mpos.begin(); mit != mpos.end(); ++mit) {
128  typename result_type::iterator match = res.find(mit->first);
129  if (match == res.end())
130  boost::tie(match, boost::tuples::ignore) = res.insert( std::make_pair(mit->first, 0.) );
131 
132  if (!this->is_super_meas) {
133  match->second += expval(mps, mit->second);
134  } else {
135  MPS<Matrix, SymmGroup> super_mpo = mpo_to_smps(mit->second, this->phys_psi);
136  // static_cast needed for icpc 12.x
137  typedef typename MPS<Matrix, SymmGroup>::scalar_type (*overlap_func)(MPS<Matrix, SymmGroup> const &, MPS<Matrix, SymmGroup> const &);
138  typename MPS<Matrix, SymmGroup>::scalar_type val = ::overlap(super_mpo, mps);
139  match->second += val/nn;
140  }
141  }
142  }
143 
144  /// copy results to base
145  this->vector_results.reserve(this->vector_results.size() + res.size());
146  this->labels.reserve(this->labels.size() + res.size());
147  for (typename result_type::const_iterator it = res.begin(); it != res.end(); ++it) {
148  this->labels.push_back(it->first);
149  this->vector_results.push_back(it->second);
150  }
151  }
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::map< std::string, MPO< Matrix, SymmGroup > > local(const Lattice &lat, std::vector< block_matrix< Matrix, SymmGroup > > const &identities, std::vector< block_matrix< Matrix, SymmGroup > > const &fillings, std::vector< std::pair< std::vector< block_matrix< Matrix, SymmGroup > >, bool > > const &ops)
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > vector_results
Definition: measurement.h:80
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
MPSTensor< Matrix, SymmGroup >::scalar_type scalar_type
Definition: mps.h:51
MPS< Matrix, SymmGroup > mpo_to_smps(MPO< Matrix, SymmGroup > const &mpo, Index< SymmGroup > const &phys_i)
Definition: super_mpo.h:60
Index< SymmGroup > phys_psi
Definition: measurement.h:82
MPS< Matrix, SymmGroup >::scalar_type dm_trace(MPS< Matrix, SymmGroup > const &mps, Index< SymmGroup > const &phys_psi)
Definition: mps_mpo_ops.h:258
template<class Matrix, class SymmGroup>
std::string const& measurement< Matrix, SymmGroup >::name ( ) const
inlineinherited

Definition at line 66 of file measurement.h.

66 { return name_; }
template<class Matrix , class SymmGroup >
void measurement< Matrix, SymmGroup >::print ( std::ostream &  os) const
virtualinherited

Definition at line 160 of file measurement.h.

161 {
162  os << "MEASURE[" << name_ << "]";
163 }
template<class Matrix , class SymmGroup >
template<class Archive >
void measurement< Matrix, SymmGroup >::save ( Archive &  ar) const
inherited

Definition at line 107 of file measurement.h.

108 {
109  if (vector_results.size() > 0) {
110  if (cast_to_real) {
111  save_val_at_index(ar, storage::encode(name()) + std::string("/mean/value"), maquis::real(vector_results), eigenstate_index());
112  } else {
113  save_val_at_index(ar, storage::encode(name()) + std::string("/mean/value"), vector_results, eigenstate_index());
114  }
115  if (labels.size() > 0)
116  ar[storage::encode(name()) + std::string("/labels")] << labels;
117  } else {
118  if (cast_to_real) {
119  save_val_at_index(ar, storage::encode(name()) + std::string("/mean/value"), maquis::real(result), eigenstate_index());
120  } else {
121  save_val_at_index(ar, storage::encode(name()) + std::string("/mean/value"), result, eigenstate_index());
122  }
123  }
124 }
std::vector< std::string > labels
Definition: measurement.h:78
value_type result
Definition: measurement.h:79
std::string encode(std::string const &s)
Definition: archive.h:82
void save_val_at_index(Archive &ar, std::string const &archive_path, T const &val, std::size_t eig)
Definition: measurement.h:96
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > vector_results
Definition: measurement.h:80
int & eigenstate_index()
Definition: measurement.h:67
bool cast_to_real
Definition: measurement.h:77
alps::numeric::real_type< T >::type real(T f)
Definition: bindings.hpp:38
std::string const & name() const
Definition: measurement.h:66
template<class Matrix , class SymmGroup >
void measurement< Matrix, SymmGroup >::set_super_meas ( Index< SymmGroup > const &  phys_psi_)
inherited

Definition at line 153 of file measurement.h.

154 {
155  phys_psi = phys_psi_;
156  is_super_meas = true;
157 }
bool is_super_meas
Definition: measurement.h:77
Index< SymmGroup > phys_psi
Definition: measurement.h:82
template<class Matrix , class SymmGroup >
void measurement< Matrix, SymmGroup >::write_xml ( alps::oxstream &  out) const
inherited

Definition at line 127 of file measurement.h.

128 {
129  if (labels.size() > 0) {
130  out << alps::start_tag("VECTOR_AVERAGE") << alps::attribute("name", name());
131  for (int i=0; i<labels.size(); ++i) {
132  out << alps::start_tag("SCALAR_AVERAGE");
133  out << alps::attribute("indexvalue",labels[i]) << alps::no_linebreak;
134 
135  if (cast_to_real) {
136  out << alps::start_tag("MEAN") << alps::no_linebreak << maquis::real(vector_results[i]) << alps::end_tag("MEAN");
137  } else {
138  out << alps::start_tag("MEAN") << alps::no_linebreak << vector_results[i] << alps::end_tag("MEAN");
139  }
140  out << alps::end_tag("SCALAR_AVERAGE");
141 
142  }
143  out << alps::end_tag("VECTOR_AVERAGE");
144  } else {
145  out << alps::start_tag("SCALAR_AVERAGE") << alps::attribute("name", name()) << alps::no_linebreak;
146  out << alps::start_tag("MEAN") << alps::no_linebreak << ((cast_to_real) ? maquis::real(result) : result) << alps::end_tag("MEAN");
147  out << alps::end_tag("SCALAR_AVERAGE");
148  }
149 }
std::vector< std::string > labels
Definition: measurement.h:78
value_type result
Definition: measurement.h:79
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > vector_results
Definition: measurement.h:80
bool cast_to_real
Definition: measurement.h:77
alps::numeric::real_type< T >::type real(T f)
Definition: bindings.hpp:38
std::string const & name() const
Definition: measurement.h:66

Member Data Documentation

template<class Matrix, class SymmGroup>
bool measurement< Matrix, SymmGroup >::cast_to_real
protectedinherited

Definition at line 77 of file measurement.h.

template<class Matrix, class SymmGroup>
bool measurement< Matrix, SymmGroup >::is_super_meas
protectedinherited

Definition at line 77 of file measurement.h.

template<class Matrix, class SymmGroup>
std::vector<std::string> measurement< Matrix, SymmGroup >::labels
protectedinherited

Definition at line 78 of file measurement.h.

template<class Matrix, class SymmGroup>
Index<SymmGroup> measurement< Matrix, SymmGroup >::phys_psi
protectedinherited

Definition at line 82 of file measurement.h.

template<class Matrix, class SymmGroup>
value_type measurement< Matrix, SymmGroup >::result
protectedinherited

Definition at line 79 of file measurement.h.

template<class Matrix, class SymmGroup>
std::vector<typename MPS<Matrix, SymmGroup>::scalar_type> measurement< Matrix, SymmGroup >::vector_results
protectedinherited

Definition at line 80 of file measurement.h.


The documentation for this class was generated from the following file: