28 #ifndef MEASUREMENTS_CORRELATIONS_H
29 #define MEASUREMENTS_CORRELATIONS_H
36 #include <boost/iterator/counting_iterator.hpp>
38 namespace measurements {
41 inline std::vector<std::vector<std::size_t> >
43 std::vector<size_t>
const & order,
46 std::vector<std::vector<std::size_t> > ret(labels.size());
47 for (
int i=0; i<labels.size(); ++i) {
49 if (is_nn) assert(2*order.size() == labels[i].size());
50 else assert(order.size() == labels[i].size());
52 ret[i].resize(labels[i].size());
54 for (
int j=0; j<order.size(); ++j) {
56 ret[i][order[j]] = labels[i][2*j];
57 ret[i][order[j]+1] = labels[i][2*j+1];
59 ret[i][order[j]] = labels[i][j];
67 template <
class Matrix,
class SymmGroup>
72 typedef std::pair<std::vector<block_matrix<Matrix, SymmGroup> >,
bool>
inner_t;
76 std::vector<size_t> ord;
78 for (
size_t i=0; i<ops.size(); i+=2) ord.push_back(i);
80 for (
size_t i=0; i<ops.size(); ++i) ord.push_back(i);
83 std::vector<size_t> check_pre;
84 for (
size_t i=0; i<ops.size(); ++i) {
87 check_pre.push_back(ord[i]);
90 check_pre.push_back(ord[i]);
92 check_pre.push_back(ord[i]+1);
98 std::sort(check_pre.begin(), check_pre.end(), cmp);
101 for (
size_t i=0; i<ord.size(); ++i) {
102 tmp.push_back( ops[ord[i]] );
104 tmp.push_back( ops[ord[i]+1] );
108 for (
int type=0; type<tmp[0].first.size(); ++type)
112 orders.push_back(ord);
113 }
while (std::next_permutation(ord.begin(), ord.end()));
116 size_t size()
const {
return perm.size();}
118 std::vector<size_t>
order(
size_t i)
const {
return orders[i];}
121 std::vector<value_t> perm;
122 std::vector<std::vector<size_t> > orders;
128 template <
class Matrix,
class SymmGroup>
131 typedef std::size_t size_type;
132 typedef std::vector<block_matrix<Matrix, SymmGroup> > op_vec;
133 typedef std::vector<size_type> positions_type;
137 op_vec
const & identities_, op_vec
const & fillings_,
138 std::vector<std::pair<op_vec, bool> >
const& ops_,
139 bool half_only_,
bool nearest_neighbors_only,
140 positions_type
const& positions_ = positions_type())
143 , positions_first(positions_)
144 , identities(identities_)
145 , fillings(fillings_)
147 , half_only(half_only_)
148 , is_nn(nearest_neighbors_only)
150 if (positions_first.size() == 0)
151 std::copy(boost::counting_iterator<int>(0), boost::counting_iterator<int>(lattice.
size()-(ops.size()-1)),
152 back_inserter(positions_first));
166 for (
int i=0; i<perm.
size(); ++i) {
179 std::vector<std::pair<op_vec, bool> >
const & ops,
180 std::vector<size_type>
const & order = std::vector<size_type>())
182 typedef boost::shared_ptr<generate_mpo::CorrMakerBase<Matrix, SymmGroup> > maker_ptr;
184 for (std::vector<std::size_t>::const_iterator it = positions_first.begin(); it != positions_first.end(); ++it) {
185 if (*it >= lattice.
size()-(ops.size()-1))
186 throw std::runtime_error(
"cannot measure correlation with first operator at p="+boost::lexical_cast<std::string>(*it)+
".");
188 maquis::cout <<
" site " << *it << std::endl;
198 std::vector<typename MPS<Matrix, SymmGroup>::scalar_type> dct;
205 for (
int i=0; i<dct.size(); ++i)
213 std::copy(dct.begin(), dct.end(), std::back_inserter(this->
vector_results));
215 std::vector<std::vector<std::size_t> > num_labels = dcorr->numeric_labels();
217 std::copy(lbt.begin(), lbt.end(), std::back_inserter(this->
labels));
223 positions_type positions_first;
224 op_vec identities, fillings;
225 std::vector<std::pair<op_vec, bool> > ops;
226 bool half_only, is_nn;
std::vector< std::string > labels
std::vector< size_t > order(size_t i) const
value_t operator[](size_t i) const
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > multi_overlap(MPS< Matrix, SymmGroup > const &mps1, MPS< Matrix, SymmGroup > const &mps2)
CorrPermutator(value_t const &ops, bool is_nn)
correlations(std::string const &name_, const Lattice &lat, op_vec const &identities_, op_vec const &fillings_, std::vector< std::pair< op_vec, bool > > const &ops_, bool half_only_, bool nearest_neighbors_only, positions_type const &positions_=positions_type())
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > multi_expval(MPS< Matrix, SymmGroup > const &mps, MPO< Matrix, SymmGroup > const &mpo)
std::vector< std::string > label_strings(const Lattice &lat, const std::vector< std::vector< std::size_t > > &labels)
std::vector< typename MPS< Matrix, SymmGroup >::scalar_type > vector_results
std::vector< inner_t > value_t
void evaluate(MPS< Matrix, SymmGroup > const &mps, boost::optional< reduced_mps< Matrix, SymmGroup > const & > rmps=boost::none)
definition of Measurement base class
bool is_hermitian_meas(std::vector< block_matrix< Matrix, SymmGroup > > const &ops)
UTILITIES.
void measure_correlation(MPS< Matrix, SymmGroup > const &mps, std::vector< std::pair< op_vec, bool > > const &ops, std::vector< size_type > const &order=std::vector< size_type >())
MPSTensor< Matrix, SymmGroup >::scalar_type scalar_type
MPS< Matrix, SymmGroup > mpo_to_smps(MPO< Matrix, SymmGroup > const &mpo, Index< SymmGroup > const &phys_i)
functions to operate on MPS and MPO (compute expectation values, etc.)
std::pair< std::vector< block_matrix< Matrix, SymmGroup > >, bool > inner_t
std::vector< std::vector< std::size_t > > resort_labels(const std::vector< std::vector< std::size_t > > &labels, std::vector< size_t > const &order, bool is_nn=false)
measurement< Matrix, SymmGroup > * do_clone() const
Index< SymmGroup > phys_psi
MPS< Matrix, SymmGroup >::scalar_type dm_trace(MPS< Matrix, SymmGroup > const &mps, Index< SymmGroup > const &phys_psi)