Tensor Networks

Tensor Networks (TN) are a graphical notation for representing complex multi-linear functions. For example, the following equation

\[\sum_{ijklmnop} A_{im} B_{ijp} C_{njk} D_{pkl} E_{mno} F_{ol}\]

can be represented visually as

Sketch of a Tensor Network
Sketch of a Tensor Network

The graph's nodes represent tensors and edges represent tensor indices.

In Tenet, these objects are represented by the TensorNetwork type.

Tenet.TensorNetworkType
TensorNetwork

Graph of interconnected tensors, representing a multilinear equation. Graph vertices represent tensors and graph edges, tensor indices.

source

Information about a TensorNetwork can be queried with the following functions.

Query information

EinExprs.indsMethod
inds(tn::TensorNetwork, set = :all)

Return the names of the indices in the TensorNetwork.

Keyword Arguments

  • set

    • :all (default) All indices.
    • :open Indices only mentioned in one tensor.
    • :inner Indices mentioned at least twice.
    • :hyper Indices mentioned at least in three tensors.
    • :parallelto Indices parallel to i in the graph (i included).
source
Base.sizeMethod
size(tn::TensorNetwork)
size(tn::TensorNetwork, index)

Return a mapping from indices to their dimensionalities.

If index is set, return the dimensionality of index. This is equivalent to size(tn)[index].

source
Tenet.tensorsMethod
tensors(tn::TensorNetwork)

Return a list of the Tensors in the TensorNetwork.

Implementation details

  • As the tensors of a TensorNetwork are stored as keys of the .tensormap dictionary and it uses objectid as hash, order is not stable so it sorts for repeated evaluations.
source

Modification

Add/Remove tensors

Base.append!Method
append!(tn::TensorNetwork, tensors::AbstractVecOrTuple{<:Tensor})

Add a list of tensors to a TensorNetwork.

See also: push!, merge!.

source
Base.merge!Method
merge!(self::TensorNetwork, others::TensorNetwork...)
merge(self::TensorNetwork, others::TensorNetwork...)

Fuse various TensorNetworks into one.

See also: append!.

source
Base.pop!Method
pop!(tn::TensorNetwork, tensor::Tensor)
pop!(tn::TensorNetwork, i::Union{Symbol,AbstractVecOrTuple{Symbol}})

Remove a tensor from the Tensor Network and returns it. If a Tensor is passed, then the first tensor satisfies egality (i.e. or ===) will be removed. If a Symbol or a list of Symbols is passed, then remove and return the tensors that contain all the indices.

See also: push!, delete!.

source

Replace existing elements

Base.replace!Function
replace!(tn::TensorNetwork, old => new...)
replace(tn::TensorNetwork, old => new...)

Replace the element in old with the one in new. Depending on the types of old and new, the following behaviour is expected:

  • If Symbols, it will correspond to a index renaming.
  • If Tensors, first element that satisfies egality ( or ===) will be replaced.
source

Slicing

Miscelaneous

Base.randMethod
rand(TensorNetwork, n::Integer, regularity::Integer; out = 0, dim = 2:9, seed = nothing, globalind = false)

Generate a random tensor network.

Arguments

  • n Number of tensors.
  • regularity Average number of indices per tensor.
  • out Number of open indices.
  • dim Range of dimension sizes.
  • seed If not nothing, seed random generator with this value.
  • globalind Add a global 'broadcast' dimension to every tensor.
source