lazy storage - force contraction

is there a way to force contraction of tensors that by default use lazy contraction?

if I have:

auto D = A*B*C*E*F*G;

I would like that contraction to be actually computed and stored in “D”.


Hi Mateusz,
If I’m understanding your question correctly, ITensors actually don’t have lazy contraction behavior. The code above would “eagerly” contract A*B, then contract the (fully computed) result of that with C, then with E,F,G. Afterward the result will be fully computed and stored in D.


@miles doesn’t it contract left-to-right, i.e. first perform A * B, then contract with C, then with E, etc.?

@marchewkowy what would you be trying to gain with lazy contraction? The main advantage would be allowing for contraction sequence optimization (i.e. automotically determining a better order to contract the ITensors {A, B, C, E, F G}) which is currently not supported in the C++ version of ITensor but is supported in the Julia version.

Hi I actually want to avoid the lazy contraction. I want to compute something for all (i,j) where i,j are sites number for Extended Bose Hubbard model. My code requires me to contract tensors associated with MPS state of sites i,i+1,…, j. I wanted to store the contraction from the last step and reuse it in the new step.

But as I understand the reply by Miles and You there is actually no lazy contraction at all, which is what I needed.


@mtfishman thanks for catching that – I just edited my answer

@marchewkowy yes it sounds like ITensor already does what you need. Please give it a try in your code and let us know if it’s not working as you need.