# Issues using applyExpH

Hi,
I am trying to calculate the MPS resulting from exp(-tau H)|psi> where where H has up to three site interaction terms, and the exponential is the usual Boltzmann operator in this case.
I can't use expH because of the three term interactions so I moved to applyExpH, but I keep on having an allocation error which I cannot trace back.

Here is a snippet of my code

auto args = Args("Cutoff=",1E-8,"MaxDim=",20,"Order=",2);
for (int i = 1; i<= Nstep; i++)
{
std::cout << "Step " << i << std::endl;
applyExpH(psi1,H,dt,res,args);
psi1 = res;
println("Norm: ",norm(res));
}
writeToFile(pfile,psi1);


The error I get is the following:
terminate called after throwing an instance of 'std::badalloc'
alloc
Removing the three site interactions the error disappear so it must be related to the Hamiltonian structure. Is this a normal behaviour?

Regards,
Raffaele

commented by (70.1k points)
Hi Raffaele, it’s a little hard to say what’s causing the error. Did you compile and run the code in debug mode? http://itensor.org/docs.cgi?vers=cppv3&page=formulas/debug_mode

commented by (310 points)
Hi,
in debug mode I can't see any error. The code runs without problems.
commented by (70.1k points)
Hi, ok thanks. That's interesting. So then I'm not sure what's happening. All I can guess right now is that std::bad_alloc happens sometimes when the code is using too much ram, more than is available on the system. Are you running the code for either a very long time or involving a very large MPS bond dimension in the many thousands? Or if there is a bug in the code it could be using up a lot of ram by mistake.

Please monitor the ram usage of the code before it crashes and see if that gives a clue. Barring that I'll need to run your code myself to investigate the issue.

Miles
commented by (310 points)
Hi, thanks for the help. I tried several things but unfortunately this error is difficult to reproduce. I am currently running the code without issues but every now and then I get this error. I might also suspect some OS/hardware issue. I'll monitor the job and post an update if any.
Raffaele
commented by (70.1k points)
Hi Raffaele, thanks. Yes, please keep an eye on the ram used (and of course make sure no other program is using up too much ram at the same time). It could be that ITensor is using quite a lot relative to the total you have, and unfortunately even modern software does not handle the case of running out of ram very gracefully.

Best,
Miles
commented by (70.1k points)
Of course please let us know if ITensor seems to be using an unwarranted amount of ram, say in excess of 10 Gb for a modest calculation. On the other hand, when working with MPS having bond dimensions in the thousands, it can actually be normal for tensor network calculations to need many hundreds of Gb of ram! (Depending on the algorithm used.)