Skip to content
Draft
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
8 changes: 6 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataGraphs"
uuid = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
version = "0.5.3"
version = "0.6.0"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]

[workspace]
Expand All @@ -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"
Expand All @@ -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"
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(;
Expand Down
21 changes: 21 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
@@ -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)).
4 changes: 2 additions & 2 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 1 addition & 2 deletions examples/datagraph.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 1 addition & 2 deletions examples/disjoint_union.jl
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 1 addition & 2 deletions examples/multidimdatagraph_2d.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 1 addition & 2 deletions examples/slicing.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
63 changes: 23 additions & 40 deletions src/abstractdatagraph.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion src/abstractedgeorvertexdatagraph.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions src/datagraph.jl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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),
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/dataview.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 9 additions & 11 deletions src/edgedatagraph.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 2 additions & 16 deletions src/indexing.jl
Original file line number Diff line number Diff line change
@@ -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 ======================================= #

Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading