ITensor / website

Source code for the website at itensor.org
http://itensor.org
6 stars 12 forks source link

Create a page of performance tips #42

Open mtfishman opened 5 years ago

mtfishman commented 5 years ago

It would be good to add a page somewhere with a list of performance tips for ITensor/tensor network contraction methods.

One example is a performance issue I was just running into, where I was contracting two MPS psi and phi like this:

auto N = 10;
auto sites = SiteSet(N,2);
auto psi = MPS(sites);
auto phi = MPS(sites);
auto O = psi(1)*phi(1);
for( auto n : range1(N) )
   O *= psi(n) * phi(n);

and getting really bad performance (for medium to large bond dimensions). The definition of *= in ITensor leads to a different order of operations than I was expecting (performing psi(n)*phi(n) first, then contracting with O). So a better way is to write this as:

for( auto n : range1(N) )
  {
  O *= psi(n);
  O *= phi(n);
  }

I was used to the definition of x *= y from Julia, where it is always lowered to x = x * y, so it took longer than it should have for me to catch this. Anyway, just adding a note about this for future reference.

emstoudenmire commented 5 years ago

Agreed, it would be good to have information about this sort of thing on the website.

But I should add that this sort of behavior is not ITensor-specific. Instead, it's the order of operations that C++ itself imposes. Still something good for users to be aware of, especially if it's different in Julia.

mtfishman commented 5 years ago

Yeah I didn't mean to imply it was ITensor specific. But it is something that could be benign if you were not multiplying with ITensors (i.e. multiplying scalars).

The part that is ITensor/TN specific is being careful about order of operations, so maybe this is just part of a current tutorial or book page (for example http://www.itensor.org/docs.cgi?vers=cppv2&page=tutorials/cost).