27 #ifndef GENERATE_MPO_CORR_MAKER_H
28 #define GENERATE_MPO_CORR_MAKER_H
44 namespace generate_mpo
46 template<
class Matrix,
class SymmGroup>
55 template<
class Matrix,
class SymmGroup>
60 typedef boost::tuple<size_t, size_t, tag_type, typename Matrix::value_type> block;
61 typedef boost::tuple<size_t, size_t, string> tag;
65 const std::vector<op_t> & ident_,
66 const std::vector<op_t> & fill_,
67 std::vector<std::pair<std::vector<op_t>,
bool> >
const & ops,
73 , with_sign(lat.size()+2)
74 , identities(ident_.size())
75 , fillings(fill_.size())
79 for (
int type=0; type<ident_.size(); ++type)
81 for (
int type=0; type<fill_.size(); ++type)
84 for (
size_t n=0; n<ops.size(); ++n) {
85 op_tags[n].first.resize(ops[n].first.size());
86 op_tags[n].second = ops[n].second;
87 std::vector<tag_type> & tops = op_tags[n].first;
88 for (
int type=0; type<tops.size(); ++type)
92 with_sign[0][0] =
false;
93 recurse(0, 0, 0, std::vector<size_t>(), ref);
99 for (
size_t p = 1; p < prempo.size()-1; ++p)
100 r[p] = as_bulk(prempo[p]);
101 r[0] = as_left(prempo[0]);
102 r[prempo.size()-1] = as_right(*prempo.rbegin());
109 std::ostringstream ss;
110 for (
size_t p = 0; p < prempo.size(); ++p)
112 ss <<
"Site: " << p << std::endl;
113 for (
typename vector<tag>::const_iterator it = tags[p].begin(); it != tags[p].end(); ++it)
114 ss <<
" " << get<0>(*it) <<
" " << get<1>(*it) <<
" " << get<2>(*it) << std::endl;
125 vector<vector<block> > prempo;
126 vector<vector<tag> > tags;
127 vector<vector<size_t> > labels;
129 vector<set<size_t> > used;
130 vector<map<size_t, bool> > with_sign;
131 std::vector<tag_type> identities, fillings;
133 vector<std::pair<std::vector<tag_type>,
bool> > op_tags;
135 size_t term(
size_t p,
size_t u1, std::pair<std::vector<tag_type>,
bool>
const & op_p,
bool trivial)
139 typename Matrix::value_type scale;
141 op = (with_sign[p][u1]) ? fillings[lat.
get_prop<
int>(
"type", p)] : identities[lat.
get_prop<
int>(
"type", p)];
143 lab = (with_sign[p][u1]) ?
"filling" :
"ident";
146 if (!with_sign[p][u1] && op_p.second) {
148 boost::tie(op, scale) = tag_handler.get_product_tag(fillings[lat.
get_prop<
int>(
"type", p)], op_p.first[lat.
get_prop<
int>(
"type", p)]);
150 }
else if (with_sign[p][u1] && !op_p.second) {
152 boost::tie(op, scale) = tag_handler.get_product_tag(fillings[lat.
get_prop<
int>(
"type", p)], op_p.first[lat.
get_prop<
int>(
"type", p)]);
155 op = op_p.first[lat.
get_prop<
int>(
"type", p)];
161 while (used[p].count(u2) > 0) ++u2;
162 prempo[p].push_back( boost::make_tuple(u1, u2, op, scale) );
164 with_sign[p+1][u2] = (op_p.second) ? !with_sign[p][u1] : with_sign[p][u1];
168 tags[p].push_back( boost::make_tuple(u1, u2, lab) );
170 tags[p].push_back( boost::make_tuple(u1, u2, lab) );
174 void recurse(
size_t p0,
size_t which,
size_t use, vector<size_t> label,
int ref)
176 if (p0 + op_tags.size() - which < prempo.size()) {
177 size_t use_next = term(p0, use, std::make_pair(identities,
false),
true);
178 recurse(p0+1, which, use_next, label, ref);
182 if (ref >= 0 && which == 0 && p0 != ref)
185 if (tag_handler.get_op(op_tags[which].first[lat.
get_prop<
int>(
"type", p0)]).n_blocks() == 0)
188 size_t use_next = term(p0, use, op_tags[which],
false);
190 vector<size_t> label_(label);
191 label_.push_back(p0);
193 if (which == op_tags.size()-1) {
194 size_t t1 = use_next, t2 = use_next;
195 for (
size_t p2 = p0+1; p2 < prempo.size(); ++p2) {
196 t2 = term(p2, t1, std::make_pair(identities,
false),
true);
199 labels.resize(std::max(t2+1, labels.size()));
202 recurse(p0+1, which+1, use_next, label_, ref);
209 pair<size_t, size_t> rcd =
rcdim(ops);
216 pair<size_t, size_t> rcd =
rcdim(ops);
223 pair<size_t, size_t> rcd =
rcdim(ops);
231 template<
class Matrix,
class SymmGroup>
236 typedef boost::tuple<size_t, size_t, tag_type, typename Matrix::value_type> block;
237 typedef boost::tuple<size_t, size_t, string> tag;
241 const std::vector<op_t> & ident_,
242 const std::vector<op_t> & fill_,
243 std::vector<std::pair<std::vector<op_t>,
bool> >
const & ops,
249 , with_sign(lat.size()+2)
250 , identities(ident_.size())
251 , fillings(fill_.size())
252 , op_tags(ops.size())
254 assert(ops.size() % 2 == 0);
257 for (
int type=0; type<ident_.size(); ++type)
259 for (
int type=0; type<fill_.size(); ++type)
262 for (
size_t n=0; n<ops.size(); ++n) {
263 op_tags[n].first.resize(ops[n].first.size());
264 op_tags[n].second = ops[n].second;
265 std::vector<tag_type> & tops = op_tags[n].first;
266 for (
int type=0; type<tops.size(); ++type)
270 with_sign[0][0] =
false;
271 recurse(0, 0, 0, vector<size_t>(), ref);
277 for (
size_t p = 1; p < prempo.size()-1; ++p)
278 r[p] = as_bulk(prempo[p]);
279 r[0] = as_left(prempo[0]);
280 r[prempo.size()-1] = as_right(*prempo.rbegin());
289 std::ostringstream ss;
290 for (
size_t p = 0; p < prempo.size(); ++p)
292 ss <<
"Site: " << p << std::endl;
293 for (
typename vector<tag>::const_iterator it = tags[p].begin(); it != tags[p].end(); ++it)
294 ss <<
" " << get<0>(*it) <<
" " << get<1>(*it) <<
" " << get<2>(*it) << std::endl;
303 vector<vector<block> > prempo;
304 vector<vector<tag> > tags;
305 vector<vector<size_t> > labels;
307 vector<set<size_t> > used;
308 vector<map<size_t, bool> > with_sign;
310 std::vector<tag_type> identities, fillings;
312 vector<std::pair<std::vector<tag_type>,
bool> > op_tags;
314 size_t term(
size_t p,
size_t u1, std::pair<std::vector<tag_type>,
bool>
const & op_p,
bool trivial)
318 typename Matrix::value_type scale;
320 op = (with_sign[p][u1]) ? fillings[lat.
get_prop<
int>(
"type", p)] : identities[lat.
get_prop<
int>(
"type", p)];
321 lab = (with_sign[p][u1]) ?
"filling" :
"ident";
324 if (!with_sign[p][u1] && op_p.second) {
326 boost::tie(op, scale) = tag_handler.get_product_tag(fillings[lat.
get_prop<
int>(
"type", p)], op_p.first[lat.
get_prop<
int>(
"type", p)]);
328 }
else if (with_sign[p][u1] && !op_p.second) {
330 boost::tie(op, scale) = tag_handler.get_product_tag(fillings[lat.
get_prop<
int>(
"type", p)], op_p.first[lat.
get_prop<
int>(
"type", p)]);
333 op = op_p.first[lat.
get_prop<
int>(
"type", p)];
338 while (used[p].count(u2) > 0) ++u2;
339 prempo[p].push_back( boost::make_tuple(u1, u2, op, 1.0) );
341 with_sign[p+1][u2] = (op_p.second) ? !with_sign[p][u1] : with_sign[p][u1];
345 tags[p].push_back( boost::make_tuple(u1, u2, lab) );
347 tags[p].push_back( boost::make_tuple(u1, u2, lab) );
351 void recurse(
size_t p0,
size_t which,
size_t use, vector<size_t> label,
int ref)
353 if (p0 + op_tags.size() - which < prempo.size()) {
354 size_t use_next = term(p0, use, std::make_pair(identities,
false),
true);
355 recurse(p0+1, which, use_next, label, ref);
359 if (ref >= 0 && which == 0 && p0 != ref)
362 if (tag_handler.get_op(op_tags[which].first[lat.
get_prop<
int>(
"type", p0)]).n_blocks() == 0)
364 size_t use_next = term(p0++, use, op_tags[which++],
false);
366 if (tag_handler.get_op(op_tags[which].first[lat.
get_prop<
int>(
"type", p0)]).n_blocks() == 0)
368 use_next = term(p0, use_next, op_tags[which],
false);
370 vector<size_t> label_(label);
371 label_.push_back(p0-1);
372 label_.push_back(p0);
374 if (which == op_tags.size()-1) {
375 size_t t1 = use_next, t2 = use_next;
376 for (
size_t p2 = p0+1; p2 < prempo.size(); ++p2) {
377 t2 = term(p2, t1, std::make_pair(identities,
false),
true);
380 labels.resize(std::max(t2+1, labels.size()));
383 recurse(p0+1, which+1, use_next, label_, ref);
390 pair<size_t, size_t> rcd =
rcdim(ops);
397 pair<size_t, size_t> rcd =
rcdim(ops);
404 pair<size_t, size_t> rcd =
rcdim(ops);
definition of Lattice base class
CorrMakerNN(Lattice const &lat_, const std::vector< op_t > &ident_, const std::vector< op_t > &fill_, std::vector< std::pair< std::vector< op_t >, bool > > const &ops, int ref=-1)
MPO< Matrix, SymmGroup > create_mpo()
include all symmetry definitions
virtual MPO< Matrix, SymmGroup > create_mpo()=0
vector< vector< size_t > > const & numeric_labels()
declaration of block_matrix class
virtual std::string description() const =0
MPO< Matrix, SymmGroup > create_mpo()
vector< vector< size_t > > const & numeric_labels()
std::string description() const
definition of MPO class (vector of MPOTensor)
T get_prop(std::string property, pos_t site) const
std::pair< size_t, size_t > rcdim(Vector const &pm)
algorithms for block_matrix (gemm, svd, etc.)
CorrMaker(Lattice const &lat_, const std::vector< op_t > &ident_, const std::vector< op_t > &fill_, std::vector< std::pair< std::vector< op_t >, bool > > const &ops, int ref=-1)
virtual vector< vector< size_t > > const & numeric_labels()=0
std::string description() const
declaration of OPTable, TagHandler and KronHandler