Skip to content

TensorNetwork

Tenet.AbstractTensorNetwork Type
julia
AbstractTensorNetwork

Abstract type for TensorNetwork-derived types. Its subtypes must implement conversion or extraction of the underlying TensorNetwork by overloading the TensorNetwork constructor.

Implementors interface

Any implementor of the AbstractTensorNetwork interface (currently only TensorNetwork) must define the following methods:

  • inds

  • tensors

  • size

source

Tenet.TensorNetwork Type
julia
TensorNetwork

Hypergraph of interconnected tensors, representing a multilinear equation aka Tensor Network. Vertices represent tensors and edges, tensor indices.

source

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

Add a list of tensors to a TensorNetwork.

See also: push!, merge!.

source

Base.collect Method
julia
Base.collect(tn::AbstractTensorNetwork)

Return a list of the Tensors in the TensorNetwork. It is equivalent to tensors(tn).

source

Base.conj Method
julia
conj(tn::AbstractTensorNetwork)

Return a copy of the AbstractTensorNetwork with all tensors conjugated.

source

Base.copy Method
julia
copy(tn::TensorNetwork)

Return a shallow copy of a TensorNetwork; i.e. changes to the copied TensorNetwork won't affect the original one, but changes to the tensors will.

source

Base.delete! Method
julia
delete!(tn::TensorNetwork, x)

Like pop! but return the TensorNetwork instead.

source

Base.in Method
julia
in(tensor::Tensor, tn::TensorNetwork)
in(index::Symbol, tn::TensorNetwork)

Return true if there is a Tensor in tn for which == evaluates to true. This method is equivalent to tensor ∈ tensors(tn) code, but it's faster on large amount of tensors.

source

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

Fuse various TensorNetworks into one.

See also: append!.

source

Base.pop! Method
julia
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

Base.push! Method
julia
push!(tn::AbstractTensorNetwork, tensor::Tensor)

Add a new tensor to the Tensor Network.

See also: append!, pop!.

source

Base.rand Method
julia
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

Base.replace! Method
julia
replace!(tn::AbstractTensorNetwork, old => new...)
replace(tn::AbstractTensorNetwork, 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

Base.selectdim Method
julia
selectdim(tn::AbstractTensorNetwork, index::Symbol, i)

Return a copy of the AbstractTensorNetwork where index has been projected to dimension i.

See also: view, slice!.

source

Base.size Method
julia
size(tn::AbstractTensorNetwork)
size(tn::AbstractTensorNetwork, 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

Base.view Method
julia
view(tn::AbstractTensorNetwork, index => i...)

Return a copy of the AbstractTensorNetwork where each index has been projected to dimension i. It is equivalent to a recursive call of selectdim.

See also: selectdim, slice!.

source

EinExprs.einexpr Method
julia
einexpr(tn::AbstractTensorNetwork; optimizer = EinExprs.Greedy, output = inds(tn, :open), kwargs...)

Search a contraction path for the given AbstractTensorNetwork and return it as a EinExpr.

Keyword Arguments

  • optimizer Contraction path optimizer. Check EinExprs documentation for more info.

  • outputs Indices that won't be contracted. Defaults to open indices.

  • kwargs Options to be passed to the optimizer.

See also: contract.

source

EinExprs.inds Function
julia
inds(tn::AbstractTensorNetwork, set = :all)

Return the names of the indices in the AbstractTensorNetwork.

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

Tenet.arrays Method
julia
arrays(tn::AbstractTensorNetwork; kwargs...)

Return a list of the arrays of in the TensorNetwork. It is equivalent to parent.(tensors(tn; kwargs...)).

source

Tenet.contract! Method
julia
contract!(tn::AbstractTensorNetwork, index)

In-place contraction of tensors connected to index.

See also: contract.

source

Tenet.contract! Method
julia
contract!(tn::AbstractTensorNetwork; path=einexpr(tn))

Same as contract but in-place.

See also: einexpr.

source

Tenet.contract Method
julia
contract(tn::AbstractTensorNetwork; path=einexpr(tn))

Contract a AbstractTensorNetwork. If path is not specified, the contraction order will be computed by einexpr.

See also: einexpr, contract!.

source

Tenet.fuse! Method
julia
fuse!(tn::AbstractTensorNetwork, i::Symbol)

Group indices parallel to i and reshape the tensors accordingly.

source

Tenet.ninds Method
julia
ninds(tn::TensorNetwork; kwargs...)

Return the number of indices in the TensorNetwork. It accepts the same keyword arguments as inds.

See also: ntensors

source

Tenet.ntensors Method
julia
ntensors(tn::AbstractTensorNetwork)

Return the number of tensors in the TensorNetwork. It accepts the same keyword arguments as tensors.

See also: ninds

source

Tenet.resetinds! Method
julia
resetinds!(tn::AbstractTensorNetwork; init::Int=1)

Rename all indices in the TensorNetwork to a new set of indices starting from initth Unicode character.

source

Tenet.slice! Method
julia
slice!(tn::AbstractTensorNetwork, index::Symbol, i)

In-place projection of index on dimension i.

See also: selectdim, view.

source

Tenet.tensors Function
julia
tensors(tn::AbstractTensorNetwork)

Return a list of the Tensors in the AbstractTensorNetwork.

Implementation details

  • As the tensors of a AbstractTensorNetwork 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

DocumenterMermaid.MermaidScriptBlock([...])

Made with DocumenterVitepress.jl