Skip to content

feat : Add VNGraphs.jl stubs for chromatic_number and edge_chromatic_number#507

Open
mahmudsudo wants to merge 4 commits intoJuliaGraphs:masterfrom
mahmudsudo:very_nauty
Open

feat : Add VNGraphs.jl stubs for chromatic_number and edge_chromatic_number#507
mahmudsudo wants to merge 4 commits intoJuliaGraphs:masterfrom
mahmudsudo:very_nauty

Conversation

@mahmudsudo
Copy link
Copy Markdown

@mahmudsudo mahmudsudo commented Mar 30, 2026

Declares chromatic_number and edge_chromatic_number in Graphs.jl with helpful error hints directing users to install VNGraphs.jl for the fast C-backed very_nauty implementations.

Includes unit tests asserting the stubs throw the expected errors.
VNGraph pr : JuliaGraphs/VNGraphs.jl#26

closes #448

Declares chromatic_number and edge_chromatic_number in Graphs.jl with
helpful error hints directing users to install VNGraphs.jl for the
fast C-backed very_nauty implementations.

Includes unit tests asserting the stubs throw the expected errors.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 30, 2026

Benchmark Results (Julia v1)

Time benchmarks
master 54acbad... master / 54acbad...
centrality/digraphs/betweenness_centrality 16.2 ± 0.53 ms 16 ± 0.4 ms 1.01 ± 0.042
centrality/digraphs/closeness_centrality 11.2 ± 0.41 ms 11.1 ± 0.38 ms 1.01 ± 0.05
centrality/digraphs/degree_centrality 2.05 ± 1.6 μs 1.97 ± 0.16 μs 1.04 ± 0.8
centrality/digraphs/katz_centrality 0.865 ± 0.062 ms 0.851 ± 0.056 ms 1.02 ± 0.099
centrality/digraphs/pagerank 0.0367 ± 0.0045 ms 0.0362 ± 0.00058 ms 1.01 ± 0.12
centrality/graphs/betweenness_centrality 28.9 ± 1.2 ms 28.8 ± 1.3 ms 1 ± 0.061
centrality/graphs/closeness_centrality 21.5 ± 0.27 ms 21.1 ± 0.24 ms 1.02 ± 0.017
centrality/graphs/degree_centrality 1.45 ± 0.16 μs 1.49 ± 0.15 μs 0.973 ± 0.15
centrality/graphs/katz_centrality 1.02 ± 0.048 ms 1.02 ± 0.044 ms 0.998 ± 0.064
connectivity/digraphs/strongly_connected_components 0.0429 ± 0.0015 ms 0.0429 ± 0.0011 ms 1 ± 0.043
connectivity/graphs/connected_components 24.3 ± 0.97 μs 27.2 ± 0.66 μs 0.893 ± 0.042
core/edges/digraphs 7.84 ± 0.11 μs 7.02 ± 0.011 μs 1.12 ± 0.016
core/edges/graphs 17.1 ± 0.1 μs 15.9 ± 0.13 μs 1.08 ± 0.011
core/has_edge/digraphs 5.19 ± 0.41 μs 5.11 ± 0.34 μs 1.02 ± 0.11
core/has_edge/graphs 5.59 ± 0.68 μs 5.51 ± 0.36 μs 1.01 ± 0.14
core/nv/digraphs 0.37 ± 0.01 μs 0.371 ± 0.011 μs 0.997 ± 0.04
core/nv/graphs 0.381 ± 0.011 μs 0.391 ± 0.01 μs 0.974 ± 0.038
edges/fille 8.27 ± 1 μs 7.79 ± 1 μs 1.06 ± 0.19
edges/fillp 5.38 ± 4.4 μs 4.72 ± 3.7 μs 1.14 ± 1.3
edges/tsume 2.5 ± 0.031 μs 2.73 ± 0.05 μs 0.919 ± 0.02
edges/tsump 2.56 ± 0.16 μs 2.6 ± 0.06 μs 0.988 ± 0.066
insertions/SG(n,e) Generation 24.3 ± 3.5 ms 24.2 ± 3.4 ms 1 ± 0.2
parallel/egonet/twohop 0.287 ± 0.0033 s 0.287 ± 0.0034 s 1 ± 0.017
parallel/egonet/vertexfunction 2.18 ± 0.095 ms 2.17 ± 0.15 ms 1.01 ± 0.082
serial/egonet/twohop 0.287 ± 0.0018 s 0.288 ± 0.0041 s 0.995 ± 0.015
serial/egonet/vertexfunction 2.12 ± 0.085 ms 2.17 ± 0.24 ms 0.975 ± 0.12
traversals/digraphs/bfs_tree 0.0495 ± 0.004 ms 0.0497 ± 0.0032 ms 0.997 ± 0.1
traversals/digraphs/dfs_tree 0.0637 ± 0.0046 ms 0.0635 ± 0.0049 ms 1 ± 0.11
traversals/graphs/bfs_tree 0.0527 ± 0.0019 ms 0.0531 ± 0.0019 ms 0.994 ± 0.051
traversals/graphs/dfs_tree 0.0658 ± 0.0025 ms 0.066 ± 0.0024 ms 0.997 ± 0.052
time_to_load 0.526 ± 0.00031 s 0.526 ± 0.0031 s 1 ± 0.0059
Memory benchmarks
master 54acbad... master / 54acbad...
centrality/digraphs/betweenness_centrality 0.29 M allocs: 24 MB 0.29 M allocs: 24 MB 1
centrality/digraphs/closeness_centrality 18.6 k allocs: 14.5 MB 18.6 k allocs: 14.5 MB 1
centrality/digraphs/degree_centrality 8 allocs: 5.01 kB 8 allocs: 5.01 kB 1
centrality/digraphs/katz_centrality 2.63 k allocs: 2.83 MB 2.63 k allocs: 2.83 MB 1
centrality/digraphs/pagerank 21 allocs: 14.9 kB 21 allocs: 14.9 kB 1
centrality/graphs/betweenness_centrality 0.545 M allocs: 0.0313 GB 0.545 M allocs: 0.0313 GB 1
centrality/graphs/closeness_centrality 19.3 k allocs: 14 MB 19.3 k allocs: 14 MB 1
centrality/graphs/degree_centrality 10 allocs: 5.43 kB 10 allocs: 5.43 kB 1
centrality/graphs/katz_centrality 2.96 k allocs: 3.1 MB 2.96 k allocs: 3.1 MB 1
connectivity/digraphs/strongly_connected_components 1.05 k allocs: 0.075 MB 1.05 k allocs: 0.075 MB 1
connectivity/graphs/connected_components 0.061 k allocs: 22.5 kB 0.061 k allocs: 22.5 kB 1
core/edges/digraphs 3 allocs: 0.0938 kB 3 allocs: 0.0938 kB 1
core/edges/graphs 3 allocs: 0.0938 kB 3 allocs: 0.0938 kB 1
core/has_edge/digraphs 20 allocs: 12.6 kB 20 allocs: 12.6 kB 1
core/has_edge/graphs 28 allocs: 13.8 kB 28 allocs: 13.8 kB 1
core/nv/digraphs 3 allocs: 0.0938 kB 3 allocs: 0.0938 kB 1
core/nv/graphs 3 allocs: 0.0938 kB 3 allocs: 0.0938 kB 1
edges/fille 3 allocs: 0.153 MB 3 allocs: 0.153 MB 1
edges/fillp 3 allocs: 0.153 MB 3 allocs: 0.153 MB 1
edges/tsume 0 allocs: 0 B 0 allocs: 0 B
edges/tsump 0 allocs: 0 B 0 allocs: 0 B
insertions/SG(n,e) Generation 0.0465 M allocs: 10.9 MB 0.0465 M allocs: 11 MB 0.998
parallel/egonet/twohop 10 allocs: 0.0768 MB 10 allocs: 0.0768 MB 1
parallel/egonet/vertexfunction 10 allocs: 0.0768 MB 10 allocs: 0.0768 MB 1
serial/egonet/twohop 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
serial/egonet/vertexfunction 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
traversals/digraphs/bfs_tree 2.34 k allocs: 0.113 MB 2.34 k allocs: 0.113 MB 1
traversals/digraphs/dfs_tree 2.44 k allocs: 0.118 MB 2.44 k allocs: 0.118 MB 1
traversals/graphs/bfs_tree 2.52 k allocs: 0.121 MB 2.52 k allocs: 0.121 MB 1
traversals/graphs/dfs_tree 2.63 k allocs: 0.127 MB 2.63 k allocs: 0.127 MB 1
time_to_load 0.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.27%. Comparing base (ca5cbc3) to head (54acbad).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #507   +/-   ##
=======================================
  Coverage   97.27%   97.27%           
=======================================
  Files         126      127    +1     
  Lines        7674     7678    +4     
=======================================
+ Hits         7465     7469    +4     
  Misses        209      209           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mahmudsudo
Copy link
Copy Markdown
Author

@Krastanov

Copy link
Copy Markdown
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminder! We are a bit short staffed, so reminders like this are certainly appreciated and regrettably necessary (otherwise a lot of the volunteer reviewers just do not remember about a PR).

I have two main questions / suggestions before we continue with a more in-depth review.

  • The stubs should not be VNGraphs specific. I.e. these happen to be algorithms that are defined in VNGraphs.jl, but there might be other sources for them as well. Thus, we should organize them in a way that fits the overall API and file structure in terms of semantics, not in terms of provenance of the implementation.
  • There already seems to be a bit about coloring in Graphs.jl, so maybe we can organize these stubs appropriately around what is already present. There is for instance the function greedy_color and the struct Coloring.
  • There is also the library GraphsColoring.jl in this same organization that somewhat tries to follow the Graphs.jl API -- we need to decide whether the VNGraphs.jl hookup makes most sens in here or in GraphsColoring.jl. If it is in-here, it probably makes most sense to proceed with defining appropriate APIs and extending them. If it is in GraphsColoring.jl then once can do a pkgext in VNGraphs.jl for the already existing API in GraphsColoring.

@djukic14, could you chime in on your opinion on how to proceed. For context, Mahmud has been working on a few PRs in the ecosystem that are meant to provide a standard Graphs.jl API to wrappers around a number of other external libraries (lemon, very_naughty, igraph, etc).

Comment thread src/vngraphs_stubs.jl
Comment on lines +17 to +20
error(
"chromatic_number is not implemented in Graphs.jl. " *
"Please load VNGraphs.jl to use the very_nauty implementation.",
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a big fan of this style of defining functions to be extended. This function will get invalidated when another library gets imported, causing bad user experience (latency for imports/precompilation). I think a cleaner way to do this is to use an error hint defined in the __init__ function. The WeakDepHelpers.jl library is trying to automate some of this.

@djukic14
Copy link
Copy Markdown

@Krastanov @mahmudsudo I’d be happy to help integrate this into GraphsColoring.jl. I also think we should aim for a generic API (both here and in GraphsColoring.jl) so different implementations can plug in without being tied to a specific backend.

@Krastanov
Copy link
Copy Markdown
Member

@djukic14 , do you think the functions chromatic_number and edge_chromatic_number should live in the Graphs.jl namespace or in the GraphsColoring.jl namespace. We have the Coloring and greedy_color in the Graphs.jl namespace.

@djukic14
Copy link
Copy Markdown

@Krastanov for now it probably makes sense for these to live in Graphs.jl, but we should discuss whether (in a future breaking change) all coloring-related APIs should move to GraphsColoring.jl for consistency, though I’m unsure how the community would feel about that.

Copy link
Copy Markdown
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @djukic14 !

@mahmudsudo , given what was discussed, and given the existence of GraphsColoring.jl and GraphsOptim.jl with which we will need to coordinate in the future, how do you feel about the following (submitted as a new review so that the comments are grouped together, see comments)

Let's also start discussing how the bounty will be paid -- send me an email so that I can give you the details. I want to make sure you have them, as the payout processing from our nonprofit can be pretty slow (everyone is a volunteer here, as I have mentioned embarrassingly often :D )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now, let's keep the stubs private, so that it is not a breaking change when we decide how to incorporate them with GraphsOptim and GraphsColoring

i.e., we will not be including documentation pages and this one should be deleted

Comment thread src/Graphs.jl
Comment on lines +458 to +459
chromatic_number,
edge_chromatic_number
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not export them

Comment thread src/vngraphs_stubs.jl
Comment on lines +7 to +9
Note: This is a stub provided by `Graphs.jl`. For a concrete implementation,
please use the `VNGraphs.jl` package which provides a fast C implementation
via `very_nauty`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are including "notes" use the Documenter.jl note syntax that puts it in a separate panel

And let's make the API be chromatic_number(g, ::Algorithm) to clearly state that you need to specify an algorithm implementation. Mention VNGraphs.jl as one currently implemented option, but do not make it sound like it is the only one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the timeout should be an argument of the Algorithm type to keep things clean (so no need to mention it here)

Comment thread src/vngraphs_stubs.jl
Comment on lines +11 to +13
```julia
using VNGraphs
chromatic_number(g)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you include code in docstrings, make sure it is a doctest, so that it is automatically checked in case it might be outdated. Here we can probably just remove it altogether

Comment thread src/vngraphs_stubs.jl
Comment on lines +16 to +21
function chromatic_number(g::AbstractGraph, args...; kwargs...)
error(
"chromatic_number is not implemented in Graphs.jl. " *
"Please load VNGraphs.jl to use the very_nauty implementation.",
)
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function chromatic_number(g::AbstractGraph, args...; kwargs...)
error(
"chromatic_number is not implemented in Graphs.jl. " *
"Please load VNGraphs.jl to use the very_nauty implementation.",
)
end
function chromatic_number end

We want just to declare it as part of the namespace without giving it an implementation. No need to worry about adding error hints even, given that it is private for now

Comment thread src/vngraphs_stubs.jl
Comment on lines +23 to +41
"""
edge_chromatic_number(g, timeout=0)
Return the edge chromatic number of the graph `g`.
Note: This is a stub provided by `Graphs.jl`. For a concrete implementation,
please use the `VNGraphs.jl` package which provides a fast C implementation
via `very_nauty`.
```julia
using VNGraphs
edge_chromatic_number(g)
```
"""
function edge_chromatic_number(g::AbstractGraph, args...; kwargs...)
error(
"edge_chromatic_number is not implemented in Graphs.jl. " *
"Please load VNGraphs.jl to use the very_nauty implementation.",
)
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same changes to this one

Comment thread src/Graphs.jl
"""
Graphs
include("interface.jl")
include("vngraphs_stubs.jl")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these stubs are not VNGraphs specific, rather they are for coloring. Maybe we can name the file coloring or see if there is already existing file about these concepts?

Comment thread test/runtests.jl
"trees/prufer",
"experimental/experimental",
"planarity",
"vngraphs_stubs",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that these are kept private, I guess there are no new tests to be added

Comment thread CHANGELOG.md

## unreleased
- `is_articulation(g, v)` for checking whether a single vertex is an articulation point
- `chromatic_number` and `edge_chromatic_number` stubs (implemented in `VNGraphs.jl`)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call them declared private functions without any methods instead of stubs and point to VNGraphs.jl as one place that happens to implement methods, but do not make it sound like it is meant to be the only one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A reliable idiomatic wrapper for the C library very_nauty [$400]

3 participants