From ac4ea8390a45da46b5cb2d185b7a0fa929349ceb Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Fri, 28 Aug 2026 19:04:27 -0400 Subject: [PATCH 1/2] Migrate to the NamedGraphs v0.14 interface NamedGraphs v0.14 replaced the position-graph interface with encode and decode, and removed the submodules DataGraphs imported from, so `main` cannot load against it at all. Also clears the five method ambiguities the migration surfaced and turns on the Aqua check guarding them. --- Project.toml | 8 ++- docs/Project.toml | 2 +- examples/Project.toml | 4 +- examples/datagraph.jl | 3 +- examples/disjoint_union.jl | 3 +- examples/multidimdatagraph_2d.jl | 3 +- examples/slicing.jl | 3 +- src/abstractdatagraph.jl | 63 ++++++---------- src/abstractedgeorvertexdatagraph.jl | 15 +++- src/datagraph.jl | 15 ++-- src/dataview.jl | 2 +- src/edgedatagraph.jl | 20 +++--- src/indexing.jl | 18 +---- .../src/DataGraphsPartitionedGraphsExt.jl | 47 +++++++----- src/traits/isunderlyinggraph.jl | 5 +- src/vertexdatagraph.jl | 20 +++--- test/Project.toml | 4 +- test/test_aqua.jl | 3 +- test/test_basics.jl | 38 +++++----- test/test_itensorvisualizationbase_ext.jl | 2 +- test/test_partitionedgraphs.jl | 71 ++++++++++++++++--- test/test_vertexoredgedatagraph.jl | 39 ++++++---- 22 files changed, 220 insertions(+), 168 deletions(-) diff --git a/Project.toml b/Project.toml index e3a180d..28aef60 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DataGraphs" uuid = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a" -version = "0.5.3" +version = "0.6.0" authors = ["Matthew Fishman and contributors"] [workspace] @@ -16,6 +16,10 @@ SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889" ITensorVisualizationBase = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23" +[sources.NamedGraphs] +rev = "main" +url = "https://github.com/ITensor/NamedGraphs.jl" + [extensions] DataGraphsGraphsFlowsExt = "GraphsFlows" DataGraphsITensorVisualizationBaseExt = "ITensorVisualizationBase" @@ -25,6 +29,6 @@ Dictionaries = "0.4" Graphs = "1" GraphsFlows = "0.1.1" ITensorVisualizationBase = "0.1" -NamedGraphs = "0.11.4, 0.12, 0.13" +NamedGraphs = "0.14" SimpleTraits = "0.9" julia = "1.10" diff --git a/docs/Project.toml b/docs/Project.toml index 429184c..d0dce12 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,7 +8,7 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" path = ".." [compat] -DataGraphs = "0.5" +DataGraphs = "0.6" Documenter = "1.10" ITensorFormatter = "0.2.27" Literate = "2.20.1" diff --git a/examples/Project.toml b/examples/Project.toml index beb6b0e..2a5c733 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -7,6 +7,6 @@ NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19" path = ".." [compat] -DataGraphs = "0.5" +DataGraphs = "0.6" Graphs = "1.12" -NamedGraphs = "0.11, 0.12, 0.13" +NamedGraphs = "0.14" diff --git a/examples/datagraph.jl b/examples/datagraph.jl index eed0071..0f0d082 100644 --- a/examples/datagraph.jl +++ b/examples/datagraph.jl @@ -1,7 +1,6 @@ using DataGraphs: DataGraph using Graphs: has_edge, has_vertex -using NamedGraphs.NamedGraphGenerators: named_grid -using NamedGraphs: NamedEdge +using NamedGraphs: NamedEdge, named_grid g = named_grid((4)) dg = DataGraph(g; vertex_data_type = String, edge_data_type = Symbol) diff --git a/examples/disjoint_union.jl b/examples/disjoint_union.jl index 674e359..1711a81 100644 --- a/examples/disjoint_union.jl +++ b/examples/disjoint_union.jl @@ -1,7 +1,6 @@ using DataGraphs: DataGraph using Graphs: edges, has_edge, has_vertex, ne, nv, vertices -using NamedGraphs.GraphsExtensions: ⊔ -using NamedGraphs.NamedGraphGenerators: named_grid +using NamedGraphs: named_grid, ⊔ g = DataGraph(named_grid((2, 2)); vertex_data_type = String, edge_data_type = String) diff --git a/examples/multidimdatagraph_2d.jl b/examples/multidimdatagraph_2d.jl index cb5af12..14ac425 100644 --- a/examples/multidimdatagraph_2d.jl +++ b/examples/multidimdatagraph_2d.jl @@ -1,6 +1,5 @@ using DataGraphs: DataGraph -using NamedGraphs.NamedGraphGenerators: named_grid -using NamedGraphs: NamedEdge +using NamedGraphs: NamedEdge, named_grid g = named_grid((2, 2)) dg = DataGraph(g; vertex_data_type = String, edge_data_type = String) diff --git a/examples/slicing.jl b/examples/slicing.jl index 3f2ff6f..c07aad6 100644 --- a/examples/slicing.jl +++ b/examples/slicing.jl @@ -1,7 +1,6 @@ using DataGraphs: DataGraph using Graphs: ne, nv -using NamedGraphs.GraphsExtensions: subgraph -using NamedGraphs.NamedGraphGenerators: named_grid +using NamedGraphs: named_grid, subgraph g = named_grid((2, 2)) dg = DataGraph(g; vertex_data_type = String, edge_data_type = String) diff --git a/src/abstractdatagraph.jl b/src/abstractdatagraph.jl index 47616f0..42cced2 100644 --- a/src/abstractdatagraph.jl +++ b/src/abstractdatagraph.jl @@ -1,13 +1,10 @@ using Dictionaries: Indices, set!, unset! using Graphs: Graphs, AbstractEdge, IsDirected, a_star, add_edge!, add_vertex!, edges, indegree, induced_subgraph, ne, nv, outdegree, steiner_tree, vertices -using NamedGraphs.GraphsExtensions: GraphsExtensions, add_edges!, add_vertices!, - arrange_edge, incident_edges, is_edge_arranged, rem_edges, vertextype -using NamedGraphs.OrdinalIndexing: OrdinalSuffixedInteger -using NamedGraphs.SimilarType: similar_type -using NamedGraphs: NamedGraphs, AbstractEdges, AbstractNamedEdge, AbstractNamedGraph, - AbstractVertices, NamedDiGraph, NamedGraph, Vertices, position_graph_type, - similar_graph, subgraph_edges +using NamedGraphs: NamedGraphs, AbstractEdges, AbstractNamedGraph, AbstractVertices, + NamedDiGraph, NamedGraph, Vertices, add_edges!, arrange_edge, decoded_vertex, + encoded_graph, encoded_graph_type, encoded_vertex, incident_edges, is_edge_arranged, + rem_edges, similar_graph, subgraph_edges, vertextype using SimpleTraits: SimpleTraits, @traitfn, Not struct VertexEdgeDataTypes{VD, ED} @@ -72,8 +69,8 @@ underlying_graph_type(graph::AbstractGraph) = typeof(underlying_graph(graph)) vertex_data_type(graph::AbstractGraph) = vertex_data_type(typeof(graph)) edge_data_type(graph::AbstractGraph) = edge_data_type(typeof(graph)) -function NamedGraphs.position_graph_type(type::Type{<:AbstractDataGraph}) - return position_graph_type(underlying_graph_type(type)) +function NamedGraphs.encoded_graph_type(type::Type{<:AbstractDataGraph}) + return encoded_graph_type(underlying_graph_type(type)) end function Base.copy(graph::AbstractDataGraph) @@ -116,27 +113,24 @@ function Graphs.vertices(graph::AbstractDataGraph) return Graphs.vertices(underlying_graph(graph)) end function Graphs.add_vertex!(graph::AbstractDataGraph, vertex) - Graphs.add_vertex!(underlying_graph(graph), vertex) - return graph + return Graphs.add_vertex!(underlying_graph(graph), vertex) end # Simple NamedGraphs overloads -for f in [ - :(NamedGraphs.ordered_vertices), - :(NamedGraphs.vertex_positions), - :(NamedGraphs.position_graph), - ] - @eval begin - $f(graph::AbstractDataGraph) = $f(underlying_graph(graph)) - end +NamedGraphs.encoded_graph(graph::AbstractDataGraph) = encoded_graph(underlying_graph(graph)) +function NamedGraphs.encoded_vertex(graph::AbstractDataGraph, vertex) + return encoded_vertex(underlying_graph(graph), vertex) +end +function NamedGraphs.decoded_vertex(graph::AbstractDataGraph, code::Integer) + return decoded_vertex(underlying_graph(graph), code) end # These cannot be known abstractly. -GraphsExtensions.directed_graph_type(::AbstractDataGraph) = not_implemented() -GraphsExtensions.undirected_graph_type(::AbstractDataGraph) = not_implemented() +NamedGraphs.directed_graph_type(::AbstractDataGraph) = not_implemented() +NamedGraphs.undirected_graph_type(::AbstractDataGraph) = not_implemented() # Thase canot be implemented abstractly. -GraphsExtensions.convert_vertextype(::Type, ::AbstractDataGraph) = not_implemented() +NamedGraphs.convert_vertextype(::Type, ::AbstractDataGraph) = not_implemented() function Base.:(==)(dg1::AbstractDataGraph, dg2::AbstractDataGraph) underlying_graph(dg1) == underlying_graph(dg2) || return false @@ -220,24 +214,15 @@ end return DataGraph(underlying_graph; vertex_data_type = VD, edge_data_type = ED) end -# Fix for ambiguity error with `AbstractGraph` version -function Graphs.eccentricity( - graph::AbstractDataGraph, - vertex::Integer, - distmx::AbstractMatrix{<:Real} = NamedGraphs.weights(graph) - ) - return NamedGraphs.namedgraph_eccentricity(graph, vertex, distmx) -end - -@traitfn GraphsExtensions.directed_graph(graph::AbstractDataGraph::IsDirected) = graph +@traitfn NamedGraphs.directed_graph(graph::AbstractDataGraph::IsDirected) = graph -reverse_data_direction(graph::AbstractDataGraph, data) = data -function reverse_data_direction(graph::AbstractDataGraph, edge::AbstractEdge, data) +reverse_data_direction(graph::AbstractGraph, data) = data +function reverse_data_direction(graph::AbstractGraph, edge::AbstractEdge, data) return is_edge_arranged(graph, edge) ? data : reverse_data_direction(graph, data) end # Fallback to constructing a concrete `DataGraph`. -@traitfn function GraphsExtensions.directed_graph(graph::AbstractDataGraph::(!IsDirected)) +@traitfn function NamedGraphs.directed_graph(graph::AbstractDataGraph::(!IsDirected)) underlying_digraph = similar_graph(NamedDiGraph, vertices(graph)) # edgeless VD = vertex_data_type(graph) @@ -264,7 +249,7 @@ end return digraph end -function GraphsExtensions.rename_vertices(f::Function, graph::AbstractDataGraph) +function NamedGraphs.rename_vertices(f::Function, graph::AbstractDataGraph) # Uses the two-argument `similar_graph` method so the new graph has correct vertex type renamed_vertices = map(f, vertices(graph)) renamed_graph = similar_graph(graph, renamed_vertices) @@ -351,12 +336,10 @@ function Base.union( end function Graphs.rem_vertex!(graph::AbstractDataGraph, vertex) - Graphs.rem_vertex!(underlying_graph(graph), vertex) - return graph + return Graphs.rem_vertex!(underlying_graph(graph), vertex) end function Graphs.rem_edge!(graph::AbstractDataGraph, edge) - Graphs.rem_edge!(underlying_graph(graph), edge) - return graph + return Graphs.rem_edge!(underlying_graph(graph), edge) end function map_vertex_data(f, graph::AbstractGraph; vertices = nothing) diff --git a/src/abstractedgeorvertexdatagraph.jl b/src/abstractedgeorvertexdatagraph.jl index b52ae67..72e1056 100644 --- a/src/abstractedgeorvertexdatagraph.jl +++ b/src/abstractedgeorvertexdatagraph.jl @@ -1,5 +1,6 @@ using Dictionaries: Dictionaries, Indices, isinsertable, set! -using Graphs: edges, edgetype, has_edge, has_vertex, rem_edge!, rem_vertex!, vertices +using Graphs: + dst, edges, edgetype, has_edge, has_vertex, rem_edge!, rem_vertex!, src, vertices using NamedGraphs: NamedGraphs, Vertices, similar_graph, subgraph_edges, to_graph_index abstract type AbstractVertexDataGraph{T, V} <: AbstractDataGraph{V, T, Nothing} end @@ -22,6 +23,15 @@ for GType in (:AbstractVertexDataGraph, :AbstractEdgeDataGraph) return similar_graph(graph, valtype(graph), vertices) end + # `VertexEdgeDataTypes` is a wrapper that names data types, so the second argument + # keeps its data-type meaning here rather than the vertices meaning above. + function NamedGraphs.similar_graph( + graph::$GType, + D::VertexEdgeDataTypes + ) + return similar_datagraph(graph, D) + end + function Base.copy(graph::$GType) graph_dst = similar_graph(graph) # Allow copies of graphs with undefined data. @@ -195,6 +205,9 @@ function insert!_datagraph(graph::AbstractEdgeDataGraph, edge::AbstractEdge, dat if has_edge(graph, edge) throw(IndexError("Graph already contains edge $edge")) end + if !has_vertex(graph, src(edge)) || !has_vertex(graph, dst(edge)) + throw(IndexError("Graph does not contain the vertices of edge $edge")) + end insert_edge_data!(graph, edge, data) return graph end diff --git a/src/datagraph.jl b/src/datagraph.jl index 35c980f..b37c6af 100644 --- a/src/datagraph.jl +++ b/src/datagraph.jl @@ -1,8 +1,7 @@ using Dictionaries: Dictionary using Graphs: Graphs, bfs_tree, dfs_tree, edgetype, has_edge, has_vertex -using NamedGraphs.GraphsExtensions: - convert_vertextype, directed_graph, directed_graph_type, rename_vertices, vertextype -using NamedGraphs: GenericNamedGraph, similar_graph +using NamedGraphs: NamedGraphs, convert_vertextype, directed_graph, directed_graph_type, + rename_vertices, similar_graph, vertextype # TODO: define VertexDataGraph, a graph with only data on the # vertices, and EdgeDataGraph, a graph with only data on the edges. @@ -141,11 +140,11 @@ function DataGraph{V}(graph::DataGraph) where {V} ) end -function GraphsExtensions.convert_vertextype(vertextype::Type, graph::DataGraph) +function NamedGraphs.convert_vertextype(vertextype::Type, graph::DataGraph) return DataGraph{vertextype}(graph) end -function GraphsExtensions.directed_graph_type(graph_type::Type{<:DataGraph}) +function NamedGraphs.directed_graph_type(graph_type::Type{<:DataGraph}) return DataGraph{ vertextype(graph_type), vertex_data_type(graph_type), @@ -161,12 +160,10 @@ function Graphs.rem_vertex!(graph::DataGraph, vertex) for neighbor_edge in neighbor_edges delete!(graph.edge_data, neighbor_edge) end - Graphs.rem_vertex!(graph.underlying_graph, vertex) - return graph + return Graphs.rem_vertex!(graph.underlying_graph, vertex) end function Graphs.rem_edge!(graph::DataGraph, edge) delete!(graph.edge_data, edge) - Graphs.rem_edge!(graph.underlying_graph, edge) - return graph + return Graphs.rem_edge!(graph.underlying_graph, edge) end diff --git a/src/dataview.jl b/src/dataview.jl index cd7eb63..d7413ba 100644 --- a/src/dataview.jl +++ b/src/dataview.jl @@ -1,6 +1,6 @@ using Dictionaries: Dictionaries, AbstractDictionary, IndexError, Indices, filterview, getindices, gettokenvalue, istokenizable -using NamedGraphs: to_edges, to_graph_index, to_vertices +using NamedGraphs: to_graph_index abstract type AbstractDataView{K, V} <: AbstractDictionary{K, V} end diff --git a/src/edgedatagraph.jl b/src/edgedatagraph.jl index 6ed93d9..0879ed5 100644 --- a/src/edgedatagraph.jl +++ b/src/edgedatagraph.jl @@ -1,5 +1,5 @@ using Graphs: dst, has_edge, rem_edge!, rem_vertex!, src -using NamedGraphs: NamedEdge, NamedGraph, ordered_vertices, position_graph, vertex_positions +using NamedGraphs: NamedEdge, NamedGraph, decoded_vertex, encoded_graph, encoded_vertex struct EdgeDataGraph{T, V} <: AbstractEdgeDataGraph{T, V} underlying_graph::NamedGraph{V} @@ -75,14 +75,12 @@ for GType in (:EdgeDataGraph, :EdgeDataDiGraph) for edge in incident_edges(graph, vertex) unset!(graph.edge_data, edge) end - rem_vertex!(graph.underlying_graph, vertex) - return graph + return rem_vertex!(graph.underlying_graph, vertex) end function Graphs.rem_edge!(graph::$GType, edge) unset!(graph.edge_data, edge) - rem_edge!(graph.underlying_graph, edge) - return graph + return rem_edge!(graph.underlying_graph, edge) end Graphs.vertices(graph::$GType) = vertices(graph.underlying_graph) @@ -93,16 +91,16 @@ end for GType in (:EdgeDataGraph, :EdgeDataDiGraph) @eval begin - function NamedGraphs.vertex_positions(graph::$GType) - return vertex_positions(graph.underlying_graph) + function NamedGraphs.encoded_vertex(graph::$GType, vertex) + return encoded_vertex(graph.underlying_graph, vertex) end - function NamedGraphs.ordered_vertices(graph::$GType) - return ordered_vertices(graph.underlying_graph) + function NamedGraphs.decoded_vertex(graph::$GType, code::Integer) + return decoded_vertex(graph.underlying_graph, code) end - function NamedGraphs.position_graph(graph::$GType) - return position_graph(graph.underlying_graph) + function NamedGraphs.encoded_graph(graph::$GType) + return encoded_graph(graph.underlying_graph) end function NamedGraphs.similar_graph(graph::$GType, T::Type, vertices) diff --git a/src/indexing.jl b/src/indexing.jl index 3368dd0..c807089 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -1,7 +1,6 @@ using Dictionaries: AbstractIndices, getindices -using NamedGraphs.GraphsExtensions: subgraph -using NamedGraphs: AbstractEdges, AbstractGraphIndices, AbstractVertices, to_edges, - to_graph_index, to_vertices +using NamedGraphs: + AbstractEdges, AbstractGraphIndices, AbstractVertices, subgraph, to_graph_index # ====================================== getindex ======================================= # @@ -115,19 +114,6 @@ function Base.setindex!(graph::AbstractDataGraph, x, i1, i2, i...) return graph end -# Ordinal Indexing -function NamedGraphs.to_graph_index( - graph::AbstractGraph, - pair::Pair{<:OrdinalSuffixedInteger, <:OrdinalSuffixedInteger} - ) - vs = vertices(graph) - v1, v2 = pair - return to_graph_index(graph, vs[v1] => vs[v2]) -end -function NamedGraphs.to_graph_index(graph::AbstractGraph, vertex::OrdinalSuffixedInteger) - return to_graph_index(graph, vertices(graph)[vertex]) -end - # ====================================== getindices ====================================== # function Dictionaries.getindices(graph::AbstractDataGraph, inds::Indices) diff --git a/src/lib/DataGraphsPartitionedGraphsExt/src/DataGraphsPartitionedGraphsExt.jl b/src/lib/DataGraphsPartitionedGraphsExt/src/DataGraphsPartitionedGraphsExt.jl index e38a523..33402b3 100644 --- a/src/lib/DataGraphsPartitionedGraphsExt/src/DataGraphsPartitionedGraphsExt.jl +++ b/src/lib/DataGraphsPartitionedGraphsExt/src/DataGraphsPartitionedGraphsExt.jl @@ -1,22 +1,21 @@ module DataGraphsPartitionedGraphsExt -using ..DataGraphs: AbstractDataGraph, DataGraph, DataGraphs, IsUnderlyingGraph, _DataGraph, - _getindex, edge_data, edgetype, get_edge_data, get_edges_data, get_index_data, - get_vertex_data, get_vertices_data, is_edge_assigned, is_graph_index_assigned, - is_underlying_graph, is_vertex_assigned, set_edge_data!, set_edges_data!, - set_index_data!, set_vertex_data!, set_vertices_data!, underlying_graph, vertex_data +using ..DataGraphs: AbstractDataGraph, AbstractEdgeDataGraph, AbstractVertexDataGraph, + DataGraph, DataGraphs, IsUnderlyingGraph, _DataGraph, _getindex, edge_data, edgetype, + get_edge_data, get_edges_data, get_index_data, get_vertex_data, get_vertices_data, + is_edge_assigned, is_graph_index_assigned, is_underlying_graph, is_vertex_assigned, + set_edge_data!, set_edges_data!, set_index_data!, set_vertex_data!, set_vertices_data!, + underlying_graph, vertex_data using Dictionaries: Dictionary, IndexError, Indices -using Graphs: Graphs, AbstractEdge, AbstractGraph, edges, vertices -using NamedGraphs.GraphsExtensions: add_vertices!, edge_subgraph, subgraph, vertextype +using Graphs: Graphs, AbstractEdge, AbstractGraph, add_edge!, add_vertices!, dst, edges, + has_edge, src, vertices using NamedGraphs.PartitionedGraphs: AbstractPartitionedGraph, PartitionedGraph, - PartitionedGraphs, PartitionedView, QuotientEdge, QuotientEdgeEdge, QuotientEdgeEdges, - QuotientEdgeSlice, QuotientEdges, QuotientVertex, QuotientVertexOrEdge, - QuotientVertexSlice, QuotientVertexVertex, QuotientVertexVertices, QuotientVertices, - QuotientVerticesVertices, QuotientView, departition, has_quotientedge, - has_quotientvertex, parent_graph_type, partitioned_vertices, partitionedgraph, - quotient_graph, quotient_graph_type, quotientedges, quotientvertex, quotientvertices, - unpartitioned_graph -using NamedGraphs: NamedGraphs, Edges, Vertices, get_graph_index, similar_graph, to_edges, - to_graph_index, to_vertices + PartitionedGraphs, PartitionedView, QuotientEdge, QuotientEdgeSlice, QuotientEdges, + QuotientVertex, QuotientVertexOrEdge, QuotientVertexSlice, QuotientVertices, + QuotientVerticesVertices, QuotientView, departition, parent_graph_type, + partitioned_vertices, partitionedgraph, quotient_graph, quotient_graph_type, + quotientvertex, unpartitioned_graph +using NamedGraphs: NamedGraphs, Edges, Vertices, edge_subgraph, get_graph_index, + similar_graph, subgraph, to_edges, to_graph_index, to_vertices, vertextype using SimpleTraits: SimpleTraits, @traitfn, Not # ======================== DataGraphs interface for QuotientView ========================= # @@ -155,6 +154,18 @@ DataGraphs.is_graph_index_assigned(graph::AbstractGraph, ind::QuotientVertexOrEd function DataGraphs.set_index_data!(graph::AbstractGraph, value, ind::QuotientVertexOrEdge) return throw(MethodError(set_index_data!, (graph, value, ind))) end +# These graphs take an untyped index as a vertex or edge of their own, which a quotient +# index never is, so they defer to the method above instead of the other way around. +function DataGraphs.set_index_data!( + graph::AbstractVertexDataGraph, value, ind::QuotientVertexOrEdge + ) + return throw(MethodError(set_index_data!, (graph, value, ind))) +end +function DataGraphs.set_index_data!( + graph::AbstractEdgeDataGraph, value, ind::QuotientVertexOrEdge + ) + return throw(MethodError(set_index_data!, (graph, value, ind))) +end function DataGraphs.vertex_data_type(T::Type{<:QuotientView}) PGT = parent_graph_type(T) @@ -228,7 +239,7 @@ function PartitionedGraphs.quotient_graph( ) where {PV} ug = unpartitioned_graph(g) - sg = similar_graph(underlying_graph(ug), PV) + sg = similar_graph(underlying_graph(ug), PV[]) qg = DataGraph( sg; vertex_data_type = Base.promote_op(subgraph, typeof(g), QuotientVertex{PV}), @@ -251,7 +262,7 @@ function PartitionedGraphs.quotient_graph( qe = edgetype(qg)(qv_src => qv_dst) if qv_src != qv_dst && !has_edge(qg, qe) add_edge!(qg, qe) - qg[qe] = g[QuotientEdge(e)] + qg[qe] = g[QuotientEdge(qv_src => qv_dst)] end end diff --git a/src/traits/isunderlyinggraph.jl b/src/traits/isunderlyinggraph.jl index 16d1e20..77f08e0 100644 --- a/src/traits/isunderlyinggraph.jl +++ b/src/traits/isunderlyinggraph.jl @@ -11,5 +11,6 @@ is_underlying_graph(::Type{<:AbstractGraph}) = false using Graphs.SimpleGraphs: AbstractSimpleGraph is_underlying_graph(::Type{<:AbstractSimpleGraph}) = true -using NamedGraphs: GenericNamedGraph -is_underlying_graph(::Type{<:GenericNamedGraph}) = true +using NamedGraphs: NamedDiGraph, NamedGraph +is_underlying_graph(::Type{<:NamedGraph}) = true +is_underlying_graph(::Type{<:NamedDiGraph}) = true diff --git a/src/vertexdatagraph.jl b/src/vertexdatagraph.jl index e7fdd6d..7d0a5ad 100644 --- a/src/vertexdatagraph.jl +++ b/src/vertexdatagraph.jl @@ -1,7 +1,7 @@ using Dictionaries: Dictionary, set! using Graphs: Graphs, has_edge, rem_vertex! using NamedGraphs: - NamedDiGraph, NamedEdge, NamedGraph, ordered_vertices, position_graph, vertex_positions + NamedDiGraph, NamedEdge, NamedGraph, decoded_vertex, encoded_graph, encoded_vertex struct VertexDataGraph{T, V} <: AbstractVertexDataGraph{T, V} underlying_graph::NamedGraph{V} @@ -75,13 +75,11 @@ for GType in (:VertexDataGraph, :VertexDataDiGraph) function Graphs.rem_vertex!(graph::$GType, vertex) unset!(graph.vertex_data, vertex) - rem_vertex!(graph.underlying_graph, vertex) - return graph + return rem_vertex!(graph.underlying_graph, vertex) end function Graphs.rem_edge!(graph::$GType, vertex) - rem_edge!(graph.underlying_graph, vertex) - return graph + return rem_edge!(graph.underlying_graph, vertex) end Graphs.vertices(graph::$GType) = vertices(graph.underlying_graph) @@ -92,16 +90,16 @@ end for GType in (:VertexDataGraph, :VertexDataDiGraph) @eval begin - function NamedGraphs.vertex_positions(graph::$GType) - return vertex_positions(graph.underlying_graph) + function NamedGraphs.encoded_vertex(graph::$GType, vertex) + return encoded_vertex(graph.underlying_graph, vertex) end - function NamedGraphs.ordered_vertices(graph::$GType) - return ordered_vertices(graph.underlying_graph) + function NamedGraphs.decoded_vertex(graph::$GType, code::Integer) + return decoded_vertex(graph.underlying_graph, code) end - function NamedGraphs.position_graph(graph::$GType) - return position_graph(graph.underlying_graph) + function NamedGraphs.encoded_graph(graph::$GType) + return encoded_graph(graph.underlying_graph) end function NamedGraphs.similar_graph(graph::$GType, T::Type, vertices) diff --git a/test/Project.toml b/test/Project.toml index 91df964..cadbfbf 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -16,13 +16,13 @@ path = ".." [compat] Aqua = "0.8.11" -DataGraphs = "0.5" +DataGraphs = "0.6" Dictionaries = "0.4.4" Graphs = "1.12" GraphsFlows = "0.1.1" ITensorPkgSkeleton = "0.3.42" ITensorVisualizationBase = "0.1" -NamedGraphs = "0.11, 0.12, 0.13" +NamedGraphs = "0.14" SafeTestsets = "0.1" Suppressor = "0.2.8" Test = "1.10" diff --git a/test/test_aqua.jl b/test/test_aqua.jl index c23ed74..b787604 100644 --- a/test/test_aqua.jl +++ b/test/test_aqua.jl @@ -3,5 +3,6 @@ using DataGraphs: DataGraphs using Test: @testset @testset "Code quality (Aqua.jl)" begin - # Aqua.test_all(DataGraphs) + Aqua.test_ambiguities(DataGraphs) + # TODO: Enable the remaining checks with `Aqua.test_all(DataGraphs)`. end diff --git a/test/test_basics.jl b/test/test_basics.jl index 5700f36..1f9aff3 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -6,11 +6,9 @@ using Graphs: SimpleDiGraph, a_star, add_edge!, bfs_tree, connected_components, dfs_tree, dijkstra_shortest_paths, dst, edges, edgetype, grid, has_edge, has_vertex, indegree, is_directed, ne, nv, outdegree, path_graph, src, steiner_tree, vertices using GraphsFlows: GraphsFlows -using NamedGraphs.GraphsExtensions: - directed_graph, empty_graph, rename_vertices, subgraph, vertextype, ⊔ -using NamedGraphs.NamedGraphGenerators: named_grid, named_path_graph -using NamedGraphs.OrdinalIndexing: nd, rd, st, th -using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph, similar_graph +using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph, decoded_vertex, directed_graph, + empty_graph, named_grid, named_path_graph, rename_vertices, similar_graph, subgraph, + vertextype, ⊔ using Test: @test, @test_broken, @testset @testset "DataGraphs.jl" begin @@ -455,17 +453,18 @@ using Test: @test, @test_broken, @testset @test verts[4] ∈ part2 @test flow == 1 end - @testset "OrdinalIndexing" begin + @testset "Indexing by decoded vertex" begin g = DataGraph( NamedGraph(path_graph(3), ["a", "b", "c"]); vertex_data_type = String, edge_data_type = Symbol ) - g[1st] = "v_a" - g[2nd] = "v_b" - g[3rd] = "v_c" - g[1st => 2nd] = :e_ab - g[2nd => 3rd] = :e_bc + v1, v2, v3 = map(c -> decoded_vertex(g, c), 1:3) + g[v1] = "v_a" + g[v2] = "v_b" + g[v3] = "v_c" + g[v1 => v2] = :e_ab + g[v2 => v3] = :e_bc @test g["a"] == "v_a" @test g["b"] == "v_b" @test g["c"] == "v_c" @@ -473,16 +472,13 @@ using Test: @test, @test_broken, @testset @test g["b" => "a"] === :e_ab @test g["b" => "c"] === :e_bc @test g["c" => "b"] === :e_bc - @test g[1st] == "v_a" - @test g[1th] == "v_a" - @test g[2nd] == "v_b" - @test g[2th] == "v_b" - @test g[3rd] == "v_c" - @test g[3th] == "v_c" - @test g[1st => 2nd] === :e_ab - @test g[2nd => 1st] === :e_ab - @test g[2nd => 3rd] === :e_bc - @test g[3rd => 2nd] === :e_bc + @test g[v1] == "v_a" + @test g[v2] == "v_b" + @test g[v3] == "v_c" + @test g[v1 => v2] === :e_ab + @test g[v2 => v1] === :e_ab + @test g[v2 => v3] === :e_bc + @test g[v3 => v2] === :e_bc end @testset "Data views" begin diff --git a/test/test_itensorvisualizationbase_ext.jl b/test/test_itensorvisualizationbase_ext.jl index 1741d42..49f352e 100644 --- a/test/test_itensorvisualizationbase_ext.jl +++ b/test/test_itensorvisualizationbase_ext.jl @@ -1,7 +1,7 @@ @eval module $(gensym()) using DataGraphs: AbstractDataGraph, DataGraph using ITensorVisualizationBase: ITensorVisualizationBase -using NamedGraphs.NamedGraphGenerators: named_grid +using NamedGraphs: named_grid using Test: @test, @testset @testset "DataGraphsITensorVisualizationBaseExt" begin diff --git a/test/test_partitionedgraphs.jl b/test/test_partitionedgraphs.jl index 2ee519d..e530580 100644 --- a/test/test_partitionedgraphs.jl +++ b/test/test_partitionedgraphs.jl @@ -1,18 +1,18 @@ module TestModule -using DataGraphs: DataGraphs, AbstractDataGraph, DataGraph, EdgeDataView, VertexDataView, - assigned_edge_data, assigned_vertex_data, edge_data, edge_data_type, underlying_graph, - vertex_data, vertex_data_type +using DataGraphs: DataGraphs, AbstractDataGraph, DataGraph, EdgeDataGraph, EdgeDataView, + VertexDataGraph, VertexDataView, assigned_edge_data, assigned_vertex_data, edge_data, + edge_data_type, set_index_data!, underlying_graph, vertex_data, vertex_data_type using Dictionaries: Dictionary, IndexError, Indices -using Graphs: AbstractGraph, dst, edges, edgetype, has_edge, has_vertex, src, vertices -using NamedGraphs.GraphsExtensions: GraphsExtensions, subgraph, vertextype -using NamedGraphs.NamedGraphGenerators: named_path_graph -using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionedGraphs, QuotientEdge, - QuotientEdges, QuotientVertex, QuotientVertexOrEdge, QuotientVertexVertex, +using Graphs: + AbstractGraph, dst, edges, edgetype, has_edge, has_vertex, path_graph, src, vertices +using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionedGraphs, PartitionedView, + QuotientEdge, QuotientEdges, QuotientVertex, QuotientVertexOrEdge, QuotientVertexVertex, QuotientVertexVertices, QuotientVertices, QuotientVerticesVertices, QuotientView, departition, partitioned_vertices, partitionedgraph, quotient_graph, quotientedges, quotientvertices, unpartition -using NamedGraphs: NamedGraphs, Edges, NamedGraph, Vertices, similar_graph +using NamedGraphs: NamedGraphs, Edges, NamedEdge, NamedGraph, Vertices, named_path_graph, + similar_graph, subgraph, vertextype using Test: @test, @test_throws, @testset struct TestDataGraph{V, VD, ED, DG <: DataGraph{V, VD, ED}, QDG} <: @@ -305,6 +305,59 @@ end @test !has_edge(QuotientView(sg), :b => :c) end end + + @testset "Quotient indexing of vertex or edge data graphs" begin + vdg = VertexDataGraph(Dictionary([1, 2], ["1", "2"])) + edg = EdgeDataGraph(Dictionary([NamedEdge(1, 2)], [("1", "2")])) + + # A quotient index is never a vertex or an edge of these graphs, so it takes the + # quotient meaning rather than the vertex or edge meaning. + for (graph, ind) in ( + (vdg, QuotientVertex(1)), + (vdg, QuotientEdge(NamedEdge(1, 2))), + (edg, QuotientEdge(NamedEdge(1, 2))), + ) + method = which(set_index_data!, Tuple{typeof(graph), String, typeof(ind)}) + @test method.module === DataGraphs.DataGraphsPartitionedGraphsExt + @test_throws MethodError set_index_data!(graph, "x", ind) + end + end +end + +@testset "quotient_graph of a PartitionedView over a DataGraph" begin + # Nothing else reaches + # `quotient_graph(::PartitionedView{<:Any, PV, <:DataGraph})`, since the other + # tests build a `PartitionedGraph` from the underlying `NamedGraph` instead. + g = DataGraph( + NamedGraph(path_graph(4), ["a", "b", "c", "d"]); + vertex_data_type = String, + edge_data_type = Symbol + ) + for (v, d) in zip(["a", "b", "c", "d"], ["v_a", "v_b", "v_c", "v_d"]) + g[v] = d + end + g["a" => "b"] = :e_ab + g["b" => "c"] = :e_bc + g["c" => "d"] = :e_cd + + pvs = Dictionary([:L, :R], [["a", "b"], ["c", "d"]]) + pv = PartitionedView(g, pvs) + qg = quotient_graph(pv) + + @test qg isa DataGraph + @test issetequal(vertices(qg), [:L, :R]) + @test issetequal(edges(qg), [edgetype(qg)(:L => :R)]) + + # The data types come from `Base.promote_op`, which infers `Union{}` rather + # than throwing if the inner call is broken. + @test vertex_data_type(typeof(qg)) !== Union{} + @test edge_data_type(typeof(qg)) !== Union{} + + # Each quotient vertex carries its induced subgraph, each quotient edge the + # edges crossing between the two blocks. + @test issetequal(vertices(qg[:L]), ["a", "b"]) + @test issetequal(vertices(qg[:R]), ["c", "d"]) + @test issetequal(edges(qg[:L => :R]), [NamedEdge("b" => "c")]) end end diff --git a/test/test_vertexoredgedatagraph.jl b/test/test_vertexoredgedatagraph.jl index ebeacf5..aee2901 100644 --- a/test/test_vertexoredgedatagraph.jl +++ b/test/test_vertexoredgedatagraph.jl @@ -1,14 +1,13 @@ -using DataGraphs: DataGraphs, EdgeDataDiGraph, EdgeDataGraph, EdgeDataView, - VertexDataDiGraph, VertexDataGraph, VertexDataView, edge_data, edge_data_type, - underlying_graph, vertex_data, vertex_data_type +using DataGraphs: DataGraphs, DataGraph, EdgeDataDiGraph, EdgeDataGraph, EdgeDataView, + VertexDataDiGraph, VertexDataGraph, VertexDataView, VertexEdgeDataTypes, edge_data, + edge_data_type, underlying_graph, vertex_data, vertex_data_type using Dictionaries: AbstractDictionary, Dictionary, IndexError, Indices, isinsertable, issettable, set! using Graphs: AbstractGraph, AbstractSimpleGraph, add_edge!, add_vertex!, dst, edges, edgetype, has_edge, has_vertex, is_directed, ne, nv, rem_edge!, rem_vertex!, src, vertices -using NamedGraphs.GraphsExtensions: add_edge, subgraph, vertextype -using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph, ordered_vertices, position_graph, - similar_graph, vertex_positions +using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph, add_edge, decoded_vertex, + encoded_graph, encoded_vertex, similar_graph, subgraph, vertextype using Test: @test, @test_throws, @testset @testset "VertexDataGraph and EdgeDataGraph" begin @@ -125,9 +124,9 @@ using Test: @test, @test_throws, @testset @testset "NamedGraphs interface" begin g = GType(undef, [1, 2, 3]) - @test position_graph(g) isa AbstractSimpleGraph{Int} - @test ordered_vertices(g) == [1, 2, 3] - @test keys(vertex_positions(g)) == vertices(g) + @test encoded_graph(g) isa AbstractSimpleGraph{Int} + @test [decoded_vertex(g, c) for c in 1:nv(g)] == [1, 2, 3] + @test [encoded_vertex(g, v) for v in vertices(g)] == 1:nv(g) g = add_edge(g, NamedEdge(1, 2)) g[1] = "1" @@ -163,6 +162,14 @@ using Test: @test, @test_throws, @testset gs = similar_graph(g, Float64, vertices(g)) @test ne(gs) == 0 + # A `VertexEdgeDataTypes` is data types, not vertices. + gs = similar_graph(g, VertexEdgeDataTypes(Float64, Char)) + @test gs isa DataGraph + @test vertex_data_type(gs) === Float64 + @test edge_data_type(gs) === Char + @test issetequal(vertices(gs), vertices(g)) + @test issetequal(edges(gs), edges(g)) + gs = similar_graph(GType, [1.0, 2.0]) @test gs isa GType @test has_vertex(gs, 1) @@ -339,9 +346,9 @@ using Test: @test, @test_throws, @testset @testset "NamedGraphs interface" begin g = GType(Dictionary([1 => 2, 2 => 3], ["E12", "E23"])) @test issetequal(vertices(g), [1, 2, 3]) - @test position_graph(g) isa AbstractSimpleGraph{Int} - @test ordered_vertices(g) isa AbstractVector - @test vertex_positions(g) isa AbstractDictionary + @test encoded_graph(g) isa AbstractSimpleGraph{Int} + @test issetequal([decoded_vertex(g, c) for c in 1:nv(g)], vertices(g)) + @test [encoded_vertex(g, v) for v in vertices(g)] == 1:nv(g) gs = similar_graph(g) @test gs isa GType @@ -372,6 +379,14 @@ using Test: @test, @test_throws, @testset gs = similar_graph(g, Float64, vertices(g)) @test ne(gs) == 0 + # A `VertexEdgeDataTypes` is data types, not vertices. + gs = similar_graph(g, VertexEdgeDataTypes(Float64, Char)) + @test gs isa DataGraph + @test vertex_data_type(gs) === Float64 + @test edge_data_type(gs) === Char + @test issetequal(vertices(gs), vertices(g)) + @test issetequal(edges(gs), edges(g)) + gs = similar_graph(GType, [1.0, 2.0]) @test gs isa GType @test has_vertex(gs, 1) From a780aec08115052442645b1b5b88452da18bdb4e Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Mon, 31 Aug 2026 10:55:40 -0400 Subject: [PATCH 2/2] Add a changelog Records that 0.6.0 requires NamedGraphs v0.14, whose breaking changes reach the graph types here through `AbstractNamedGraph`, and points at the NamedGraphs changelog for what those are. --- docs/make.jl | 6 +++++- docs/src/changelog.md | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 docs/src/changelog.md diff --git a/docs/make.jl b/docs/make.jl index aa934d5..bbcee11 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -15,7 +15,11 @@ makedocs(; edit_link = "main", assets = ["assets/favicon.ico", "assets/extras.css"] ), - pages = ["Home" => "index.md", "Reference" => "reference.md"] + pages = [ + "Home" => "index.md", + "Reference" => "reference.md", + "Changelog" => "changelog.md", + ] ) deploydocs(; diff --git a/docs/src/changelog.md b/docs/src/changelog.md new file mode 100644 index 0000000..802df6f --- /dev/null +++ b/docs/src/changelog.md @@ -0,0 +1,21 @@ +# Changelog + +## [0.6.0](https://github.com/ITensor/DataGraphs.jl/compare/v0.5.3...main) - Unreleased + +### Breaking changes + +- Requires NamedGraphs v0.14. The graph 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/) + ([#126](https://github.com/ITensor/DataGraphs.jl/pull/126)). + +### Non-breaking changes + +- `quotient_graph` of a `PartitionedView` of a `DataGraph` works, where it + previously threw and read the edge data from the wrong edge + ([#126](https://github.com/ITensor/DataGraphs.jl/pull/126)). +- The method ambiguities in the package are resolved, and + `Aqua.test_ambiguities` is enabled to keep them from coming back + ([#126](https://github.com/ITensor/DataGraphs.jl/pull/126)).