0 votes
asked by (220 points)
edited by

I was noticing some strange results after using the function nmultMPO and so I decided to look directly the mpoalgs.cc file.

It looks to me that, in line 60 there should be
auto lB = linkInds(B);
insted of
auto lB = linkInds(A);

am I wrong?

commented by (8.5k points)
Indeed, that does look like a mistake on that line, thanks for pointing it out. I'll push a fix for that.

Could you please post a minimal code example using `nmultMPO` that is leading to incorrect results for you, so that we can make sure it fixes any problems you are seeing?
commented by (220 points)
Thank you for your fast reply!

I was computing the variance of the Hamiltonian H measured on a state psi. I think it would be too long to post the details, but the part of interest is:

MPO H2 = MPO(sites);
H2 = nmultMPO(prime(H),H,{"MaxDim",1000,"Cutoff",1E-13});
double variance = inner(psi, H2, psi)  -  inner(psi, H, psi) *  inner(psi, H, psi)  ;
commented by (8.5k points)
I'm a bit confused about what is going on here. I ran the following minimal code on v3:

    int N = 5;
    auto sites = SpinHalf(N,{"ConserveQNs",false});
    auto ampo = AutoMPO(sites);
    for(auto j : range1(N-1))
        {
        ampo += 0.5,"S+",j,"S-",j+1;
        ampo += 0.5,"S-",j,"S+",j+1;
        ampo +=     "Sz",j,"Sz",j+1;
        }
    auto H = toMPO(ampo);
    auto psi = randomMPS(sites);
    auto H2 = nmultMPO(prime(H), H);
    PrintData(inner(psi, H2, psi) - inner(H, psi, H, psi));

and it runs fine (note that `inner(H, psi, H, psi)` is an alternative way to calculate `inner(psi, H2, psi)` without using `nmultMPO`). After I change that line in mpoalgs.cc as you suggested (which I believe is correct), the code above also runs correctly. Either way, all of the unit tests pass.

Could you give a more complete minimal code that is showing issues? Before making the change, I would like to test if it fixes the issue you are seeing (or if perhaps you have another issue).
commented by (8.5k points)
Alternatively, if it is difficult to create a minimal example, could you checkout the branch `nmultmpo_bugfix` I created that makes the suggested change (or just make the change locally) and see if it fixes the problem you are seeing?
commented by (220 points)
I have just discovered that my issue was related to another error (not related to the library itself).

Nevertheless, I think that in this case there would be no problem because the two operators that you are multiplying are the same, and so the (possible) error doesn't arise.

I think that a possible check can be to calculate the expectation value of an operator C, given by C=A*B with A different from B.
commented by (8.5k points)
Thanks for the update.

Oddly enough, the unit tests already have checks for cases like that: https://github.com/ITensor/ITensor/blob/v3/unittest/mpo_test.cc#L516

I think I understand why it might not be causing issues. The only place those link indices are used are to initialize an input ITensor for a later call to `denmatDecomp`. I think `denmatDecomp` is only using the indices of the other ITensor that is input, so those indices aren't really being used at all. Anyway, it is probably good to fix it since at the very least it is confusing.

1 Answer

0 votes
answered by (8.5k points)
selected by
 
Best answer

It appears that this bug is not causing errors in the code (the reported errors are unrelated, see the comments above). I'll push a fix anyway, since the code is a bit confusing as it is.

Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...