+1 vote
asked by (170 points)

I'm having trouble trying to reflect an MPS psi around the center of a 1D lattice-
psi(x) ---> psi(-x)
I expected changing the order of the tensors to be enough, i.e. change the tensor at site 1 to be the tensor originally at site N, change site 2 to the tensor at site N-1 etc.
This is the code implementation:

for(int i = 1; i <= N; ++i)
{phi.setA( i, psi.A(N+1-i));}

However, trying to perform a DMRG sweep on the resulting wavefunction phi, I get the error:
terminate called after throwing an instance of 'std::bad_alloc'

Also this error pops up when making calculations on phi using .cplx() :
Wrong number of IndexVals passed to real/cplx (expected 4, got 0)

Swapping just one pair of tensors inside the MPS produced the same error.

Note I'm using IQTensors.
Would appreciate any help.


1 Answer

+1 vote
answered by (70.1k points)
selected by
Best answer

Hi Oren,
Good question. I think the std::bad_alloc may be because your code is running out of memory. This can happen when the contractions are not doing what you think, and the number of indices grows to be very large. I have been meaning to put in a line that checks if the number of indices grows beyond, say, 10 and then throws an error unless disabled by the user.

So I think what's happening is that the MPS tensors are being swapped ok, but then the actual site indices are not being switched. This could cause mismatches to, say, a Hamiltonian made from the original site set which would have the site indices in the original order. So I'd suggest you add the following step: use "delta" tensors (http://itensor.org/docs.cgi?page=classes/diag_itensor) to change all of the site/physical indices after you swap the order of the tensors. For example, on the first site do:

phi.Aref(1) *= delta(dag(sites(N)),sites(1);

which (efficiently) replaces the Nth site index with the first site index. Here I'm assuming "sites" is the variable holding your site set (SpinHalf, Hubbard, SpinOne, etc. are examples of site sets).

Please let me know if that fixes your issue -


commented by (70.1k points)
One other comment is that it's always a good idea to run your code in "debug mode" (http://itensor.org/docs.cgi?page=formulas/debug_mode) to test it. This enables many more error messages which can be much more informative and tell you what's happening before you get a cryptic "std::bad_alloc" or some such error.
commented by (170 points)
Thanks! that fixed it.
Another problem appeared though- when I try to add the original MPS to the reflected one:


I get the following error on debug mode:

nindex() = 3
i = 140733193388033

IQIndex::qn arg out of range

Any idea why this happens?

commented by (70.1k points)
Hi Oren,
This is a bug of some sort, but whether it's coming from your code or from ITensor is hard to tell. Can you email me a minimal code that reproduces the issue? I will try it out and see what I find. Always good to keep an eye out for issues like this - thanks.

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.