0 votes
asked by (680 points)

I am making a Lanczos type algorithm, and when I add two MPS' I am getting a segfault. The relevant code snippet is

    V = std::vector<MPS>(actual_maxiter+2);
    auto W = std::vector<MPS>(actual_maxiter+2);
    auto WP = std::vector<MPS>(actual_maxiter+2);
    T = CMatrix(actual_maxiter+2,actual_maxiter+2);
    for(auto& el : T) el = Cplx(0,0);
    V[0] = psii;
    WP[0] = applyMPO(A,V[0],args);
    T(0,0) = innerC(WP[0],V[0]).real();
    auto num = -1*T(0,0);
    W[0] = num*V[0];
    W[0].plusEq(WP[0]);

psii is an MPS passed into the function, V and T are members of my class. I am getting the segfault from the last line. I have also tried using sum instead of plusEq, and also there is a segfault. What is going wrong?

Also if I shift the positions to match for W[0] and WP[0], then I get the error "different index structure." Not sure if this last statement is useful information, but I figured I would share.

commented by (70.1k points)
Hi Nick, did you try running the code in debug mode to see if you get a more helpful error message? Also did you print out the two MPS you are summing to inspect their index structure? They have to have the same physical indices for the sum to work.

Debug mode instructions:
http://itensor.org/docs.cgi?vers=cppv3&page=formulas/debug_mode
commented by (680 points)
edited by
Hi Miles, in debug mode I get the error:
'SafePtr: pointer is null'
Not sure why, the MPS' that are used in sum have been set equal to something before the sum.

I checked the index structure, and they have the same physical indices, but WP[0] was all primed. So I added the line of code

WP[0] = noPrime(WP[0],siteInds(WP[0]));

Still a segfault.

The sum is basically a|v> + A|v>, where A is an MPO and a is a number. Is it normal for applyMPO to change the index structure? Should I be doing this some other way?

1 Answer

0 votes
answered by (680 points)

I solved this issue by adding

    V[0].position(c);
    WP[0].position(c);
    WP[0].replaceSiteInds(siteInds(V[0]));

To make sure the positions and the indices matched before adding. For some reason the sum function that takes a vector of MPS' does not work, but at least this does.

commented by (70.1k points)
Hi Nick, glad you were able to get it working. Yes, the indices have to match before adding. (The gauge positions shouldn't have to be the same for adding to work, so it would be interesting to comment out both of the .position(c) lines to see if it still works.)

I can't easily comment on what wasn't working in your earlier code without more context, such as knowing how the MPO "A" was defined. But if it was making WP[0] have different indices from V[0] then the addition does not work in that case.

Best regards,
Miles
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

...