Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

TensorNetworks

Guides

  • TensorNetworks

Tech Notes

  • Building Tensor Networks
  • Contraction Paths and Execution
  • Matrix Product States
  • A Working Tour of the Symmetry Functions
  • Tensor Networks Overview
  • Young Tableaux and Tensor Symmetries

Symbols

  • ActivateTensors
  • BinaryTensorNetwork
  • BinaryTensorNetworkQ
  • CanonicalPath
  • CanonicalPathQ
  • ContractIndices
  • ContractionTree
  • EinsteinSummation
  • GreedyContractionPath
  • HookFactor
  • HookLength
  • HookLengths
  • IndexedMultiply
  • InitializeTensorNetwork
  • MetricTensor
  • MetricTensorQ
  • MPSCanonicalForm
  • MPSCanonicalQ
  • MPSEntanglementEntropy
  • MPSNormalize
  • MPSNorm
  • MPSOverlap
  • MPSSchmidtValues
  • MPSTruncate
  • OptimalContractionPath
  • PartitionQ
  • PathIndexContractions
  • PathQ
  • PathToTreePath
  • RandomTensorNetwork
  • SchurDimension
  • SparseTensorNetwork
  • TableauColumns
  • TableauDimension
  • TableauRows
  • TableauShape
  • TableauSize
  • TableauWeylDimension
  • TensorNetworkAdd
  • TensorNetworkContraction
  • TensorNetworkContractions
  • TensorNetworkContract
  • TensorNetworkData
  • TensorNetworkDelete
  • TensorNetworkFreeIndices
  • TensorNetworkGraphData
  • TensorNetworkGraphQ
  • TensorNetworkIndexDimensions
  • TensorNetworkIndexGraph
  • TensorNetworkIndices
  • TensorNetwork
  • TensorNetworkQ
  • TensorNetworkRemoveCycles
  • TensorNetworkReplaceIndices
  • TensorNetworkSize
  • TensorNetworkTensors
  • TensorNetworkToNetGraph
  • ToTensorNetworkGraph
  • TransposePartition
  • TreePathQ
  • TreePathToPath
  • YoungProject
  • YoungSymmetrize
  • YoungTableau
  • YoungTableauQ
Wolfram`TensorNetworks`
TensorNetworkContraction
​
TensorNetworkContraction
[tn]
returns an inactive contraction expression for the tensor network using an auto-selected path •
​
​
TensorNetworkContraction
[tn,path]
uses the explicit canonical contraction path •
​
​
TensorNetworkContraction
[tn,treePath]
uses a tree-structured contraction path •
​
​
TensorNetworkContraction
[tn,"Greedy"]
auto-computes a greedy contraction path •
​
​
TensorNetworkContraction
[tn,method]
uses method-string "Optimal", "flops", "max", "size", "write", "combo", or "limit" •
​
​
TensorNetworkContraction
[graph]
operates on a tensor-network Graph •
​
​
TensorNetworkContraction
[data]
accepts the low-level Association of network data
​
Details and Options
▪
By default
TensorNetworkContraction
returns an
Inactive
expression tree (
"Inactive"True
) that you can inspect, transform, or pass to
ContractionTree
.
▪
Setting
"Inactive"False
evaluates the tree and returns the numerical tensor; this is the path
TensorNetworkContract
takes.
▪
ActivateTensors
collapses a returned tree into a numerical tensor; this is useful when the tree has already been inspected and only the value is needed.
▪
The
Method
option selects one of five binary-contraction engines: "ArrayDot" (default), "ArrayDotTranspose", "Dot", "TensorContract", and "TableSum". All engines produce numerically identical results after activation; they differ only in the internal representation of the tree. The full list is in
$TensorNetworkContractionMethods
.
▪
For a single-tensor network (no contraction indices),
TensorNetworkContraction
returns the tensor directly via the
EinsteinSummation
fallback path.
▪
A
path
is a list of integer pairs
{{i,j},…}
in opt_einsum convention; a
treePath
is the tree-structured form produced by
PathToTreePath
.
▪
The following options can be given:
Method
"ArrayDot"
binary-contraction engine, one of $TensorNetworkContractionMethods.
"Inactive"
True
when False, evaluates the tree (equivalent to TensorNetworkContract).
"TransposeFunction"
Transpose
transpose primitive used for the final permutation step.
Examples  
(1)
Build a fixed three-tensor network for the path-form examples:
In[2]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}]
Out[3]=
TensorNetwork
Tensors: 3
Binary: Yes
Free indices: 2
Sparse: No
Output dimension: 4
​

​
Default form auto-selects a path:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn]
Out[2]=
TensorContract[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}}{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}}{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},{{2,3},{4,5}}]
​
An explicit canonical path drives the binary contractions step by step:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,{{1,2},{1,2}}]
Out[2]=
Transpose[ArrayDot[{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},ArrayDot[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{2,1}}],{{1,2}}],Cycles[{{1,2}}]]
​
Method-string shortcuts produce the path via GreedyContractionPath, OptimalContractionPath, or one of the cost variants:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,"Greedy"]
Out[2]=
ArrayDot[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},ArrayDot[{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},{{2,1}}],{{2,1}}]
​
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,"flops"]
Out[2]=
ArrayDot[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},ArrayDot[{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},{{2,1}}],{{2,1}}]
​
The five engines produce structurally distinct trees for the same path:
ArrayDot (default) emits the index-aware Inactive[ArrayDot] primitive:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,{{1,2},{1,2}},Method"ArrayDot"]
Out[2]=
Transpose[ArrayDot[{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},ArrayDot[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{2,1}}],{{1,2}}],Cycles[{{1,2}}]]
​
ArrayDotTranspose introduces explicit Inactive[Transpose] reshuffles around each ArrayDot:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,{{1,2},{1,2}},Method"ArrayDotTranspose"]
Out[2]=
Transpose[ArrayDot[Transpose[{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},Cycles[{{1,2}}]],Transpose[ArrayDot[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},1],Cycles[{{1,2}}]],1],Cycles[{{1,2}}]]
​
Dot reshapes operands to matrices and uses Inactive[Dot]:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,{{1,2},{1,2}},Method"Dot"]
Out[2]=
Transpose[Transpose[{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}},Cycles[{{1,2}}]].Transpose[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}}.{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},Cycles[{{1,2}}]],Cycles[{{1,2}}]]
​
TensorContract emits a TensorProduct wrapped in TensorContract:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,{{1,2},{1,2}},Method"TensorContract"]
Out[2]=
Transpose[TensorContract[{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}TensorContract[{{0.5,-0.2,0.3},{0.1,0.8,-0.4}}{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{2,3}}],{{1,4}}],Cycles[{{1,2}}]]
​
TableSum unrolls the contraction into explicit Table/Sum loops over formal indices:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​
TensorNetworkContraction
[tn,{{1,2},{1,2}},Method"TableSum"]
Out[2]=
TransposeTable
4
∑
c.1
{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}c.1,i.1Table
3
∑
c.1
{{0.5,-0.2,0.3},{0.1,0.8,-0.4}}i.1,c.1{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}}c.1,j.1,{i.1,2},j.1,4j.1,c.1,{i.1,2},j.1,2,Cycles[{{1,2}}]
​
All five engines yield the same numerical value after activation:
In[1]:=
tn=
TensorNetwork
[{{{0.5,-0.2,0.3},{0.1,0.8,-0.4}},{{0.6,0.4,-0.1,0.2},{-0.3,0.5,0.7,-0.2},{0.1,-0.4,0.3,0.5}},{{0.2,-0.3},{0.4,0.1},{-0.5,0.6},{0.3,-0.2}}},{{i,j},{j,k},{k,l}}];​​Equal@@
ActivateTensors

TensorNetworkContraction
[tn,{{1,2},{1,2}},Method#1]&/@$TensorNetworkContractionMethods
​
From a TensorNetwork object (the typical workflow):
​
From a tensor-network Graph:
​
From the low-level Association produced by TensorNetworkData on a binary network:
​
ContractionTree renders the contraction hierarchy of an inactive tree:
​
With "Labels"  "Dimensions" the tree shows the running shape at each node:
Construct a small two-tensor network used in the examples below:
Return the default inactive contraction expression:
Evaluate the tree with ActivateTensors:
The option "Inactive"  False evaluates the tree on the fly:

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com