TensorNetwork
Tenet.AbstractTensorNetwork Type
AbstractTensorNetworkAbstract 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:
indstensorssize
Tenet.TensorNetwork Type
TensorNetworkHypergraph of interconnected tensors, representing a multilinear equation aka Tensor Network. Vertices represent tensors and edges, tensor indices.
Base.append! Method
append!(tn::TensorNetwork, tensors::AbstractVecOrTuple{<:Tensor})Add a list of tensors to a TensorNetwork.
Base.collect Method
Base.collect(tn::AbstractTensorNetwork)Return a list of the Tensors in the TensorNetwork. It is equivalent to tensors(tn).
Base.conj Method
conj(tn::AbstractTensorNetwork)Return a copy of the AbstractTensorNetwork with all tensors conjugated.
Base.copy Method
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.
Base.delete! Method
delete!(tn::TensorNetwork, x)Like pop! but return the TensorNetwork instead.
Base.in Method
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.
Base.merge! Method
merge!(self::TensorNetwork, others::TensorNetwork...)
merge(self::TensorNetwork, others::TensorNetwork...)Fuse various TensorNetworks into one.
See also: append!.
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.
Base.push! Method
push!(tn::AbstractTensorNetwork, tensor::Tensor)Add a new tensor to the Tensor Network.
Base.rand Method
rand(TensorNetwork, n::Integer, regularity::Integer; out = 0, dim = 2:9, seed = nothing, globalind = false)Generate a random tensor network.
Arguments
nNumber of tensors.regularityAverage number of indices per tensor.outNumber of open indices.dimRange of dimension sizes.seedIf notnothing, seed random generator with this value.globalindAdd a global 'broadcast' dimension to every tensor.
Base.replace! Method
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.
Base.selectdim Method
selectdim(tn::AbstractTensorNetwork, index::Symbol, i)Return a copy of the AbstractTensorNetwork where index has been projected to dimension i.
Base.size Method
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].
Base.view Method
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.
EinExprs.einexpr Method
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
optimizerContraction path optimizer. CheckEinExprsdocumentation for more info.outputsIndices that won't be contracted. Defaults to open indices.kwargsOptions to be passed to the optimizer.
See also: contract.
EinExprs.inds Function
inds(tn::AbstractTensorNetwork, set = :all)Return the names of the indices in the AbstractTensorNetwork.
Keyword Arguments
set:all(default) All indices.:openIndices only mentioned in one tensor.:innerIndices mentioned at least twice.:hyperIndices mentioned at least in three tensors.:paralleltoIndices parallel toiin the graph (iincluded).
Tenet.arrays Method
arrays(tn::AbstractTensorNetwork; kwargs...)Return a list of the arrays of in the TensorNetwork. It is equivalent to parent.(tensors(tn; kwargs...)).
Tenet.contract! Method
contract!(tn::AbstractTensorNetwork, index)In-place contraction of tensors connected to index.
See also: contract.
Tenet.contract! Method
contract!(tn::AbstractTensorNetwork; path=einexpr(tn))Same as contract but in-place.
See also: einexpr.
Tenet.contract Method
contract(tn::AbstractTensorNetwork; path=einexpr(tn))Contract a AbstractTensorNetwork. If path is not specified, the contraction order will be computed by einexpr.
Tenet.fuse! Method
fuse!(tn::AbstractTensorNetwork, i::Symbol)Group indices parallel to i and reshape the tensors accordingly.
Tenet.ninds Method
ninds(tn::TensorNetwork; kwargs...)Return the number of indices in the TensorNetwork. It accepts the same keyword arguments as inds.
See also: ntensors
Tenet.ntensors Method
ntensors(tn::AbstractTensorNetwork)Return the number of tensors in the TensorNetwork. It accepts the same keyword arguments as tensors.
See also: ninds
Tenet.resetinds! Method
resetinds!(tn::AbstractTensorNetwork; init::Int=1)Rename all indices in the TensorNetwork to a new set of indices starting from initth Unicode character.
Tenet.slice! Method
slice!(tn::AbstractTensorNetwork, index::Symbol, i)In-place projection of index on dimension i.
Tenet.tensors Function
tensors(tn::AbstractTensorNetwork)Return a list of the Tensors in the AbstractTensorNetwork.
Implementation details
- As the tensors of a
AbstractTensorNetworkare stored as keys of the.tensormapdictionary and it usesobjectidas hash, order is not stable so it sorts for repeated evaluations.
DocumenterMermaid.MermaidScriptBlock([...])