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: 4 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ and edges used internally.
override these hooks rather than the Graphs.jl functions themselves, which
means a subtype no longer needs its own `::Integer` disambiguator
([#187](https://github.com/ITensor/NamedGraphs.jl/pull/187)).
- The `GraphsExtensions` submodule is removed. Its contents are in `NamedGraphs`
directly, so `using NamedGraphs.GraphsExtensions: boundary_edges` becomes
`using NamedGraphs: boundary_edges`
([#190](https://github.com/ITensor/NamedGraphs.jl/pull/190)).

### Non-breaking changes

Expand Down
7 changes: 4 additions & 3 deletions docs/src/dev_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ decode_edge

## Graphs.jl interface extensions

```@docs; canonical=false
GraphsExtensions
```
NamedGraphs also defines generic extensions of the Graphs.jl interface. Many of
them are written against `Graphs.AbstractGraph` rather than against named graphs,
so they work for any graph type, including `Graphs.SimpleGraph`. The rest need
vertices that carry names and are only defined for [`AbstractNamedGraph`](@ref).
6 changes: 0 additions & 6 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ Modules = [NamedGraphs]
```@autodocs
Modules = [NamedGraphs.PartitionedGraphs]
```

## GraphsExtensions

```@autodocs
Modules = [NamedGraphs.GraphsExtensions]
```
5 changes: 2 additions & 3 deletions examples/boundary.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using NamedGraphs.GraphsExtensions:
boundary_vertices, inner_boundary_vertices, outer_boundary_vertices
using NamedGraphs: boundary_edges, named_grid
using NamedGraphs: boundary_edges, boundary_vertices, inner_boundary_vertices, named_grid,
outer_boundary_vertices

g = named_grid((5, 5))
subgraph_vertices = [(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)]
Expand Down
3 changes: 1 addition & 2 deletions examples/mincut.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Graphs: path_graph
using NamedGraphs.GraphsExtensions: mincut_partitions
using NamedGraphs: NamedGraph
using NamedGraphs: NamedGraph, mincut_partitions

g = NamedGraph(path_graph(4), ["A", "B", "C", "D"])

Expand Down
3 changes: 1 addition & 2 deletions ext/NamedGraphsGraphsFlowsExt/NamedGraphsGraphsFlowsExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module NamedGraphsGraphsFlowsExt
using Graphs: AbstractGraph, IsDirected
using GraphsFlows: GraphsFlows
using NamedGraphs.GraphsExtensions: GraphsExtensions
using NamedGraphs: NamedGraphs, AbstractNamedGraph, DefaultNamedCapacity, _symmetrize,
decode_vertex, directed_graph, encode_dist_matrix, encode_vertex, encoded_graph
using SimpleTraits: SimpleTraits, @traitfn
Expand Down Expand Up @@ -44,7 +43,7 @@ end
)
end

function GraphsExtensions.mincut_partitions(
function NamedGraphs.mincut_partitions(
graph::AbstractGraph,
source,
target,
Expand Down
6 changes: 3 additions & 3 deletions ext/NamedGraphsKaHyParExt/NamedGraphsKaHyParExt.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module NamedGraphsKaHyParExt
using Graphs: AbstractSimpleGraph, incidence_matrix
using KaHyPar: KaHyPar
using NamedGraphs.GraphsExtensions: @Backend_str, GraphsExtensions
using NamedGraphs: NamedGraphs, @Backend_str
using SplitApplyCombine: groupfind

GraphsExtensions.set_partitioning_backend!(Backend"kahypar"())
NamedGraphs.set_partitioning_backend!(Backend"kahypar"())

# KaHyPar configuration options
#
Expand Down Expand Up @@ -33,7 +33,7 @@ const KAHYPAR_ALGS = Dict(
- :connectivity => "km1_kKaHyPar_sea20.ini"
- imbalance::Number=0.03
"""
function GraphsExtensions.partition_vertices(
function NamedGraphs.partition_vertices(
::Backend"kahypar",
g::AbstractSimpleGraph,
npartitions::Integer;
Expand Down
6 changes: 3 additions & 3 deletions ext/NamedGraphsMetisExt/NamedGraphsMetisExt.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module NamedGraphsMetisExt
using Graphs: AbstractSimpleGraph
using Metis: Metis
using NamedGraphs.GraphsExtensions: @Backend_str, GraphsExtensions
using NamedGraphs: NamedGraphs, @Backend_str
using SplitApplyCombine: groupfind

GraphsExtensions.set_partitioning_backend!(Backend"metis"())
NamedGraphs.set_partitioning_backend!(Backend"metis"())

# Metis configuration options
const METIS_ALGS = Dict(["kway" => :KWAY, "recursive" => :RECURSIVE])
Expand All @@ -18,7 +18,7 @@ The partition algorithm is defined by the `alg` keyword:
- :KWAY: multilevel k-way partitioning
- :RECURSIVE: multilevel recursive bisection
"""
function GraphsExtensions.partition_vertices(
function NamedGraphs.partition_vertices(
::Backend"metis", g::AbstractSimpleGraph, npartitions::Integer; alg = "recursive",
kwargs...
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module NamedGraphsSimpleGraphAlgorithmsExt
using Graphs: AbstractGraph, dst, edges, edgetype, src, vertices
using NamedGraphs.GraphsExtensions: GraphsExtensions
using NamedGraphs: AbstractNamedGraph, decode_vertex, encoded_graph
using SimpleGraphAlgorithms: SimpleGraphAlgorithms
using SimpleGraphs: UndirectedGraph, add!
Expand Down
4 changes: 2 additions & 2 deletions ext/NamedGraphsSymRCMExt/NamedGraphsSymRCMExt.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module NamedGraphsSymRCMExt
using Graphs: AbstractGraph, adjacency_matrix
using NamedGraphs.GraphsExtensions: GraphsExtensions
using NamedGraphs: NamedGraphs
using SymRCM: SymRCM

function GraphsExtensions.symrcm_perm(graph::AbstractGraph)
function NamedGraphs.symrcm_perm(graph::AbstractGraph)
return SymRCM.symrcm(adjacency_matrix(graph))
end
end
33 changes: 0 additions & 33 deletions src/GraphsExtensions/GraphsExtensions.jl

This file was deleted.

19 changes: 12 additions & 7 deletions src/NamedGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export ⊔, AbstractNamedGraph, NamedDiGraph, NamedEdge, NamedGraph,
similar_graph, spanning_forest, spanning_tree, subgraph, undirected_graph,
vertextype
if VERSION >= v"1.11.0-DEV.469"
eval(Meta.parse("public GraphsExtensions, PartitionedGraphs"))
eval(Meta.parse("public PartitionedGraphs"))
# The encode and decode interface is what a new `AbstractNamedGraph` overloads,
# so it is public rather than exported.
# `to_graph_index` is an indexing extension point that graph and index types
Expand All @@ -46,12 +46,17 @@ if VERSION >= v"1.11.0-DEV.469"
end

include("similartype.jl")
include("GraphsExtensions/GraphsExtensions.jl")
# The `GraphsExtensions` names re-exported below, listed here rather than relying
# on the per-file imports that happen to bring them into scope.
using .GraphsExtensions: boundary_edges, convert_vertextype, default_root_vertex,
in_incident_edges, incident_edges, is_leaf_vertex, leaf_vertices, post_order_dfs_edges,
post_order_dfs_vertices, similar_graph, subgraph, vertextype
include("graphsextensions/graphgenerators.jl")
include("graphsextensions/abstractgraph.jl")
include("graphsextensions/abstracttrees.jl")
include("graphsextensions/boundary.jl")
include("graphsextensions/neighbors.jl")
include("graphsextensions/shortestpaths.jl")
include("graphsextensions/symrcm.jl")
include("graphsextensions/partitioning.jl")
include("graphsextensions/trees_and_forests.jl")
include("graphsextensions/simplegraph.jl")
include("graphsextensions/arrange_edges.jl")
include("utils.jl")
include("abstractnamededge.jl")
include("namededge.jl")
Expand Down
12 changes: 5 additions & 7 deletions src/PartitionedGraphs/abstractpartitionedgraph.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using ..NamedGraphs.GraphsExtensions:
GraphsExtensions, convert_vertextype, not_implemented, subgraph
using ..NamedGraphs:
AbstractNamedGraph, NamedDiGraph, NamedGraph, NamedGraphs, get_graph_index
using ..NamedGraphs: AbstractNamedGraph, NamedDiGraph, NamedGraph, NamedGraphs,
convert_vertextype, get_graph_index, not_implemented, subgraph
using Dictionaries: Dictionary
using Graphs: Graphs, AbstractEdge, AbstractGraph, AbstractSimpleGraph, add_vertex!, dst,
edgetype, has_vertex, is_directed, rem_vertex!, src, vertices
Expand Down Expand Up @@ -133,7 +131,7 @@ of [`QuotientEdge`](@ref)s; the concrete type is not part of the interface, and
the result may be a view into `graph`, so do not modify it or use it after
mutating `graph`.

Keyword arguments are forwarded to `GraphsExtensions.boundary_edges`, in
Keyword arguments are forwarded to `boundary_edges`, in
particular `dir`, which selects the edge direction to consider in a directed
graph.
"""
Expand Down Expand Up @@ -263,10 +261,10 @@ Base.copy(::AbstractPartitionedGraph) = not_implemented()
function unpartitioned_graph_type(::Type{<:AbstractPartitionedGraph})
return not_implemented()
end
function GraphsExtensions.directed_graph_type(::Type{<:AbstractPartitionedGraph})
function NamedGraphs.directed_graph_type(::Type{<:AbstractPartitionedGraph})
return not_implemented()
end
function GraphsExtensions.undirected_graph_type(::Type{<:AbstractPartitionedGraph})
function NamedGraphs.undirected_graph_type(::Type{<:AbstractPartitionedGraph})
return not_implemented()
end

Expand Down
11 changes: 5 additions & 6 deletions src/PartitionedGraphs/partitionedgraph.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ..NamedGraphs.GraphsExtensions: GraphsExtensions, boundary_edges, directed_graph_type,
is_self_loop, partition_vertices, undirected_graph_type, vertextype
using ..NamedGraphs: NamedEdge, NamedGraph, NamedGraphs
using ..NamedGraphs: NamedEdge, NamedGraph, NamedGraphs, boundary_edges,
directed_graph_type, is_self_loop, partition_vertices, undirected_graph_type, vertextype
using Dictionaries: Dictionary
using Graphs: AbstractEdge, AbstractGraph, add_edge!, dst, edges, edgetype, has_edge,
induced_subgraph, src, vertices
Expand All @@ -25,7 +24,7 @@ land in exactly one quotient vertex.

Passing `partitioned_vertices` alone gives the discrete partitioning of an
edgeless graph. Passing `graph` alone partitions with
`GraphsExtensions.partition_vertices`, which the keyword arguments go to: it
`partition_vertices`, which the keyword arguments go to: it
needs either `npartitions` or `nvertices_per_partition`, and a backend such as
Metis.jl loaded.

Expand Down Expand Up @@ -249,15 +248,15 @@ function NamedGraphs.directed_graph(g::PartitionedGraph)
dg = NamedGraphs.directed_graph(unpartitioned_graph(g))
return PartitionedGraph(dg, partitioned_vertices(g))
end
function GraphsExtensions.undirected_graph_type(
function NamedGraphs.undirected_graph_type(
type::Type{<:PartitionedGraph{V, PV}}
) where {V, PV}
UG = undirected_graph_type(unpartitioned_graph_type(type))
QG = undirected_graph_type(quotient_graph_type(type))
P = fieldtype(type, :partitioned_vertices)
return PartitionedGraph{V, PV, UG, QG, P}
end
function GraphsExtensions.directed_graph_type(
function NamedGraphs.directed_graph_type(
type::Type{<:PartitionedGraph{V, PV}}
) where {V, PV}
DG = directed_graph_type(unpartitioned_graph_type(type))
Expand Down
5 changes: 2 additions & 3 deletions src/PartitionedGraphs/quotientedge.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ..NamedGraphs.GraphsExtensions: GraphsExtensions, not_implemented
using ..NamedGraphs: AbstractEdges, AbstractNamedEdge, AbstractNamedGraph, Edges,
NamedGraphs, parent_graph_indices, rem_edges!, to_edges
NamedGraphs, not_implemented, parent_graph_indices, rem_edges!, to_edges
using Graphs: Graphs, AbstractEdge, AbstractGraph, dst, has_edge, ne, src

struct QuotientEdgeSlice{V, E, GI <: AbstractEdges{V, E}} <: AbstractEdges{V, E}
Expand Down Expand Up @@ -177,7 +176,7 @@ Graphs.edgetype(::Type{<:QuotientEdgeEdge{V, E}}) where {V, E} = E
Graphs.edgetype(::Type{<:QuotientEdgeEdge{V}}) where {V} = AbstractNamedEdge{V}
Graphs.edgetype(::Type{<:QuotientEdgeEdge}) = AbstractNamedEdge

GraphsExtensions.vertextype(::Type{<:QuotientEdgeEdge{V, E}}) where {V, E} = V
NamedGraphs.vertextype(::Type{<:QuotientEdgeEdge{V, E}}) where {V, E} = V

quotient_edgetype(::Type{<:QuotientEdgeEdge{V, E, QE}}) where {V, E, QE} = QE

Expand Down
7 changes: 3 additions & 4 deletions src/PartitionedGraphs/quotientvertex.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ..NamedGraphs.GraphsExtensions: GraphsExtensions, subgraph
using ..NamedGraphs: AbstractNamedGraph, AbstractVertices, Edges, NamedGraphs, Vertices,
parent_graph_indices, to_graph_index, to_vertices
parent_graph_indices, subgraph, to_graph_index, to_vertices
using Graphs: Graphs, AbstractGraph, induced_subgraph, nv

struct QuotientVertexSlice{V, GI <: AbstractVertices{V}} <: AbstractVertices{V}
Expand Down Expand Up @@ -128,8 +127,8 @@ function Base.getindex(qv::QuotientVertex, v::Vertices)
return QuotientVertexVertices(qv.vertex, v.vertices)
end

GraphsExtensions.vertextype(::Type{<:QuotientVertexVertex{V}}) where {V} = V
GraphsExtensions.vertextype(::Type{<:QuotientVertexVertex}) = Any
NamedGraphs.vertextype(::Type{<:QuotientVertexVertex{V}}) where {V} = V
NamedGraphs.vertextype(::Type{<:QuotientVertexVertex}) = Any

quotient_vertextype(::Type{<:QuotientVertexVertex{V, QV}}) where {V, QV} = QV

Expand Down
9 changes: 4 additions & 5 deletions src/PartitionedGraphs/quotientview.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ..NamedGraphs:
NamedGraph, encoded_graph_type, induced_subgraph_from_vertices, similar_type
using .GraphsExtensions: directed_graph_type, undirected_graph_type
using ..NamedGraphs: NamedGraph, directed_graph_type, encoded_graph_type,
induced_subgraph_from_vertices, similar_type, undirected_graph_type
using Graphs: AbstractGraph, edges, has_edge, rem_edge!, rem_vertex!, vertices

"""
Expand Down Expand Up @@ -71,10 +70,10 @@ function NamedGraphs.encoded_graph_type(type::Type{<:QuotientView})
return encoded_graph_type(quotient_graph_type(parent_graph_type(type)))
end

function NamedGraphs.GraphsExtensions.directed_graph_type(type::Type{<:QuotientView})
function NamedGraphs.directed_graph_type(type::Type{<:QuotientView})
return directed_graph_type(quotient_graph_type(parent_graph_type(type)))
end
function NamedGraphs.GraphsExtensions.undirected_graph_type(type::Type{<:QuotientView})
function NamedGraphs.undirected_graph_type(type::Type{<:QuotientView})
return undirected_graph_type(quotient_graph_type(parent_graph_type(type)))
end

Expand Down
15 changes: 7 additions & 8 deletions src/abstractnamededge.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using .GraphsExtensions: GraphsExtensions, convert_vertextype
using Graphs: Graphs, AbstractEdge, dst, src

abstract type AbstractNamedEdge{V} <: AbstractEdge{V} end
Expand All @@ -10,12 +9,12 @@ Graphs.dst(e::AbstractNamedEdge) = not_implemented()

AbstractNamedEdge(e::AbstractNamedEdge) = e

function GraphsExtensions.convert_vertextype(
function convert_vertextype(
::Type{V}, E::Type{<:AbstractNamedEdge{V}}
) where {V}
return E
end
function GraphsExtensions.convert_vertextype(::Type, E::Type{<:AbstractNamedEdge})
function convert_vertextype(::Type, E::Type{<:AbstractNamedEdge})
return not_implemented()
end

Expand All @@ -39,15 +38,15 @@ function Base.:(==)(e1::AbstractNamedEdge, e2::AbstractNamedEdge)
end
Base.hash(e::AbstractNamedEdge, h::UInt) = hash(src(e), hash(dst(e), h))

# TODO: Define generic version in `GraphsExtensions`.
# TODO: Define generic `set_vertices` in `GraphsExtensions`.
# TODO: Define generic version.
# TODO: Define generic `set_vertices`.
set_src(e::AbstractNamedEdge, src) = set_vertices(e, src, dst(e))
# TODO: Define generic version in `GraphsExtensions`.
# TODO: Define generic `set_vertices` in `GraphsExtensions`.
# TODO: Define generic version.
# TODO: Define generic `set_vertices`.
set_dst(e::AbstractNamedEdge, dst) = set_vertices(e, src(e), dst)

function rename_vertices(f::Function, e::AbstractNamedEdge)
# TODO: Define generic `set_vertices` in `GraphsExtensions`.
# TODO: Define generic `set_vertices`.
return set_vertices(e, f(src(e)), f(dst(e)))
end

Expand Down
10 changes: 4 additions & 6 deletions src/abstractnamedgraph.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using .GraphsExtensions: GraphsExtensions, all_edges, directed_graph_type, incident_edges,
partition_vertices, similar_graph, subgraph, undirected_graph_type
using Dictionaries: Dictionary, set!
using Graphs: Graphs, AbstractGraph, AbstractSimpleGraph, IsDirected, SimpleDiGraph,
SimpleEdge, SimpleGraph, a_star, add_edge!, adjacency_matrix, bfs_parents, blockdiag,
Expand Down Expand Up @@ -180,7 +178,7 @@ julia> [decode_vertex(g, c) for c in 1:nv(g)]
Graphs.vertices(graph::AbstractNamedGraph) = NamedVerticesView(graph)

# TODO: Is this a good definition? Maybe make it generic to any graph?
function GraphsExtensions.permute_vertices(graph::AbstractNamedGraph, permutation)
function permute_vertices(graph::AbstractNamedGraph, permutation)
return subgraph(graph, map(c -> decode_vertex(graph, c), permutation))
end

Expand All @@ -192,8 +190,8 @@ end
# In terms of `encoded_graph_type`
# is_directed(::Type{<:AbstractNamedGraph}) = not_implemented()

GraphsExtensions.convert_vertextype(::Type{V}, g::AbstractNamedGraph{V}) where {V} = g
function GraphsExtensions.convert_vertextype(vertextype::Type, graph::AbstractNamedGraph)
convert_vertextype(::Type{V}, g::AbstractNamedGraph{V}) where {V} = g
function convert_vertextype(vertextype::Type, graph::AbstractNamedGraph)
new_vertices = map(c -> decode_vertex(graph, c), vertices(encoded_graph(graph)))
return namedgraph(copy(encoded_graph(graph)), convert(Vector{vertextype}, new_vertices))
end
Expand Down Expand Up @@ -491,7 +489,7 @@ function Graphs.mincut(graph::AbstractNamedGraph, distmx::AbstractMatrix{<:Numbe
end

# TODO: Make this more generic?
function GraphsExtensions.partition_vertices(
function partition_vertices(
graph::AbstractNamedGraph; npartitions = nothing, nvertices_per_partition = nothing,
kwargs...
)
Expand Down
Loading