JuliaGraphs / JuliaGraphs/Graphs.jl
Add more convenience constructors
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 538
- Forks
- 128
- Avg merge
- 10h 25m
- Merged PRs (30d)
- 2
Description
The type GNNGraph from GraphNeuralNetworks.jl is a Graphs.AbstractGraphs and implements the corresponding interface, therefore it would be nice to make the following code work by providing an appropriate constructor:
julia> using GraphNeuralNetworks, Graphs
julia> g = GraphNeuralNetworks.rand_graph(10, 20)
GNNGraph:
num_nodes = 10
num_edges = 20
julia> g isa Graphs.AbstractGraph
true
julia> Graphs.SimpleGraph(g)
ERROR: MethodError: no method matching SimpleGraph(::GNNGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}})
Closest candidates are:
SimpleGraph(::Any, ::Array{Vector{T}, 1}) where T at ~/.julia/packages/Graphs/pxGmw/src/SimpleGraphs/simplegraph.jl:18
SimpleGraph() at ~/.julia/packages/Graphs/pxGmw/src/SimpleGraphs/simplegraph.jl:50
SimpleGraph(::SimpleGraph) at ~/.julia/packages/Graphs/pxGmw/src/SimpleGraphs/simplegraph.jl:115
...
Moreover, we could also have the following constructor:
julia> src, dest = edge_index(g)
([1, 1, 1, 1, 2, 2, 2, 5, 5, 5, 2, 3, 7, 10, 5, 6, 7, 6, 7, 9], [2, 3, 7, 10, 5, 6, 7, 6, 7, 9, 1, 1, 1, 1, 2, 2, 2, 5, 5, 5])
julia> SimpleGraph(src, dest)
ERROR: MethodError: no method matching SimpleGraph(::Vector{Int64}, ::Vector{Int64})
Closest candidates are:
SimpleGraph(::Any, ::Array{Vector{T}, 1}) where T at ~/.julia/packages/Graphs/pxGmw/src/SimpleGraphs/simplegraph.jl:18
which is more concise and discoverable than
julia> SimpleGraph(Edge.(src,dest))
{10, 10} undirected simple Int64 graph
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing GNNGraph, rand_graph, edge_index, and Graphs.SimpleGraph entry points, then inspect how Graphs currently constructs graphs from edges. Use the REPL examples in the issue as acceptance checks: conversion from GNNGraph and construction from source and destination vectors should work, while preserving the existing Edge-based form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100