Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ITensorNetworksTensorOperationsExt = "TensorOperations"
[compat]
Accessors = "0.1.42"
Adapt = "4"
DataGraphs = "0.4.1, 0.5"
DataGraphs = "0.6"
Dictionaries = "0.4"
DocStringExtensions = "0.9"
Graphs = "1.8"
Expand All @@ -51,7 +51,7 @@ IsApprox = "0.1, 1, 2"
KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10"
MacroTools = "0.5"
NDTensors = "0.3, 0.4"
NamedGraphs = "0.11.1, 0.12, 0.13"
NamedGraphs = "0.14"
OMEinsumContractionOrders = "0.8.3, 0.9, 1"
SimpleTraits = "0.9"
SplitApplyCombine = "1.2"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ ITensorFormatter = "0.2.27"
ITensorNetworks = "0.23"
ITensors = "0.9"
Literate = "2.20.1"
NamedGraphs = "0.11, 0.12, 0.13"
NamedGraphs = "0.14"
OMEinsumContractionOrders = "1.2.2"
TensorOperations = "5.5"
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ makedocs(;
"Deprecated Methods" => "deprecated_methods.md",
],
"API Reference" => "reference.md",
"Changelog" => "changelog.md",
]
)

Expand Down
15 changes: 15 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## [0.23.0](https://github.com/ITensor/ITensorNetworks.jl/compare/v0.22.0...main) - Unreleased

### Breaking changes

- Requires NamedGraphs v0.14. The network types here are `AbstractNamedGraph`
subtypes, so its breaking changes carry through to them, including the output
types of `vertices` and `edges` and the return values of the mutating
functions. See the
[NamedGraphs changelog](https://itensor.github.io/NamedGraphs.jl/stable/changelog/)
([#384](https://github.com/ITensor/ITensorNetworks.jl/pull/384)).
- The leaf type of a contraction sequence is `ITensorNetworks.Key`, where it was
`NamedGraphs.Keys.Key`
([#384](https://github.com/ITensor/ITensorNetworks.jl/pull/384)).
3 changes: 1 addition & 2 deletions docs/src/computing_properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ using ITensorNetworks:
ITensorNetwork, TreeTensorNetwork, expect, inner, loginner, normalize, siteinds
using ITensors: Index, random_itensor
using LinearAlgebra: norm
using NamedGraphs.GraphsExtensions: incident_edges
using NamedGraphs.NamedGraphGenerators: named_grid
using NamedGraphs: incident_edges, named_grid

function random_state(g, s; link_space)
l = Dict(e => Index(link_space, "Link") for e in edges(g))
Expand Down
2 changes: 1 addition & 1 deletion docs/src/developer_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
* Tree-traversal sequence: cover `g` with a forest, then for each tree push a post-order
DFS sweep followed by its reverse — gives a back-and-forth sequence covering every edge (`edge_sequences.jl`):
```julia
edge_sequence(::Algorithm"forest_cover", g; root_vertex = GraphsExtensions.default_root_vertex)
edge_sequence(::Algorithm"forest_cover", g; root_vertex = default_root_vertex)
```

* Parallel sequence: each edge (and its reverse) as its own one-edge group, suitable
Expand Down
4 changes: 2 additions & 2 deletions docs/src/experimental_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ Methods which still need to be discussed, modified, or deprecated.
* Sweep-based truncation. The whole-TTN form orthogonalizes towards `src(e)` before
each bond truncation; the edge form lifts `truncate` from the underlying `ITensorNetwork` (`treetensornetworks/abstracttreetensornetwork.jl`):
```julia
truncate(tn::AbstractTTN; root_vertex = GraphsExtensions.default_root_vertex(tn), kwargs...)
truncate(tn::AbstractTTN; root_vertex = default_root_vertex(tn), kwargs...)
truncate(tn::AbstractTTN, edge::AbstractEdge; kwargs...)
```

* Contract the whole tree into a single `ITensor` via a reverse post-order DFS sequence (`treetensornetworks/abstracttreetensornetwork.jl`):
```julia
contract(tn::AbstractTTN, root_vertex = GraphsExtensions.default_root_vertex(tn); kwargs...)
contract(tn::AbstractTTN, root_vertex = default_root_vertex(tn); kwargs...)
```

* Inner product `⟨x|y⟩`, matrix element `⟨y|A|x⟩`, and four-network form `⟨B|y|A|x⟩`,
Expand Down
5 changes: 2 additions & 3 deletions docs/src/itensor_networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ indices:
using Graphs: edges, ne, neighbors, nv, vertices
using ITensorNetworks: ITensorNetwork, add, linkinds, siteinds
using ITensors: Index, ITensor
using NamedGraphs.NamedGraphGenerators: named_grid
using NamedGraphs: named_grid

i, j, k = Index(2, "i"), Index(2, "j"), Index(2, "k")
A, B, C = ITensor(i, j), ITensor(j, k), ITensor(k)
Expand All @@ -39,8 +39,7 @@ indices on each edge, build the indices once per edge and reuse them at both end

```@example main
using ITensors: random_itensor
using NamedGraphs: NamedGraph
using NamedGraphs.GraphsExtensions: edgetype, incident_edges
using NamedGraphs: NamedGraph, edgetype, incident_edges

g = NamedGraph(named_grid((3, 3)))
s = siteinds("S=1/2", g) # one spin-½ site Index per vertex
Expand Down
3 changes: 1 addition & 2 deletions docs/src/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ using Graphs: vertices
using ITensorNetworks:
ITensorNetwork, TreeTensorNetwork, dmrg, dst, edges, normalize, siteinds, src
using ITensors: Index, OpSum, random_itensor
using NamedGraphs.GraphsExtensions: incident_edges
using NamedGraphs.NamedGraphGenerators: named_comb_tree
using NamedGraphs: incident_edges, named_comb_tree

function random_state(g, s; link_space)
l = Dict(e => Index(link_space, "Link") for e in edges(g))
Expand Down
4 changes: 1 addition & 3 deletions docs/src/tree_tensor_networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ using ITensorNetworks: ITensorNetwork, TreeTensorNetwork, ortho_region, orthogon
siteinds
using ITensors: ITensors, Index, random_itensor
using LinearAlgebra: norm
using NamedGraphs: NamedGraph
using NamedGraphs.GraphsExtensions: incident_edges
using NamedGraphs.NamedGraphGenerators: named_comb_tree
using NamedGraphs: NamedGraph, incident_edges, named_comb_tree

# Comb-tree TTN (a popular tree topology for 2D-like systems)
g = NamedGraph(named_comb_tree((3, 2)))
Expand Down
6 changes: 2 additions & 4 deletions src/abstractindsnetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ using DataGraphs: DataGraphs, AbstractDataGraph, DataGraph, IsUnderlyingGraph, e
set_edge_data!, set_vertex_data!, underlying_graph_type, vertex_data
using Graphs: Graphs, AbstractEdge
using ITensors: ITensors, Index, unioninds
using NamedGraphs.GraphsExtensions:
GraphsExtensions, directed_graph, incident_edges, rename_vertices
using NamedGraphs: NamedGraphs
using NamedGraphs: NamedGraphs, directed_graph, incident_edges, rename_vertices

abstract type AbstractIndsNetwork{V, I} <: AbstractDataGraph{V, Vector{I}, Vector{I}} end

Expand All @@ -14,7 +12,7 @@ data_graph(graph::AbstractIndsNetwork) = not_implemented()

# Overload if needed
Graphs.is_directed(::Type{<:AbstractIndsNetwork}) = false
GraphsExtensions.directed_graph(is::AbstractIndsNetwork) = directed_graph(data_graph(is))
NamedGraphs.directed_graph(is::AbstractIndsNetwork) = directed_graph(data_graph(is))

# AbstractDataGraphs overloads
DataGraphs.underlying_graph(is::AbstractIndsNetwork) = underlying_graph(data_graph(is))
Expand Down
20 changes: 6 additions & 14 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ using DataGraphs:
DataGraphs, set_vertex_data!, underlying_graph, underlying_graph_type, vertex_data
using Dictionaries: Dictionaries, Dictionary
using Graphs: Graphs, Graph, add_edge!, add_vertex!, bfs_tree, center, dst, edges, edgetype,
has_edge, ne, neighbors, rem_edge!, src, vertices
has_edge, ne, neighbors, rem_edge!, src, steiner_tree, vertices
using ITensors: ITensors, ITensor, Index, addtags, commoninds, commontags, contract, dag,
inds, noprime, onehot, prime, replaceprime, replacetags, setprime, settags, sim,
swaptags, tags
using LinearAlgebra: LinearAlgebra, qr, qr!
using NDTensors: NDTensors, Algorithm, dim, scalartype
using NamedGraphs.GraphsExtensions:
add_edges, directed_graph, incident_edges, rename_vertices, vertextype, ⊔
using NamedGraphs: NamedGraphs, NamedGraph, Vertices, not_implemented, steiner_tree
using NamedGraphs: NamedGraphs, NamedGraph, add_edges, directed_graph, incident_edges,
not_implemented, rename_vertices, vertextype, ⊔
using SplitApplyCombine: flatten

abstract type AbstractITensorNetwork{V} <: AbstractDataGraph{V, ITensor, ITensor} end
Expand Down Expand Up @@ -56,7 +55,7 @@ Base.eltype(tn::AbstractITensorNetwork) = eltype(vertex_data(tn))

# Overload if needed
Graphs.is_directed(::Type{<:AbstractITensorNetwork}) = false
function GraphsExtensions.directed_graph(tn::AbstractITensorNetwork)
function NamedGraphs.directed_graph(tn::AbstractITensorNetwork)
return directed_graph(underlying_graph(tn))
end

Expand All @@ -75,13 +74,6 @@ DataGraphs.is_edge_assigned(::AbstractITensorNetwork, _) = false

DataGraphs.get_vertex_data(tn::AbstractITensorNetwork, v) = vertex_data(tn)[v]

function NamedGraphs.vertex_positions(tn::AbstractITensorNetwork)
return NamedGraphs.vertex_positions(underlying_graph(tn))
end
function NamedGraphs.ordered_vertices(tn::AbstractITensorNetwork)
return NamedGraphs.ordered_vertices(underlying_graph(tn))
end

function Adapt.adapt_structure(to, tn::AbstractITensorNetwork)
return map(adapt(to), tn)
end
Expand Down Expand Up @@ -623,15 +615,15 @@ function add(tn1::AbstractITensorNetwork, tn2::AbstractITensorNetwork)
length(linkinds(tn2, e)) > 1 && qr!(tn2, e)
end

edges_tn1, edges_tn2 = edges(tn1), edges(tn2)
edges_tn1, edges_tn2 = collect(edges(tn1)), collect(edges(tn2))

if !issetequal(edges_tn1, edges_tn2)
new_edges = union(edges_tn1, edges_tn2)
tn1 = add_edges(tn1, new_edges)
tn2 = add_edges(tn2, new_edges)
end

edges_tn1, edges_tn2 = edges(tn1), edges(tn2)
edges_tn1, edges_tn2 = collect(edges(tn1)), collect(edges(tn2))
@assert issetequal(edges_tn1, edges_tn2)

tn12 = copy(tn1)
Expand Down
6 changes: 2 additions & 4 deletions src/caches/abstractbeliefpropagationcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ using Graphs: Graphs, IsDirected, dst, src
using ITensors: dir
using LinearAlgebra: diag, dot
using NDTensors: NDTensors
using NamedGraphs.GraphsExtensions: subgraph
using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionedGraphs, QuotientEdge,
QuotientVertex, boundary_quotientedges, quotientedges, quotientvertices,
unpartitioned_graph
using NamedGraphs.SimilarType: SimilarType
using NamedGraphs: to_graph_index
using NamedGraphs: NamedGraphs, subgraph, to_graph_index
using SimpleTraits: SimpleTraits, @traitfn, Not
using SplitApplyCombine: group

abstract type AbstractBeliefPropagationCache{V, PV} <: AbstractITensorNetwork{V} end

function SimilarType.similar_type(bpc::AbstractBeliefPropagationCache)
function NamedGraphs.similar_type(bpc::AbstractBeliefPropagationCache)
return typeof(tensornetwork(bpc))
end

Expand Down
9 changes: 5 additions & 4 deletions src/contract.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using ITensors.NDTensors: @Algorithm_str, Algorithm, NDTensors, contract
using ITensors: ITensor, scalar
using LinearAlgebra: normalize!
using NamedGraphs.OrdinalIndexing: th
using NamedGraphs: NamedGraphs
using NamedGraphs: decoded_vertex, encoded_vertex, to_graph_index

function NDTensors.contract(tn::AbstractITensorNetwork; alg = "exact", kwargs...)
return contract(Algorithm(alg), tn; kwargs...)
Expand All @@ -15,8 +14,10 @@ function NDTensors.contract(
sequence = contraction_sequence(tn; contraction_sequence_kwargs...),
kwargs...
)
sequence_linear_index = deepmap(v -> NamedGraphs.vertex_positions(tn)[v], sequence)
ts = map(v -> tn[v], (1:nv(tn))th)
sequence_linear_index = deepmap(
v -> encoded_vertex(tn, to_graph_index(tn, v)), sequence
)
ts = map(code -> tn[decoded_vertex(tn, code)], 1:nv(tn))
return contract(ts; sequence = sequence_linear_index, kwargs...)
end

Expand Down
25 changes: 19 additions & 6 deletions src/contraction_sequences.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
using Graphs: vertices
using Graphs: nv, vertices
using ITensors.NDTensors: @Algorithm_str, Algorithm
using ITensors: ITensor
using NamedGraphs.Keys: Key
using NamedGraphs.OrdinalIndexing: th
using NamedGraphs: NamedGraphs, decoded_vertex

# A key (index) type, used for unambiguously identifying an object as a key or
# index of an indexable object rather than as a container to descend into. That
# distinction matters for the nested structure of a contraction sequence, whose
# leaves are vertices that may themselves be containers:
#
# [Key([1, 2]), [Key([3, 4]), Key([5, 6])]]
struct Key{K}
I::K
end
Key(I...) = Key(I)

Base.show(io::IO, I::Key) = print(io, "Key(", I.I, ")")

NamedGraphs.to_graph_index(graph, key::Key) = key.I

const ITensorList = Union{Vector{ITensor}, Tuple{Vararg{ITensor}}}

Expand All @@ -24,9 +38,8 @@ function deepmap(f, tree; filter = (x -> x isa AbstractArray))
end

function contraction_sequence(tn::AbstractITensorNetwork; kwargs...)
# TODO: Use `token_vertex` and/or `token_vertices` here.
ts = map(v -> tn[v], (1:nv(tn))th)
ts = map(code -> tn[decoded_vertex(tn, code)], 1:nv(tn))
seq_linear_index = contraction_sequence(ts; kwargs...)
# TODO: Use `Functors.fmap` or `StructWalk`?
return deepmap(n -> Key(vertices(tn)[n * th]), seq_linear_index)
return deepmap(code -> Key(decoded_vertex(tn, code)), seq_linear_index)
end
10 changes: 5 additions & 5 deletions src/edge_sequences.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Graphs: IsDirected, connected_components, edges, edgetype
using ITensors.NDTensors: @Algorithm_str, Algorithm
using NamedGraphs.GraphsExtensions:
GraphsExtensions, forest_cover, subgraph, undirected_graph
using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientEdge, quotient_graph
using NamedGraphs: NamedGraphs
using NamedGraphs:
NamedGraphs, default_root_vertex, forest_cover, subgraph, undirected_graph
using SimpleTraits: SimpleTraits, @traitfn, Not

default_edge_sequence_alg() = "forest_cover"
Expand Down Expand Up @@ -32,7 +31,7 @@ end
@traitfn function edge_sequence(
::Algorithm"forest_cover",
g::::(!IsDirected);
root_vertex = GraphsExtensions.default_root_vertex
root_vertex = default_root_vertex
)
forests = forest_cover(g)
edges = edgetype(g)[]
Expand All @@ -47,5 +46,6 @@ end
end

@traitfn function edge_sequence(::Algorithm"parallel", g::::(!IsDirected))
return [[e] for e in vcat(edges(g), reverse.(edges(g)))]
es = collect(edges(g))
return [[e] for e in vcat(es, reverse.(es))]
end
8 changes: 4 additions & 4 deletions src/formnetworks/abstractformnetwork.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DataGraphs: DataGraphs, underlying_graph, vertex_data
using Graphs: induced_subgraph
using NamedGraphs.SimilarType: SimilarType
using NamedGraphs: NamedGraphs

default_bra_vertex_suffix() = "bra"
default_ket_vertex_suffix() = "ket"
Expand All @@ -10,18 +10,18 @@ abstract type AbstractFormNetwork{V} <: AbstractITensorNetwork{V} end

#Needed for interface
dual_index_map(f::AbstractFormNetwork) = not_implemented()
# TODO: Use `NamedGraphs.GraphsExtensions.parent_graph`.
# TODO: Use `NamedGraphs.parent_graph`.
tensornetwork(f::AbstractFormNetwork) = not_implemented()
Base.copy(f::AbstractFormNetwork) = not_implemented()
operator_vertex_suffix(f::AbstractFormNetwork) = not_implemented()
bra_vertex_suffix(f::AbstractFormNetwork) = not_implemented()
ket_vertex_suffix(f::AbstractFormNetwork) = not_implemented()

function SimilarType.similar_type(f::AbstractFormNetwork)
function NamedGraphs.similar_type(f::AbstractFormNetwork)
return typeof(tensornetwork(f))
end

# TODO: Use `NamedGraphs.GraphsExtensions.parent_graph` / `parent_graph_type`.
# TODO: Use `NamedGraphs.parent_graph` / `parent_graph_type`.
DataGraphs.underlying_graph(f::AbstractFormNetwork) = underlying_graph(tensornetwork(f))
DataGraphs.vertex_data(f::AbstractFormNetwork) = vertex_data(tensornetwork(f))

Expand Down
4 changes: 2 additions & 2 deletions src/formnetworks/bilinearformnetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Adapt: adapt
using DataGraphs: DataGraphs, set_vertex_data!
using ITensors.NDTensors: datatype, denseblocks
using ITensors: ITensor, Index, Op, dag, delta, prime, sim
using NamedGraphs.GraphsExtensions: disjoint_union
using NamedGraphs: disjoint_union

default_dual_site_index_map = prime
default_dual_link_index_map = sim
Expand Down Expand Up @@ -44,7 +44,7 @@ end
operator_vertex_suffix(blf::BilinearFormNetwork) = blf.operator_vertex_suffix
bra_vertex_suffix(blf::BilinearFormNetwork) = blf.bra_vertex_suffix
ket_vertex_suffix(blf::BilinearFormNetwork) = blf.ket_vertex_suffix
# TODO: Use `NamedGraphs.GraphsExtensions.parent_graph`.
# TODO: Use `NamedGraphs.parent_graph`.
tensornetwork(blf::BilinearFormNetwork) = blf.tensornetwork

# Forward vertex writes to the wrapped network so reverse-index map and
Expand Down
4 changes: 2 additions & 2 deletions src/formnetworks/linearformnetwork.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DataGraphs: DataGraphs, set_vertex_data!
using ITensors: ITensor, dag, prime
using NamedGraphs.GraphsExtensions: disjoint_union
using NamedGraphs: disjoint_union

default_dual_link_index_map = prime

Expand Down Expand Up @@ -36,7 +36,7 @@ end

bra_vertex_suffix(lf::LinearFormNetwork) = lf.bra_vertex_suffix
ket_vertex_suffix(lf::LinearFormNetwork) = lf.ket_vertex_suffix
# TODO: Use `NamedGraphs.GraphsExtensions.parent_graph`.
# TODO: Use `NamedGraphs.parent_graph`.
tensornetwork(lf::LinearFormNetwork) = lf.tensornetwork

# Forward vertex writes to the wrapped network so reverse-index map and
Expand Down
5 changes: 2 additions & 3 deletions src/indsnetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ using Dictionaries: AbstractDictionary, Dictionary, Indices
using Graphs.SimpleGraphs: AbstractSimpleGraph
using Graphs: Graphs
using ITensors: Index, QN, dag
using NamedGraphs.GraphsExtensions: vertextype
using NamedGraphs.NamedGraphGenerators: named_path_graph
using NamedGraphs: NamedGraphs, AbstractNamedGraph, NamedEdge, NamedGraph
using NamedGraphs:
NamedGraphs, AbstractNamedGraph, NamedEdge, NamedGraph, named_path_graph, vertextype
using SimpleTraits: SimpleTraits, @traitfn, Not

# Spaces accepted by `Index`: a plain `Integer` dimension (dense) or a QN-block
Expand Down
Loading
Loading