0 votes
asked by (140 points)

Hi Miles,

I am working with a 20-site electron system with periodic boundary condition. I obtained the ground state with dmrg and measure the spin correlation functions following this formula. However, when the largest bond dim @@\gtrsim 500@@, I always got the error message

terminate called after throwing an instance of 'std::bad_alloc'

If I run the code in gdb, I got the following error message:

Program received signal SIGABRT, Aborted.
0x00007ffff640570f in raise () from /lib64/libc.so.6

This seems to be an issue of running out of memory. However, I have ~400G memory and this program seems only using @@\gtrsim@@10G memory. I am not sure whether this is an issue of my code or I really run out of memory. The relevant part of the code is the following function:

Real TwopointCorrelation(const Electron& sites, MPS& psi, string Opi, string Opj, int site_i, int site_j)
  int N = length(sites);

  auto op_i = op(sites,Opi,site_i);
  auto op_j = op(sites,Opj,site_j);

  //'gauge' the MPS to site i
  //any 'position' between i and j, inclusive, would work here

  //Create the bra/dual version of the MPS psi
  auto psidag = dag(psi);

  //Prime the link indices to make them distinct from
  //the original ket links

  //index linking i-1 to i:
  auto li_1 = leftLinkIndex(psi,site_i);

  auto C = prime(psi(site_i),li_1) * op_i * prime(psidag(site_i),"Site");
  for(int k = site_i+1; k < site_j; ++k)
      C *= psi(k) * psidag(k);
  //index linking j to j+1:
  auto lj = rightLinkIndex(psi,site_j);

  C *= prime(psi(site_j),lj) * op_j * prime(psidag(site_j),"Site");

  auto result = elt(C); //or eltC(C) if expecting complex

  return result;

Thank you so much!

commented by (70.1k points)
Hi, when you say you are working with periodic boundary conditions, do you mean just your Hamiltonian has PBC (site 1 connecting to site N) ? Or is your MPS also periodic too, as in having the topology of a circle instead of a chain? Both are valid approaches: I just ask because periodic MPS can incur a lot of extra memory costs.

Also did you print out the indices of the "C" tensor at each step? That could give really useful information about what's happening. For example there could be some indices that aren't matching correctly so that C is ending up with many indices instead of just 3.

commented by (70.1k points)
Let me also add that every time I've encounteed this error it's been because my system ran out of memory. So even if you don't think you are running out of memory, it's still possible that you are but it's just happening too suddenly for your system monitor (or whichever program you are using to track the memory usage) to report this correctly to you.

A good idea would be to see if the code produces a large tensor with many indices by mistake, as usually this is why tensor network codes suddenly run out of memory.

Please log in or register to answer this question.

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.