Contracting Tensor Networks
To contract a tensor network is to sum over its shared (internal) indices, collapsing many tensors into a single resulting tensor. Every quantity you read off a tensor network — an amplitude, an overlap, an expectation value, the unitary of a circuit — is the result of a contraction. This lesson develops the idea on the smallest possible networks.
Contraction is index summation
Two tensors connected by a shared index are contracted by summing over that index. For two matrices and sharing the middle index ,
which is ordinary matrix multiplication. The free indices survive; the bond index is summed away. A tensor network is just a bookkeeping diagram for many such sums at once: a line joining two tensors is a contracted index, a dangling line is a free (physical) index.
For a quantum circuit on a single wire, each gate is a tensor with one input index and one output index. Stacking gates connects each gate's output index to the next gate's input index. Contracting the whole chain — summing over all the internal wire indices — yields the circuit's overall unitary, applied in time order.
Contraction order matters for cost, not for the answer
The contracted result is unique, but the order in which you perform the pairwise sums can change the computational cost enormously. Contracting a long chain left-to-right is cheap; contracting it in a bad order can blow up the size of the intermediate tensors. Choosing a good contraction order is one of the central engineering problems of tensor-network simulation, and finding the optimal order is in general NP-hard. For the tiny networks here every order is cheap, so we focus on getting the answer right.
A worked single-wire contraction
Place three gates on one qubit in time order: , then , then . As matrices,
Contracting the chain means multiplying the matrices in reverse application order (the last gate sits leftmost when acting on a column vector):
Work it out. First :
Then :
The contracted network is the bit-flip . This is the famous identity : conjugating a by Hadamards rotates it into an .
Try it
Build a single-qubit circuit whose contracted unitary equals the Pauli- gate, using only Hadamard and gates — realise the identity . The grader contracts your circuit into its unitary and compares it to the reference solution.
After running, applying your circuit to should produce , confirming the contraction equals .
Sign in on the full site to ask questions and join the discussion.