Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to NamedGraphs 0.6 #163

Merged
merged 3 commits into from
Apr 26, 2024
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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensorNetworks"
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]
version = "0.10.0"
version = "0.10.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -49,7 +49,7 @@ ITensorNetworksOMEinsumContractionOrdersExt = "OMEinsumContractionOrders"
AbstractTrees = "0.4.4"
Combinatorics = "1"
Compat = "3, 4"
DataGraphs = "0.2.2"
DataGraphs = "0.2.3"
DataStructures = "0.18"
Dictionaries = "0.4"
Distributions = "0.25.86"
Expand All @@ -61,7 +61,7 @@ ITensors = "0.4"
IsApprox = "0.1"
IterTools = "1.4.0"
KrylovKit = "0.6, 0.7"
NamedGraphs = "0.5.1"
NamedGraphs = "0.6.0"
NDTensors = "0.3"
Observers = "0.2"
OMEinsumContractionOrders = "0.8.3"
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ julia> using ITensorNetworks: ITensorNetwork

julia> tn = ITensorNetwork(path_graph(4); link_space=2)
ITensorNetworks.ITensorNetwork{Int64} with 4 vertices:
4-element Dictionaries.Indices{Int64}
4-element NamedGraphs.OrderedDictionaries.OrderedIndices{Int64}
1
2
3
Expand Down Expand Up @@ -93,7 +93,7 @@ julia> using NamedGraphs.NamedGraphGenerators: named_grid

julia> tn = ITensorNetwork(named_grid((2, 2)); link_space=2)
ITensorNetworks.ITensorNetwork{Tuple{Int64, Int64}} with 4 vertices:
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
4-element NamedGraphs.OrderedDictionaries.OrderedIndices{Tuple{Int64, Int64}}
(1, 1)
(2, 1)
(1, 2)
Expand Down Expand Up @@ -128,7 +128,7 @@ julia> neighbors(tn, (1, 2))

julia> tn_1 = subgraph(v -> v[1] == 1, tn)
ITensorNetworks.ITensorNetwork{Tuple{Int64, Int64}} with 2 vertices:
2-element Dictionaries.Indices{Tuple{Int64, Int64}}
2-element NamedGraphs.OrderedDictionaries.OrderedIndices{Tuple{Int64, Int64}}
(1, 1)
(1, 2)

Expand All @@ -142,7 +142,7 @@ with vertex data:

julia> tn_2 = subgraph(v -> v[1] == 2, tn)
ITensorNetworks.ITensorNetwork{Tuple{Int64, Int64}} with 2 vertices:
2-element Dictionaries.Indices{Tuple{Int64, Int64}}
2-element NamedGraphs.OrderedDictionaries.OrderedIndices{Tuple{Int64, Int64}}
(2, 1)
(2, 2)

Expand All @@ -167,7 +167,7 @@ julia> using ITensorUnicodePlots: @visualize

julia> s = siteinds("S=1/2", named_grid(3))
ITensorNetworks.IndsNetwork{Int64, ITensors.Index} with 3 vertices:
3-element Dictionaries.Indices{Int64}
3-element NamedGraphs.OrderedDictionaries.OrderedIndices{Int64}
1
2
3
Expand All @@ -187,7 +187,7 @@ and edge data:

julia> tn1 = ITensorNetwork(s; link_space=2)
ITensorNetworks.ITensorNetwork{Int64} with 3 vertices:
3-element Dictionaries.Indices{Int64}
3-element NamedGraphs.OrderedDictionaries.OrderedIndices{Int64}
1
2
3
Expand All @@ -204,7 +204,7 @@ with vertex data:

julia> tn2 = ITensorNetwork(s; link_space=2)
ITensorNetworks.ITensorNetwork{Int64} with 3 vertices:
3-element Dictionaries.Indices{Int64}
3-element NamedGraphs.OrderedDictionaries.OrderedIndices{Int64}
1
2
3
Expand Down Expand Up @@ -305,20 +305,20 @@ julia> @visualize Z̃;
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Z̃(3, 1)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠁⠀⠀⠀⠉⠉⠑⠒⠒⠢⠤⠤⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈2⠉⠑⠒⠒⠤⠤⠤⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀(2)'⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Z̃(3, 2)⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠤⠊⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀2⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Z̃(2, 1)⠤⠤⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢣⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠑⠒2⠢⠤⠤⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣀⠔⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉Z̃(2, 2)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀2⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠤⠤⠒⠊⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡠⠤2⠒⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢱⠀⢀⣀⠤⠔⠒⠊⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀Z̃(1, 2)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Z̃(2, 1)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀(2)'⠤⠤⠔⠒⠒⠉⠉⠀⠀⢱⠀⠈⠉⠑⠒⠢⠤⢄⣀2⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠤⠔⠒⠊⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠒⠒⠤⠤⢄⣀⡀⠀⠀⠀⠀⠀
Z̃(3, 1)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Z̃(1, 2)⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠁⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀2⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠2⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀2⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⢀⠤⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Z̃(2, 2)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠸⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡠⠤⠒⠊⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠤2⠒⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡀⠀⣀⡠⠤⠒⠊⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀Z̃(3, 2)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Expand Down
11 changes: 5 additions & 6 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ using ITensors:
using ITensors.ITensorMPS: ITensorMPS, add, linkdim, linkinds, siteinds
using .ITensorsExtensions: ITensorsExtensions, indtype, promote_indtype
using LinearAlgebra: LinearAlgebra, factorize
using NamedGraphs:
NamedGraphs, NamedGraph, not_implemented, parent_vertex_to_vertex, vertex_to_parent_vertex
using NamedGraphs: NamedGraphs, NamedGraph, not_implemented
using NamedGraphs.GraphsExtensions:
⊔, directed_graph, incident_edges, rename_vertices, vertextype
using NDTensors: NDTensors, dim
Expand Down Expand Up @@ -94,11 +93,11 @@ function DataGraphs.edge_data(graph::AbstractITensorNetwork, args...)
end

DataGraphs.underlying_graph(tn::AbstractITensorNetwork) = underlying_graph(data_graph(tn))
function NamedGraphs.vertex_to_parent_vertex(tn::AbstractITensorNetwork, vertex)
return vertex_to_parent_vertex(underlying_graph(tn), vertex)
function NamedGraphs.vertex_positions(tn::AbstractITensorNetwork)
return NamedGraphs.vertex_positions(underlying_graph(tn))
end
function NamedGraphs.parent_vertex_to_vertex(tn::AbstractITensorNetwork, parent_vertex)
return parent_vertex_to_vertex(underlying_graph(tn), parent_vertex)
function NamedGraphs.ordered_vertices(tn::AbstractITensorNetwork)
return NamedGraphs.ordered_vertices(underlying_graph(tn))
end

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

function NDTensors.contract(tn::AbstractITensorNetwork; alg="exact", kwargs...)
return contract(Algorithm(alg), tn; kwargs...)
Expand All @@ -15,10 +16,8 @@ function NDTensors.contract(
sequence=contraction_sequence(tn; contraction_sequence_kwargs...),
kwargs...,
)
# TODO: Use `vertex`.
sequence_linear_index = deepmap(v -> vertex_to_parent_vertex(tn, v), sequence)
# TODO: Use `tokenized_vertex`.
ts = map(pv -> tn[parent_vertex_to_vertex(tn, pv)], 1:nv(tn))
sequence_linear_index = deepmap(v -> NamedGraphs.vertex_positions(tn)[v], sequence)
ts = map(v -> tn[v], (1:nv(tn))th)
return contract(ts; sequence=sequence_linear_index, kwargs...)
end

Expand Down
6 changes: 3 additions & 3 deletions src/contraction_sequences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ using Graphs: vertices
using ITensors: ITensor, contract
using ITensors.ContractionSequenceOptimization: deepmap, optimal_contraction_sequence
using ITensors.NDTensors: Algorithm, @Algorithm_str
using NamedGraphs: parent_vertex_to_vertex
using NamedGraphs.Keys: Key
using NamedGraphs.OrdinalIndexing: th

function contraction_sequence(tn::Vector{ITensor}; alg="optimal", kwargs...)
return contraction_sequence(Algorithm(alg), tn; kwargs...)
end

function contraction_sequence(tn::AbstractITensorNetwork; kwargs...)
# TODO: Use `token_vertex` and/or `token_vertices` here.
ts = map(pv -> tn[parent_vertex_to_vertex(tn, pv)], 1:nv(tn))
ts = map(v -> tn[v], (1:nv(tn))th)
seq_linear_index = contraction_sequence(ts; kwargs...)
# TODO: Use `Functors.fmap` or `StructWalk`?
return deepmap(n -> Key(parent_vertex_to_vertex(tn, n)), seq_linear_index)
return deepmap(n -> Key(vertices(tn)[n * th]), seq_linear_index)
end

function contraction_sequence(::Algorithm"optimal", tn::Vector{ITensor})
Expand Down
2 changes: 1 addition & 1 deletion src/treetensornetworks/projttns/projttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ProjTTN{V,Pos<:Union{Indices{V},NamedEdge{V}}} <: AbstractProjTTN{V}
environments::Dictionary{NamedEdge{V},ITensor}
end

function ProjTTN(pos::Vector, operator::TTN, environments::Dictionary)
function ProjTTN(pos, operator::TTN, environments::Dictionary)
return ProjTTN(Indices(pos), operator, environments)
end

Expand Down
2 changes: 1 addition & 1 deletion src/treetensornetworks/treetensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct TreeTensorNetwork{V} <: AbstractTreeTensorNetwork{V}
end
end

function _TreeTensorNetwork(tensornetwork::ITensorNetwork, ortho_region::Vector)
function _TreeTensorNetwork(tensornetwork::ITensorNetwork, ortho_region)
return _TreeTensorNetwork(tensornetwork, Indices(ortho_region))
end

Expand Down
19 changes: 12 additions & 7 deletions src/visualize.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# TODO: Move to `ITensorNetworksITensors.ITensorVisualizationCoreExt`.
using DataGraphs: AbstractDataGraph, underlying_graph
# TODO: Move to `NamedGraphsITensorVisualizationCoreExt`.
using Graphs: vertices
using ITensors.ITensorVisualizationCore: ITensorVisualizationCore, visualize
using NamedGraphs: AbstractNamedGraph, parent_graph

using NamedGraphs: NamedGraphs, AbstractNamedGraph
using ITensors.ITensorVisualizationCore: ITensorVisualizationCore
function ITensorVisualizationCore.visualize(
graph::AbstractNamedGraph,
args...;
Expand All @@ -15,9 +13,16 @@ function ITensorVisualizationCore.visualize(
vertex_labels = [vertex_labels_prefix * string(v) for v in vertices(graph)]
end
#edge_labels = [string(e) for e in edges(graph)]
return visualize(parent_graph(graph), args...; vertex_labels, kwargs...)
return ITensorVisualizationCore.visualize(
NamedGraphs.position_graph(graph), args...; vertex_labels, kwargs...
)
end

# TODO: Move to `DataGraphsITensorVisualizationCoreExt`.
using DataGraphs: DataGraphs, AbstractDataGraph
using ITensors.ITensorVisualizationCore: ITensorVisualizationCore
function ITensorVisualizationCore.visualize(graph::AbstractDataGraph, args...; kwargs...)
return visualize(underlying_graph(graph), args...; kwargs...)
return ITensorVisualizationCore.visualize(
DataGraphs.underlying_graph(graph), args...; kwargs...
)
end
Loading