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`
OptimalContractionPath
​
OptimalContractionPath
[tn]
finds an optimal contraction path through the
TensorNetwork
tn
by dynamic-programming search.
​
​
OptimalContractionPath
[graph]
works directly on a tensor-network
Graph
graph
.
​
​
OptimalContractionPath
[data]
accepts the low-level
Association
data
with keys
"Dimensions"
,
"Indices"
, and
"Contractions"
.
​
​
OptimalContractionPath
[expr]
finds a path for an
Inactive
TensorContract
over a
TensorProduct
, optionally wrapped in
Transpose
with a
Cycles
permutation.
​
Details and Options
▪
Returns a canonical contraction path — a list of pairs {{i, j}, …} where each step removes the tensors at positions i and j from the working list and appends their pairwise contraction (the opt_einsum convention).
▪
The path is optimal under the chosen
Method
. Search uses dynamic programming and is exponential in the number of tensors in the worst case; use
GreedyContractionPath
for networks where exhaustive search is impractical.
▪
The default
Method
"size"
minimizes the size of the largest intermediate tensor produced during contraction.
▪
When the input has a hyper-edge (an index that appears in three or more tensors),
OptimalContractionPath
first applies
BinaryTensorNetwork
to insert copy tensors and reduce the network to pairwise edges before searching.
▪
The search backend is a Rust library function loaded from the
Wolfram/PacletExtensions
paclet; the library function is called
optimize_optimal
.
▪
The following options can be given:
Method
"size"
cost function:
"size"
,
"flops"
,
"max"
,
"write"
,
"combo"
, or
"limit"
.
"PruningThreshold"
None
prune search branches whose running cost exceeds this value.
"AllowOuterProducts"
None
when
True
, the search may pair tensors that share no index.
"PreSimplify"
None
when
True
, fuse duplicate indices and trivial dimensions before searching.
"FixedIndexing"
None
when
True
, use static single-assignment (SSA) index allocation.
​
Examples  
(26)
Basic Examples  
(4)
Find an optimal path for a small random tensor network. The default cost function is "size":
In[1]:=
tn=
RandomTensorNetwork
[{4,5},3];​​
OptimalContractionPath
[tn]
Out[1]=
{{2,3},{2,3},{1,2}}
​
Optimize for floating-point operations instead of largest intermediate-tensor size:
In[1]:=
tn=
RandomTensorNetwork
[{4,5},3];​​
OptimalContractionPath
[tn,Method"flops"]
Out[1]=
{{3,5},{2,4},{1,3},{1,2}}
​
Disallow outer-product pairs during the search:
In[1]:=
tn=
RandomTensorNetwork
[{4,5},3];​​
OptimalContractionPath
[tn,"AllowOuterProducts"False]
Out[1]=
{{2,3},{2,3},{1,2}}
​
Use the low-level Association form (dimensions, indices, contractions) for the same calculation:
In[1]:=
OptimalContractionPath
[Association["Dimensions"{{2,3},{3,4},{4,2}},"Indices"{{i,j},{j,k},{k,i}},"Contractions"{{{i,i}},{{j,j}},{{k,k}}}]]
Out[1]=
{{2,3},{1,2}}
Scope  
(12)

Options  
(5)

Applications  
(2)

Properties & Relations  
(3)

SeeAlso
GreedyContractionPath
 
▪
TensorNetworkContract
 
▪
TensorNetworkContraction
 
▪
CanonicalPath
 
▪
PathQ
 
▪
ContractionTree
 
▪
BinaryTensorNetwork
 
▪
TensorNetwork
 
▪
TensorContract
 
▪
TensorProduct
TechNotes
▪
Contraction Paths and Execution
RelatedGuides
▪
TensorNetworks
RelatedLinks
▪
opt_einsum dynamic-programming contraction-path algorithm
""

© 2026 Wolfram. All rights reserved.

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