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 1 commit
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
10 changes: 5 additions & 5 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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
NamedGraphs, NamedGraph, not_implemented, ordinal_vertex_to_vertex, vertex_to_ordinal_vertex
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
using NamedGraphs.GraphsExtensions:
⊔, directed_graph, incident_edges, rename_vertices, vertextype
using NDTensors: NDTensors, dim
Expand Down Expand Up @@ -94,11 +94,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_to_ordinal_vertex(tn::AbstractITensorNetwork, vertex)
return vertex_to_ordinal_vertex(underlying_graph(tn), vertex)
end
function NamedGraphs.parent_vertex_to_vertex(tn::AbstractITensorNetwork, parent_vertex)
return parent_vertex_to_vertex(underlying_graph(tn), parent_vertex)
function NamedGraphs.ordinal_vertex_to_vertex(tn::AbstractITensorNetwork, ordinal_vertex)
return ordinal_vertex_to_vertex(underlying_graph(tn), ordinal_vertex)
end

#
Expand Down
6 changes: 3 additions & 3 deletions src/contract.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NamedGraphs: vertex_to_parent_vertex
using NamedGraphs: vertex_to_ordinal_vertex
using ITensors: ITensor, scalar
using ITensors.ContractionSequenceOptimization: deepmap
using ITensors.NDTensors: NDTensors, Algorithm, @Algorithm_str, contract
Expand All @@ -16,9 +16,9 @@ function NDTensors.contract(
kwargs...,
)
# TODO: Use `vertex`.
sequence_linear_index = deepmap(v -> vertex_to_parent_vertex(tn, v), sequence)
sequence_linear_index = deepmap(v -> vertex_to_ordinal_vertex(tn, v), sequence)
# TODO: Use `tokenized_vertex`.
ts = map(pv -> tn[parent_vertex_to_vertex(tn, pv)], 1:nv(tn))
ts = map(pv -> tn[ordinal_vertex_to_vertex(tn, pv)], 1:nv(tn))
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,7 +2,7 @@ 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: ordinal_vertex_to_vertex
using NamedGraphs.Keys: Key

function contraction_sequence(tn::Vector{ITensor}; alg="optimal", kwargs...)
Expand All @@ -11,10 +11,10 @@ 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(pv -> tn[ordinal_vertex_to_vertex(tn, pv)], 1:nv(tn))
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(ordinal_vertex_to_vertex(tn, n)), seq_linear_index)
end

function contraction_sequence(::Algorithm"optimal", tn::Vector{ITensor})
Expand Down
4 changes: 2 additions & 2 deletions src/visualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using DataGraphs: AbstractDataGraph, underlying_graph
using Graphs: vertices
using ITensors.ITensorVisualizationCore: ITensorVisualizationCore, visualize
using NamedGraphs: AbstractNamedGraph, parent_graph
using NamedGraphs: AbstractNamedGraph, ordinal_graph

function ITensorVisualizationCore.visualize(
graph::AbstractNamedGraph,
Expand All @@ -15,7 +15,7 @@ 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 visualize(ordinal_graph(graph), args...; vertex_labels, kwargs...)
end

function ITensorVisualizationCore.visualize(graph::AbstractDataGraph, args...; kwargs...)
Expand Down
Loading