# std::bad_alloc in spin-polarized system

0 votes
asked

Hello.
I am studying the spin-polarized system(J<0 Heisenberg Chain) by iDMRG.
When I calculate two-site correlator, I met error:

terminate called after throwing an instance of 'std::bad_alloc'
what():  std::bad_alloc


The MPS I'd like to contruct is,

psi.A(2) =
/--------------IQTensor--------------
r=3 div=QN(0) log(scale)=0
IQIndex("d",1400,Link|364) <Out>
("d_0",9,Link|122) QN(1672)
("d_1",53,Link|233) QN(1674)
("d_2",141,Link|696) QN(1676)
("d_3",243,Link|799) QN(1678)
("d_4",304,Link|145) QN(1680)
("d_5",291,Link|740) QN(1682)
("d_6",212,Link|105) QN(1684)
("d_7",109,Link|767) QN(1686)
("d_8",34,Link|353) QN(1688)
("d_9",4,Link|863) QN(1690)

IQIndex("S=1/2 2",2,Site|143) <Out>
("Up 2",1,Site|4) QN(1)
("Dn 2",1,Site|62) QN(-1)

IQIndex("d",1400,Link|19) <In>
("d_0",15,Link|943) QN(1673)
("d_1",67,Link|38) QN(1675)
("d_2",161,Link|871) QN(1677)
("d_3",261,Link|249) QN(1679)
("d_4",307,Link|234) QN(1681)
("d_5",280,Link|176) QN(1683)
("d_6",191,Link|472) QN(1685)
("d_7",91,Link|728) QN(1687)
("d_8",24,Link|711) QN(1689)
("d_9",2,Link|489) QN(1691)
("d_10",1,Link|111) QN(1671)
\------------------------------------


and my code is,

Print(psi.A(2));
Print(prime(dag(psi.A(2))));
Print(psi.A(2) * prime(dag(psi.A(2)), Link)); // <- cause error!


. m>=400 always cause this error, but I checked m=200 goes well.
My server has 512GB RAM.
I think that the large QN due to the spin-polarization and the large maxm might cause this problem.
"to_MPS" function does not resolve this issue.

Can I fix this problem? Should I do something like "reset QN"?
Thank you in advance.

## 1 Answer

0 votes
answered by (160 points)

Hello, I solved this problem.
This problem is due to my little knowledge of the efficient MPS contraction.

The Tensor

  psi.A(2) * prime(dag(psi.A(2))


has a very big index dimension, but what I'd like to do is calculate a correlation function.
So I should do:

lcorr *= psi.A(2);
lcorr *= prime(dag(psi.A(2)), Link);


where "lcorr" follows basic notation in the ITensor code formula.

Thank you every one.

commented by (70.1k points)
Thanks very much for posting this answer. I was planning to reply but was a bit puzzled as to how this issue could be occurring without looking much more closely at your code.

We have been planning to add a feature which, when in debug mode, throws an error if any tensor has too many indices, say 10 indices. This feature would help catch bugs of the type you just encountered. So thanks for the reminder that we should definitely add this bug-catching feature!