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
  • 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
  • SparseTensorNetwork
  • TableauColumns
  • TableauDimension
  • TableauRows
  • TableauShape
  • TableauSize
  • 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
Tensor Networks Overview
The Wolfram tensor-networks paclet represents networks as bundles of tensors with a list of hyperedges and computes contractions through a layered pipeline: constructors build a network, inspectors expose its index structure, transforms restructure it, path finders order the pairwise contractions, and an execution layer carries them out. This overview walks one running example
RandomTensorNetwork
through each tier so that the function names you will reach for in later tutorials sit on a single mental map.
In[16]:=
Needs["Wolfram`TensorNetworks`"]
1. Constructing a Network
The fundamental object is
TensorNetwork
[tensors, hyperedges], where tensors is a list of numeric arrays and hyperedges is a list of index lists, one per tensor. Each entry of a hyperedge is an integer label; labels that appear in two or more tensors are contracted indices, and labels that appear once are free. Here a rank-2, rank-3, and rank-2 tensor share four indices in a closed pattern with one free index:
In[17]:=
SeedRandom[42];​​t1=RandomReal[{-1,1},{2,3}];​​t2=RandomReal[{-1,1},{3,4,5}];​​t3=RandomReal[{-1,1},{4,5}];​​tn=
TensorNetwork
[{t1,t2,t3},{{1,2},{2,3,4},{3,4}}]
Out[21]=
TensorNetwork
Tensors: 3
Binary: Yes
Free indices: 1
Sparse: No
Output dimension: 2
​

Show corresponding hypergraph, with vertices as tensor indices and edges as tensors:
In[22]:=
tn["Hypergraph"]
Out[22]=
A second, idiomatic constructor builds families with known topology. Calling
RandomTensorNetwork
["MPS"[L, D, d]] returns a length-L matrix product state with bond dimension D and physical dimension d. The result is still a TensorNetwork expression – no specialized MPS type – so every tier below applies uniformly:
In[23]:=
SeedRandom[7];​​mps=
RandomTensorNetwork
["MPS"[6,4,2],Method"Complex"]
Out[24]=
TensorNetwork
Tensors: 6
Binary: Yes
Free indices: 6
Sparse: No
Output dimension: 64
​

Show its hypergraph:
In[25]:=
mps["Hypergraph"]
Out[25]=
2. Inspecting Structure
Networks support both functional accessors and a property-dispatch syntax. The keys "FreeIndices", "Bonds", and "BinaryQ" answer the three questions you ask first about any network: which indices remain after contraction, which pairs are joined and at what bond dimension, and whether every shared index touches exactly two tensors (the binary case, where the network reduces to a graph rather than a hypergraph).
In[26]:=
mps["FreeIndices"]
Out[26]=
{7,8,9,10,11,12}
The six free indices are the dangling "physical" legs of the chain. The bond list spells out the contracted edges and their dimensions:
In[27]:=
mps["Bonds"]
Out[27]=
{{
1
1
,
1
2
}4,{
2
2
,
2
3
}4,{
3
3
,
3
4
}4,{
4
4
,
4
5
}4,{
5
5
,
5
6
}4}
Each key on the left is a pair of index slots written as Superscript[tensor, position]; the right side is the bond dimension. Five edges of dimension 4 – one between every adjacent pair – confirm the chain topology. Asking "BinaryQ" verifies that no index lives in three or more tensors:
In[28]:=
mps["BinaryQ"]
Out[28]=
True
For a single Association of every cached structural property, call
TensorNetworkData
with no second argument:
In[29]:=
Keys
TensorNetworkData
[mps]
Out[29]=
{Tensors,Dimensions,Hyperedges,Indices,Vertices,Bonds,Contractions,ContractionIndices,FreeIndices}
3. Finding a Contraction Path
The cost of contracting a network depends drastically on the order in which pairs are merged. A path is a list of pairs {i, j} using the
OptimalContractionPath
convention: at each step the tensors in positions i and j are contracted, both are removed, and the result is appended to the end of the list.
OptimalContractionPath
runs a full search; with Method  "flops" it minimizes the total floating-point operation count rather than the default "size" objective:
In[30]:=
path=
OptimalContractionPath
[mps,Method"flops"]
Out[30]=
{{1,2},{1,5},{2,3},{1,3},{1,2}}
Exhaustive search becomes infeasible once the network grows beyond about a dozen tensors. For larger problems, reach for
GreedyContractionPath
, which picks the locally cheapest pair at every step:
In[31]:=
GreedyContractionPath
[mps]
Out[31]=
{{4,5},{4,5},{2,3},{1,3},{1,2}}
If you do not supply a path explicitly,
TensorNetworkContract
calls a planner of its own and uses the result. Passing an explicit path matters when you want reproducibility across runs, when the heuristic and the optimum diverge, or when you wish to time the search separately from the execution.
4. Contracting
Once a path is fixed, execution is one call.
TensorNetworkContract
carries out every pairwise contraction in order and returns a numerical array whose free indices match those of the input network:
In[32]:=
result=
TensorNetworkContract
[mps]
Out[32]=
{{{{{{4.55591-18.5257,7.99487-0.297649},{14.6886-5.03248,2.44838+2.2747}},{{-3.87191-12.9775,-2.59666+3.22489},{11.2872-4.24666,0.649444+1.22257}}},{{{7.78517+4.32165,-8.27917+5.00402},{4.24872-3.5752,-6.72314-1.96116}},{{18.2256+11.5789,4.09162-9.84496},{-3.16169+6.50297,15.4283+3.83903}}}},{{{{10.9613-2.45208,-4.29662+8.0546},{0.50225+0.85937,-1.72126+4.44787}},{{9.09725-5.23713,1.51309-5.92087},{3.31533-0.401529,-0.262081-1.39826}}},{{{2.68908+8.68634,0.656972-1.07961},{3.16575+10.9046,-0.0467431-0.830992}},{{-1.9322+6.92455,1.27659+0.770643},{-4.92042+6.64175,-2.01244+6.28902}}}}},{{{{{-7.07082-16.5578,-0.0140703-3.61301},{7.24983-18.2099,-0.807046+2.3774}},{{-5.68173-6.67014,4.81536+0.452678},{5.6817-12.9272,4.87108-1.37887}}},{{{1.01012+1.63054,3.2111+7.29551},{-3.38341+2.89056,-4.56769+4.28183}},{{10.3183-6.56745,-5.88143-5.91186},{-4.16213+6.85001,6.53907-7.72636}}}},{{{{-7.68228+4.77842,4.93256-0.721014},{-7.74975+6.8201,4.70083-3.25747}},{{-8.17318+3.40668,-4.83171+1.79426},{-7.70483+1.43303,-4.93935+2.23986}}},{{{4.48074-12.366,5.01763+0.91158},{11.7559-2.75617,-7.29354+5.0219}},{{5.44825-16.1657,-0.576388+2.88667},{9.48945-1.40311,5.04281-6.3379}}}}}}
The shape is informative: six dangling indices, each of physical dimension 2, give a rank-6 array which is the unnormalized state vector
ψ
s
1
s
2
s
3
s
4
s
5
s
6
of the spin chain encoded by the MPS:
In[33]:=
Dimensions[result]
Out[33]=
{2,2,2,2,2,2}
Two siblings of
TensorNetworkContract
are worth knowing.
TensorNetworkContraction
returns an Inactive symbolic expression representing the planned contraction – handy for inspecting which sub-tensors will be built and in what order.
ActivateTensors
then evaluates that expression. The available execution back-ends are listed in
$TensorNetworkContractionMethods
.
5. Where to Go Next
Five sibling tutorials drill into the tiers sketched above.
Building Tensor Networks
catalogs the constructors \[Dash] PEPS, MERA, tree tensor networks, transforms like
BinaryTensorNetwork
and
SparseTensorNetwork
, and graph adapters via
ToTensorNetworkGraph
.
Contraction Paths and Execution
surveys the planner objectives ("size", "flops", "max", "write", "combo", "limit"), the path utilities
PathQ
,
CanonicalPath
, and
ContractionTree
, and the execution back-ends.
Matrix Product States
treats the algorithmic toolkit attached to one-dimensional networks. The two subpackage tutorials cover the named-index layer \[Dash]
Named Indices and Metrics
\[Dash] and the representation theory of permutation symmetry of tensors via
Young Tableaux and Tensor Symmetries
.
RelatedGuides
▪
TensorNetworks
RelatedTechNotes
▪
Building Tensor Networks
▪
Contraction Paths and Execution
▪
Matrix Product States
▪
Named Indices and Metrics
▪
Young Tableaux and Tensor Symmetries
""

© 2026 Wolfram. All rights reserved.

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