# Any contraction orders available out of the box in itensor?

**URL:** <https://itensor.discourse.group/t/any-contraction-orders-available-out-of-the-box-in-itensor/2400>\
**Category:** ITensor Julia Questions\
**Created:** [May 27, 2025, 6:16am UTC](https://itensor.discourse.group/t/any-contraction-orders-available-out-of-the-box-in-itensor/2400 "2025-05-27T06:16:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritvik1sharma](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ritvik1sharma/32/766_2.png) [@Ritvik1sharma](https://itensor.discourse.group/u/Ritvik1sharma)\
**Post date:** [May 27, 2025, 6:16am UTC](https://itensor.discourse.group/t/any-contraction-orders-available-out-of-the-box-in-itensor/2400/1 "2025-05-27T06:16:43Z")

</div>

Hi everyone, I am fairly new to itensor and have been facing issues in solving tensor networks with large numbers of tensors. These networks are defined with individual tensors connected with a index map. I am facing issues in running it for larger system sizes. I had 2 questions:

1. Are there ways I can play with this order out-of-the-box in iTensor i.e. any way to experiment with different contraction algorithms like greedy, optimal etc? Something similar to [TensorNetwork/tensornetwork/contractors/opt\_einsum\_paths/path\_contractors.py at master · google/TensorNetwork · GitHub](https://github.com/google/TensorNetwork/blob/master/tensornetwork/contractors/opt_einsum_paths/path_contractors.py) would be great!
2. Does changing between defining tensor network as a collection of tensors and index map, differ in performance with using MPS/MPOs?

Specifically, I am trying to solve TNs with different prameterized sizes. For a problem of size n=4, the network is defined as:

```auto
x_tensors = [x1, x2, x3, x4] # MPS states
data_indices = [index_map["x1_dim0"], index_map["x2_dim0"], index_map["x3_dim0"], index_map["x4_dim0"]] # MPS state indexes
free_indices = [index_map["R_2_0__dim2"], index_map["R_2_1__dim3"], index_map["R_2_2__dim3"], index_map["R_2_3__dim3"]] # Output indexes from the last MPO attached on the MPS

# Define the network excluding data tensors
network_base = [
    H __x1_x2__ , H __x2_x3__ , H __x3_x4__ , # Tensors that form the first MPO attached on the MPS
    R_0_0_, R_0_1_, R_0_2_, R_0_3_, # Tensors that form the second MPO
    R_1_0_, R_1_1_, R_1_2_, R_1_3_, # Tensors that form the third MPO
    R_2_0_, R_2_1_, R_2_2_, R_2_3_ # Tensors that form the fourth MPO

]

```

I take this base network and add the x\_tensors into it to create the final tensor network. I am trying to use contract this tensor network. By default I call

```auto
        T = contract(network; cutoff=1e-6)

```

For a larger “n” like 10, this network contraction faces OOM error and is killed by OS. I also tried:

```auto
sequence1 = optimal_contraction_sequence(network)
cost = contraction_cost(network; sequence = sequence1)
T = contract(network; sequence = sequence1)

```

Here code seems to take forever in optimal\_contraction\_sequence calculation. But I know this network can be reasonable solved with a greedy contraction ordering. Can I easily experiment with different algorithms?

---

<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:** [May 27, 2025, 2:57pm UTC](https://itensor.discourse.group/t/any-contraction-orders-available-out-of-the-box-in-itensor/2400/2 "2025-05-27T14:57:28Z")

</div>

We are working on that in [ITensorNetworks.jl](https://github.com/ITensor/ITensorNetworks.jl), we have a number of contraction sequence optimization backends available including optimal and greedy, you can try it out there but please note the warning in the README.
