Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Create a page of performance tips #42

Open
mtfishman opened this issue Apr 12, 2019 · 2 comments
Open

Create a page of performance tips #42

mtfishman opened this issue Apr 12, 2019 · 2 comments

Comments

@mtfishman
Copy link
Member

mtfishman commented Apr 12, 2019

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
Copy link
Contributor

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
Copy link
Member Author

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).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants