# Order of contractions in a Tensor Diagram

**URL:** <https://itensor.discourse.group/t/order-of-contractions-in-a-tensor-diagram/406>\
**Category:** DMRG and Numerical Methods\
**Created:** [September 21, 2022, 12:54pm UTC](https://itensor.discourse.group/t/order-of-contractions-in-a-tensor-diagram/406 "2022-09-21T12:54:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSB](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@JSB](https://itensor.discourse.group/u/JSB)\
**Post date:** [September 21, 2022, 12:54pm UTC](https://itensor.discourse.group/t/order-of-contractions-in-a-tensor-diagram/406/1 "2022-09-21T12:54:33Z")

</div>

Hi, another naive question from a DMRG newbie: is there any order for contractions implied in tensor network diagrams? Are there any defined rules?

Thank you! 🙂

---

<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:** [September 21, 2022, 9:56pm UTC](https://itensor.discourse.group/t/order-of-contractions-in-a-tensor-diagram/406/2 "2022-09-21T21:56:28Z")

</div>

It’s a good question. Tensor diagrams do **not** usually contain any information about the order in which they are to be contracted. Figuring out this order is an important role of the programmer when implementing them. While it can be easy to figure out the most efficient ordering by hand for smaller diagrams or ones with obvious structure (like a 1d structure or tree structure) in general it’s a hard (even NP hard) problem and an active area of research.

We already do offer a feature in ITensor that lets you input a set of ITensors to contract then have our backend figure out a best ordering of the contractions. Here is the doc page about it:  
[https://itensor.github.io/ITensors.jl/stable/ContractionSequenceOptimization.html](https://itensor.github.io/ITensors.jl/stable/ContractionSequenceOptimization.html)

More options will be added to this system in the future, such as different algorithms for determining contraction orders (most are heuristic in order to have sufficiently good scaling with the number of tensors in the diagram).

---

<div class="post-metadata">

**Author:** ![JSB](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@JSB](https://itensor.discourse.group/u/JSB)\
**Post date:** [September 22, 2022, 7:21pm UTC](https://itensor.discourse.group/t/order-of-contractions-in-a-tensor-diagram/406/3 "2022-09-22T19:21:44Z")

</div>

Thank you! 🙂
