On the Optimal Linear Contraction Order for Tree Tensor Networks

Mihail StoianarXiv 2022 · OpenReview

Abstract

The contraction cost of a tensor network depends on the contraction order. However, the optimal contraction ordering problem is known to be NP-hard. We show that the linear contraction ordering problem for tree tensor networks admits a polynomial-time algorithm, by drawing connections to database join ordering. The result relies on the adjacent sequence interchange property of the contraction cost, which enables a global decision of the contraction order based on local comparisons. Based on that, we specify a modified version of the IKKBZ database join ordering algorithm to find the optimal tree tensor network linear contraction order. Finally, we extend our algorithm as a heuristic to general contraction orders and arbitrary tensor network topologies.

Introduction

In fields like quantum physics and machine learning, researchers frequently need to "contract" a network of tensors—a process involving a massive sequence of multi-dimensional matrix multiplications. While the final result is invariant to the order of operations, the computational cost in terms of time and memory varies wildly. Finding the absolute optimal order is generally an NP-hard problem, forcing a reliance on heuristics or expensive dynamic programming that only scales to small networks. This paper addresses this challenge for Tree Tensor Networks (TTNs), demonstrating that finding the optimal linear contraction order can be achieved in polynomial time.

Methods

The authors bridge the gap between quantum physics and database theory by identifying that contracting tensors is mathematically analogous to joining tables in a relational database.

Linear vs. General Contraction Orders

A linear contraction order involves adding one tensor at a time to a growing core. In contrast, a "bushy" or general order allows for independent sub-groups of tensors to be contracted separately before merging. While general orders can be more efficient, they are significantly harder to optimize.

Comparison of (a) Linear and (b) General contraction trees.

TensorIKKBZ and the ASI Property

The core of the proposed method is TensorIKKBZ, an adaptation of the IKKBZ algorithm originally designed for database query optimization. The authors prove that the tensor contraction cost function satisfies the Adjacent Sequence Interchange (ASI) property. This property is the theoretical cornerstone that allows a global optimal decision to be made based on simple local comparisons between neighboring tensors. To apply the algorithm, the network is first represented as a rooted tree.

The process of rooting a tree to facilitate the contraction ordering algorithm.

Linearized Dynamic Programming (LinDP)

To find near-optimal general orders, the authors introduce LinDP. This method uses the optimal linear order as a "seed" and applies a cubic-time dynamic programming step to "bushify" the tree. For networks that are not trees (generic graphs), they employ a Spanning Tree Heuristic, converting the graph into a tree structure to leverage their optimized algorithms.

Results

The authors evaluated their algorithms on synthetic benchmarks (Hierarchical Tucker and Fork-Tensor Product States) and real-world quantum circuit structures like the Google Sycamore processor.

  • Optimality: For tree networks, TensorIKKBZ is guaranteed to find the optimal linear contraction order in $O(n^2)$ time.
  • Efficiency: On FTPS and HT networks, the LinDP approach consistently outperformed state-of-the-art hypergraph optimizers like cotengra by nearly an order of magnitude in total contraction cost.
  • Speed: Because the algorithms leverage the underlying tree structure rather than treating the network as a generic graph, they are significantly faster than general-purpose optimizers.
  • Versatility: Even on the non-tree Sycamore circuit, the spanning-tree-based heuristic remained competitive with specialized quantum circuit optimizers.

Conclusion

By adapting decades of database research, this work provides a mathematically grounded and efficient approach to tensor network contraction. While currently a heuristic for general orders and hyperedges, the method sets a new standard for speed and efficiency in TTN optimization. Future work will focus on extending the core logic to handle hyperedges and non-naive contraction cost models.

Summary updated

Abstract

The contraction cost of a tensor network depends on the contraction order. However, the optimal contraction ordering problem is known to be NP-hard. We show that the linear contraction ordering problem for tree tensor networks admits a polynomial-time algorithm, by drawing connections to database join ordering. The result relies on the adjacent sequence interchange property of the contraction cost, which enables a global decision of the contraction order based on local comparisons. Based on that, we specify a modified version of the IKKBZ database join ordering algorithm to find the optimal tree tensor network linear contraction order. Finally, we extend our algorithm as a heuristic to general contraction orders and arbitrary tensor network topologies.
BibTeX
@misc{stoian2022optimal,
  author = {Mihail Stoian},
  title = {{On the Optimal Linear Contraction Order for Tree Tensor Networks}},
  year = {2022},
  eprint = {2209.12332},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2209.12332},
}

Loading related content...

Figure