Hi there,
I am still struggling with adding IQMPOs (IQMPSs) and I hope to get some help here.
A couple of weeks ago I already pointed out that the plusEq
function gives segfaults for any IQMPS and IQMPO I tried. After some research I figured out that this is due to the plussers(IQIndex, IQIndex, IQIndex, IQTensor, IQTensor)
function. I rewrote it and now I come up with
bool
hasQN(const IQIndex& I, const QN& qn)
{
for(auto& iq : I)
if(iq.qn == qn) return true;
return false;
}
void
plussers(IQIndex const& l1, IQIndex const& l2,
IQIndex& sumind,
IQTensor& first, IQTensor& second)
{
vector<IndexQN> iq;
vector<IQIndex> map;
for(IndexQN const& x : l1)
{
if(hasQN(l2, x.qn))
{
Index y = findByQN(l2, x.qn);
Index jj(x.index.rawname() + y.rawname(),x.m() + y.m(),x.type());
iq.push_back(IndexQN(jj, x.qn));
for (int i = 1; i <= x.m(); i++) { map.push_back(l1); }
for (int i = 1; i <= y.m(); i++) { map.push_back(l2); }
}
else
{
Index jj(x.index.rawname(),x.m(),x.type());
iq.push_back(IndexQN(jj, x.qn));
for (int i = 1; i <= x.m(); i++) { map.push_back(l1); }
}
}
for(IndexQN const& y : l2)
{
if(!hasQN(l1, y.qn))
{
Index jj(y.index.rawname(),y.m(),y.type());
iq.push_back(IndexQN(jj, y.qn));
for (int i = 1; i <= y.m(); i++) { map.push_back(l2); }
}
}
sumind = IQIndex(sumind.rawname(),std::move(iq),sumind.dir(),sumind.primeLevel());
assert(sumind.m() == l1.m() + l2.m());
first = IQTensor(dag(l1), sumind);
int count = 1;
for (int i = 1; i <= sumind.m(); i++)
{
if (map[i-1] == l1)
{
first.set(l1(count), sumind(i), 1.0);
count++;
}
}
second = IQTensor(dag(l2), sumind);
count = 1;
for (int i = 1; i <= sumind.m(); i++)
{
if (map[i-1] == l2)
{
second.set(l2(count), sumind(i), 1.0);
count++;
}
}
}
which works quite well as long as all links in the IQMPOs (IQMPSs) have corresponding arrow directions. I mean, when adding IQMPO A and IQMPO B, the first link of A needs to have the same arrow as the first link of B; the second link of A needs to have the same arrow as the second link of B....
But as soon as the n-th Link of A and B differ, the code breaks in addAssumeOrth
when adding the parts together. This is due to a QN issue I don't know how to solve.
I hope somebody can give me hint on how to fix this.
I also would be happy about some theory. How are MPOs and MPSs with different arrow structure supossed to be added? I hardy find anything on this in the literature. I tried repositioning of the MPOs (MPSs) but that change the arrow direction in my case (might this be a bug?).
Best,
Lars