[Paper Review] NCON: A tensor network contractor for MATLAB
This paper introduces ncon(), a MATLAB-based tensor network contractor that efficiently computes the contraction of multi-tensor networks using optimized pairwise contractions via permute and reshape operations. It provides a modern, well-documented, and maintainable alternative to legacy tensor network tools, supporting features like traces, outer products, and disjoint networks, with a focus on performance and correctness in quantum many-body simulations.
A fundamental process in the implementation of any numerical tensor network algorithm is that of contracting a tensor network. In this process, a network made up of multiple tensors connected by summed indices is reduced to a single tensor or a number by evaluating the index sums. This article presents a MATLAB function ncon(), or "Network CONtractor", which accepts as its input a tensor network and a contraction sequence describing how this network may be reduced to a single tensor or number. As its output it returns that single tensor or number. The function ncon() may be obtained by downloading the source of this preprint.
Motivation & Objective
- To provide a modern, maintainable, and well-documented replacement for legacy tensor network contraction tools like scon() in MATLAB.
- To support efficient and correct contraction of tensor networks used in quantum many-body physics, including traces, outer products, and disjoint networks.
- To implement a robust, backward-compatible interface that preserves the syntax of earlier tools while adding new functionality.
- To improve performance and reliability by using BLAS-accelerated matrix multiplication through permute and reshape operations.
- To detect and warn on suboptimal contraction sequences, particularly those that fail to contract all shared indices at once.
Proposed method
- The ncon() function performs tensor contractions by applying a sequence of pairwise operations using MATLAB’s permute and reshape functions to reorganize indices before matrix multiplication.
- Pairwise contractions are implemented as matrix multiplications via reshape and permute, leveraging BLAS for high performance.
- The function supports leg-labelling notation to specify which indices are contracted, with negative indices in legLinks defining the output index order.
- Traces are computed using a dedicated doTrace() function that sums over repeated indices, with warnings issued if traces are not fully contracted.
- Zeros-in-sequence notation is parsed via zisOuterProduct() to handle outer products and trivial (dimension-1) indices.
- The contraction sequence is processed step-by-step, with indices removed after each operation, and the final output is reordered according to the specified finalOrder or legLinks.
Experimental results
Research questions
- RQ1How can a tensor network contraction function be implemented in MATLAB to support both standard contractions and advanced features like traces and outer products?
- RQ2What is the most efficient way to perform pairwise tensor contractions in MATLAB using native functions and BLAS-optimized operations?
- RQ3How can a modern, maintainable, and well-documented tensor network contractor be designed to replace legacy, undocumented, and forked versions of similar tools?
- RQ4Can the tool detect and warn on suboptimal contraction sequences that lead to unnecessary computational overhead?
- RQ5What is the impact of contracting only subsets of shared indices versus all shared indices at once, and how can such inefficiencies be identified?
Key findings
- The ncon() function successfully implements a high-performance, backward-compatible tensor network contractor in MATLAB using optimized matrix multiplication via permute and reshape.
- The tool supports advanced features such as traces, outer products, disjoint networks, and 1D/0D objects, which were missing or poorly supported in earlier tools.
- The function issues warnings when a contraction sequence fails to contract all shared indices at once, indicating potential inefficiency.
- The implementation is fully documented and centrally maintained, with known provenance, addressing the lack of attribution and documentation in previous scon() variants.
- The use of BLAS-accelerated matrix multiplication ensures high performance, and the method is robust for a wide range of tensor network algorithms in quantum many-body physics.
- The function correctly handles complex index patterns, including those with repeated indices for traces and zeros-in-sequence notation for outer products.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.