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
The graph's nodes represent tensors and edges represent tensor indices.
In Tenet
, these objects are represented by the TensorNetwork
type.
Tenet.TensorNetwork
— TypeTensorNetwork
Graph of interconnected tensors, representing a multilinear equation. Graph vertices represent tensors and graph edges, tensor indices.
Information about a TensorNetwork
can be queried with the following functions.
Query information
EinExprs.inds
— Methodinds(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 toi
in the graph (i
included).
Base.size
— Methodsize(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]
.
Tenet.tensors
— Methodtensors(tn::TensorNetwork)
Return a list of the Tensor
s in the TensorNetwork
.
Implementation details
- As the tensors of a
TensorNetwork
are stored as keys of the.tensormap
dictionary and it usesobjectid
as hash, order is not stable so it sorts for repeated evaluations.
Modification
Add/Remove tensors
Base.push!
— Methodpush!(tn::TensorNetwork, tensor::Tensor)
Add a new tensor
to the Tensor Network.
Base.append!
— Methodappend!(tn::TensorNetwork, tensors::AbstractVecOrTuple{<:Tensor})
Add a list of tensors to a TensorNetwork
.
Base.merge!
— Methodmerge!(self::TensorNetwork, others::TensorNetwork...)
merge(self::TensorNetwork, others::TensorNetwork...)
Fuse various TensorNetwork
s into one.
See also: append!
.
Base.pop!
— Methodpop!(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.delete!
— Methoddelete!(tn::TensorNetwork, x)
Like pop!
but return the TensorNetwork
instead.
Replace existing elements
Base.replace!
— Functionreplace!(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
Symbol
s, it will correspond to a index renaming. - If
Tensor
s, first element that satisfies egality (≡
or===
) will be replaced.
Slicing
Base.selectdim
— Functionselectdim(tn::TensorNetwork, index::Symbol, i)
Return a copy of the TensorNetwork
where index
has been projected to dimension i
.
Tenet.slice!
— Functionslice!(tn::TensorNetwork, index::Symbol, i)
In-place projection of index
on dimension i
.
Base.view
— Methodview(tn::TensorNetwork, index => i...)
Return a copy of the TensorNetwork
where each index
has been projected to dimension i
. It is equivalent to a recursive call of selectdim
.
Miscelaneous
Base.copy
— Methodcopy(tn::TensorNetwork)
Return a shallow copy of a TensorNetwork
.
Base.rand
— Methodrand(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.