ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
measurements.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  * 2013-2013 by Michele Dolfi <dolfim@phys.ethz.ch>
7  *
8  * This software is part of the ALPS Applications, published under the ALPS
9  * Application License; you can use, redistribute it and/or modify it under
10  * the terms of the license, either version 1 or (at your option) any later
11  * version.
12  *
13  * You should have received a copy of the ALPS Application License along with
14  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
15  * available from http://alps.comp-phys.org/.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  *****************************************************************************/
26 
27 #ifndef MEASUREMENTS_H
28 #define MEASUREMENTS_H
29 
37 
38 
39 template <class Matrix, class SymmGroup>
41 public:
42  measure_and_save(std::string const& rfile_, std::string const& archive_path_,
43  MPS<Matrix, SymmGroup> const& mps_, int eigenstate_=0)
44  : rfile(rfile_)
45  , archive_path(archive_path_)
46  , eigenstate(eigenstate_)
47  , mps(mps_)
48  , rmps(mps)
49  { }
50 
52  {
53  maquis::cout << "Measuring " << meas.name() << std::endl;
54  meas.eigenstate_index() = eigenstate;
55  meas.evaluate(mps, rmps);
56  storage::archive ar(rfile, "w");
57  ar[archive_path] << meas;
58  }
59 
60 private:
61  std::string rfile, archive_path;
62  int eigenstate;
63  MPS<Matrix, SymmGroup> const& mps;
65 };
66 
67 
68 namespace detail {
70  public:
71  name_not_in_list(std::vector<std::string> const& list_)
72  : list(list_)
73  { }
74 
75  template <class Matrix, class SymmGroup>
77  {
78  return std::find(list.begin(), list.end(), term.name()) == list.end();
79  }
80 
81  private:
82  std::vector<std::string> const& list;
83  };
84 }
85 
86 template <class Matrix, class SymmGroup>
87 boost::ptr_vector<measurement<Matrix, SymmGroup> > &
88 operator<< (boost::ptr_vector<measurement<Matrix, SymmGroup> > & lhs,
89  boost::ptr_vector<measurement<Matrix, SymmGroup> > const& rhs)
90 {
91  lhs.insert(lhs.end(), rhs.begin(), rhs.end());
92  return lhs;
93 }
94 
95 template <class Matrix, class SymmGroup>
96 boost::ptr_vector<measurement<Matrix, SymmGroup> >
97 meas_sublist(boost::ptr_vector<measurement<Matrix, SymmGroup> > const& m,
98  std::vector<std::string> const& meas_list)
99 {
100  boost::ptr_vector<measurement<Matrix, SymmGroup> > sublist(m.clone());
101  sublist.erase_if( ::detail::name_not_in_list(meas_list) );
102  return sublist;
103 }
104 
105 //template <class Matrix, class SymmGroup>
106 //class DMOverlapMeasurement : public Measurement_Term<Matrix, SymmGroup> {
107 //public:
108 // typedef Measurement_Term<Matrix, SymmGroup> base;
109 //
110 // MPS<Matrix, SymmGroup> mps_ident;
111 // std::vector<MPS<Matrix, SymmGroup> > overlaps_mps;
112 // std::vector<std::string> labels;
113 //
114 //protected:
115 // virtual Measurement_Term<Matrix, SymmGroup> * do_clone() const
116 // {
117 // return new DMOverlapMeasurement<Matrix, SymmGroup>(*this);
118 // }
119 //};
120 
121 
122 template <class Matrix, class SymmGroup>
123 boost::ptr_vector<measurement<Matrix, SymmGroup> >
124 overlap_measurements(BaseParameters const & parms, boost::optional<size_t> sweep = boost::none)
125 {
126  /* Syntax for MEASURE_OVERLAP:
127  * (1) MEASURE_OVERLAP[obsname] = "/path/to/ckp.h5"
128  * (2) MEASURE_OVERLAP[obsname(sweep)] = "/path/to/ckp.h5"
129  *
130  * `obsname` is the name that will be given in archive output.
131  * if `sweep` is prensent, the overlap will only be computed when the sweep number
132  * matches the given one.
133  */
134  boost::ptr_vector<measurement<Matrix, SymmGroup> > meas;
135  boost::regex expression("^MEASURE_OVERLAP\\[([a-zA-Z]+)(\\(([0-9]+)\\))?\\]$");
136  boost::smatch what;
137  for (BaseParameters::const_iterator it=parms.begin();it != parms.end();++it) {
138  std::string lhs = it->key();
139  if (boost::regex_match(lhs, what, expression)) {
140  if (sweep && !what[3].matched) continue;
141  if (sweep && what[3].matched && boost::lexical_cast<long>(what.str(3)) != sweep.get()) continue;
142 
143  std::string name = what.str(1), bra_chkp = it->value();
144  meas.push_back( new measurements::overlap<Matrix, SymmGroup>(name, bra_chkp) );
145  }
146  }
147  return meas;
148 }
149 
150 #endif
virtual void evaluate(MPS< Matrix, SymmGroup > const &, boost::optional< reduced_mps< Matrix, SymmGroup > const & >=boost::none)=0
name_not_in_list(std::vector< std::string > const &list_)
Definition: measurements.h:71
measure_and_save(std::string const &rfile_, std::string const &archive_path_, MPS< Matrix, SymmGroup > const &mps_, int eigenstate_=0)
Definition: measurements.h:42
boost::ptr_vector< measurement< Matrix, SymmGroup > > overlap_measurements(BaseParameters const &parms, boost::optional< size_t > sweep=boost::none)
Definition: measurements.h:124
Definition: mps.h:40
int & eigenstate_index()
Definition: measurement.h:67
boost::ptr_vector< measurement< Matrix, SymmGroup > > meas_sublist(boost::ptr_vector< measurement< Matrix, SymmGroup > > const &m, std::vector< std::string > const &meas_list)
Definition: measurements.h:97
bool operator()(measurement< Matrix, SymmGroup > const &term) const
Definition: measurements.h:76
void operator()(measurement< Matrix, SymmGroup > &meas) const
Definition: measurements.h:51
std::string const & name() const
Definition: measurement.h:66