# lazy storage - force contraction

**URL:** <https://itensor.discourse.group/t/lazy-storage-force-contraction/257>\
**Category:** ITensor C++ Questions\
**Created:** [July 18, 2022, 9:24am UTC](https://itensor.discourse.group/t/lazy-storage-force-contraction/257 "2022-07-18T09:24:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marchewkowy](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@marchewkowy](https://itensor.discourse.group/u/marchewkowy)\
**Post date:** [July 18, 2022, 9:24am UTC](https://itensor.discourse.group/t/lazy-storage-force-contraction/257/1 "2022-07-18T09:24:08Z")

</div>

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

if I have:

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

```

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

Best,  
Mateusz

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [July 19, 2022, 12:03am UTC](https://itensor.discourse.group/t/lazy-storage-force-contraction/257/2 "2022-07-19T00:03:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [July 19, 2022, 11:42am UTC](https://itensor.discourse.group/t/lazy-storage-force-contraction/257/3 "2022-07-19T11:42:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marchewkowy](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@marchewkowy](https://itensor.discourse.group/u/marchewkowy)\
**Post date:** [July 19, 2022, 12:02pm UTC](https://itensor.discourse.group/t/lazy-storage-force-contraction/257/4 "2022-07-19T12:02:14Z")

</div>

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.

Best,  
Mateusz

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [July 19, 2022, 6:43pm UTC](https://itensor.discourse.group/t/lazy-storage-force-contraction/257/5 "2022-07-19T18:43:33Z")

</div>

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