TensorNetwork
Tenet.AbstractTensorNetwork Type
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
Tenet.TensorNetwork Type
TensorNetwork
Hypergraph 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 Tensor
s 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 TensorNetwork
s 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 Symbol
s 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
n
Number of tensors.regularity
Average number of indices per tensor.out
Number of open indices.dim
Range of dimension sizes.seed
If notnothing
, seed random generator with this value.globalind
Add 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
Symbol
s, it will correspond to a index renaming.If
Tensor
s, 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
optimizer
Contraction path optimizer. CheckEinExprs
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
.
EinExprs.inds Function
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 toi
in the graph (i
included).
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 init
th 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 Tensor
s in the AbstractTensorNetwork
.
Implementation details
- As the tensors of a
AbstractTensorNetwork
are stored as keys of the.tensormap
dictionary and it usesobjectid
as hash, order is not stable so it sorts for repeated evaluations.
DocumenterMermaid.MermaidScriptBlock([...])