11"""
22Generic tensor network data structure
33"""
4- mutable struct SimpleTensorNetwork <: AbstractDataGraph{Int,IndexedArray,IndexedArray}
4+ mutable struct TensorNetwork <: AbstractDataGraph{Int,IndexedArray,IndexedArray}
55 # data_graph: (undirected) graph of the tensor network
66 # An integer is assigned to each vertex (starting from 1 and increasing one by one).
77 # We can place an IndexedArray at each vertex of the graph, and an edge between two vertices.
88 # But, the latter is not supported by the current implementation of SimpleTensorNetworks.jl.
99 # This may be useful for supporting the Vidal notation.
1010 data_graph:: DataGraph{Int,IndexedArray,IndexedArray,NamedGraph{Int},NamedEdge{Int}}
1111
12- function SimpleTensorNetwork (
12+ function TensorNetwork (
1313 dg:: DataGraph{Int,IndexedArray,IndexedArray,NamedGraph{Int},NamedEdge{Int}} ,
1414 )
15- is_connected (dg) ||
16- error (" SimpleTensorNetwork is only supported for a connected graph." )
15+ is_connected (dg) || error (" TensorNetwork is only supported for a connected graph." )
1716 new (dg)
1817 end
1918end
2019
21- function SimpleTensorNetwork (ts:: AbstractVector{<:AbstractIndexedArray} )
20+ function TensorNetwork (ts:: AbstractVector{<:AbstractIndexedArray} )
2221 g = NamedGraph (collect (eachindex (ts)))
2322 dg = DataGraph {Int,IndexedArray,IndexedArray,NamedGraph{Int},NamedEdge{Int}} (g)
2423
@@ -32,34 +31,33 @@ function SimpleTensorNetwork(ts::AbstractVector{<:AbstractIndexedArray})
3231 end
3332 end
3433 end
35- tn = SimpleTensorNetwork (dg)
34+ tn = TensorNetwork (dg)
3635 return tn
3736end
3837
39- data_graph (tn:: SimpleTensorNetwork ) = getfield (tn, :data_graph )
40- data_graph_type (TN:: Type{<:SimpleTensorNetwork } ) = fieldtype (TN, :data_graph )
41- DataGraphs. underlying_graph (tn:: SimpleTensorNetwork ) = underlying_graph (data_graph (tn))
42- DataGraphs. underlying_graph_type (TN:: Type{<:SimpleTensorNetwork } ) =
38+ data_graph (tn:: TensorNetwork ) = getfield (tn, :data_graph )
39+ data_graph_type (TN:: Type{<:TensorNetwork } ) = fieldtype (TN, :data_graph )
40+ DataGraphs. underlying_graph (tn:: TensorNetwork ) = underlying_graph (data_graph (tn))
41+ DataGraphs. underlying_graph_type (TN:: Type{<:TensorNetwork } ) =
4342 fieldtype (data_graph_type (TN), :underlying_graph )
44- DataGraphs. vertex_data (graph:: SimpleTensorNetwork , args... ) =
43+ DataGraphs. vertex_data (graph:: TensorNetwork , args... ) =
4544 vertex_data (data_graph (graph), args... )
46- DataGraphs. edge_data (graph:: SimpleTensorNetwork , args... ) =
47- edge_data (data_graph (graph), args... )
45+ DataGraphs. edge_data (graph:: TensorNetwork , args... ) = edge_data (data_graph (graph), args... )
4846
49- function Base. setindex! (tn:: SimpleTensorNetwork , t:: AbstractIndexedArray , v:: Int )
47+ function Base. setindex! (tn:: TensorNetwork , t:: AbstractIndexedArray , v:: Int )
5048 tn. data_graph[v] = t
5149end
5250
53- Base. getindex (tn:: SimpleTensorNetwork , v:: Int ) = tn. data_graph[v]
51+ Base. getindex (tn:: TensorNetwork , v:: Int ) = tn. data_graph[v]
5452
5553"""
5654Return if a tensor network `tn` has a cycle. If it has not a cycle, `tn` is a tree tensor network.
5755"""
58- Graphs. is_cyclic (tn:: SimpleTensorNetwork ) =
56+ Graphs. is_cyclic (tn:: TensorNetwork ) =
5957 Graphs. is_cyclic (tn. data_graph. underlying_graph. position_graph)
6058
6159
62- Graphs. has_edge (tn:: SimpleTensorNetwork , e:: NamedEdge ) = Graphs. has_edge (tn. data_graph, e)
60+ Graphs. has_edge (tn:: TensorNetwork , e:: NamedEdge ) = Graphs. has_edge (tn. data_graph, e)
6361
6462"""
6563Contract all the tensors in a tensor network `tn` and return the result.
@@ -68,7 +66,7 @@ This function works only for tree tensor networks, i.e., `is_cyclic(tn) == false
6866
6967root_vertex: The vertex to start the contraction. The default is 1.
7068"""
71- function complete_contraction (tn:: SimpleTensorNetwork ; root_vertex:: Int = 1 )
69+ function complete_contraction (tn:: TensorNetwork ; root_vertex:: Int = 1 )
7270 ! Graphs. is_cyclic (tn) ||
7371 error (" complete_contraction is not supported only for a tree tensor network." )
7472 res = tn[root_vertex]
@@ -84,7 +82,7 @@ Contract all the tensors in a subtree of a tensor network `tn` and return the re
8482The subtree is defined by a vertex `v` and its parent vertex `parent_v`.
8583Note that `parent_v` is not included in the subtree.
8684"""
87- function _contract_subtree (tn:: SimpleTensorNetwork , v:: Int , parent_v:: Union{Int,Nothing} )
85+ function _contract_subtree (tn:: TensorNetwork , v:: Int , parent_v:: Union{Int,Nothing} )
8886 res = tn[v]
8987 for nv in neighbors (tn. data_graph, v)
9088 if nv != parent_v
0 commit comments