Skip to content

WIP: Add an is_chordal algorithm #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Luis-Varona
Copy link

We implement Tarjan and Yannakakis (1984)'s MCS algorithm, taking inspiration from the existing NetworkX implementation. Everything is done except for example doctests in src/chordality.jl and unit tests in test/chordality.jl. (This PR is part of a new suite of algorithms outlined in issue #431.)

We implement Tarjan and Yannakakis (1984)'s MCS algorithm, taking inspiration from the existing NetworkX implementation. Everything is done except for example doctests in src/chordality.jl and unit tests in test/chordality.jl. (This PR is part of a new suite of algorithms outlined in issue JuliaGraphs#431.)
Copy link

codecov bot commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.

Project coverage is 97.09%. Comparing base (c001dab) to head (eeb10f4).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/chordality.jl 0.00% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #434      +/-   ##
==========================================
- Coverage   97.41%   97.09%   -0.32%     
==========================================
  Files         120      121       +1     
  Lines        6953     6982      +29     
==========================================
+ Hits         6773     6779       +6     
- Misses        180      203      +23     

☔ 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.

@simonschoelly
Copy link
Member

Do you by any change know where I could find a public accessible version of that paper? My usual methods did not help.

@Krastanov
Copy link
Member

out.pdf

The paper is attached here, courtesy of the UMass library.

@Luis-Varona
Copy link
Author

out.pdf

The paper is attached here, courtesy of the UMass library.

Wonderful, @Krastanov, thanks!

@Luis-Varona
Copy link
Author

@simonschoelly, just wanted to let you know I certainly haven't abandoned this PR. I was busy with work this past week and I'm at a conference this weekend, but I'll get back to it shortly. I've looked over your comments and it shouldn't be many more changes at all anyway, hehe.

Originally, we restricted the input type for is_chordal to AbstractSimpleGraph to rule out parallel edges, but some other graph types we would like to support (such as SimpleWeightedGraph) are of the more general AbstractGraph type. It turns out the current AbstractGraph interface aleady does not support parallel edges, so there is no worry here--it is already stated in the Implementation Notes anyway that is_chordal should not take in graphs with parallel edges as input.
@Luis-Varona
Copy link
Author

@simonschoelly, just changed the input type from AbstractSimpleGraph to AbstractGraph. Anything else you'd like me to change before I get around to adding tests?

@Luis-Varona
Copy link
Author

Wait—I just remembered your comment about induced subgraphs. I'll think about that and get back to you I was largely just porting over networkx's implementation, which does do this, but it probably really isn't optimal.

@simonschoelly
Copy link
Member

@simonschoelly, just wanted to let you know I certainly haven't abandoned this PR. I was busy with work this past week and I'm at a conference this weekend, but I'll get back to it shortly. I've looked over your comments and it shouldn't be many more changes at all anyway, hehe.

Don't worry - we are quite slow with reviewing PRs here :D

Originally mirroring the networkx implementation, we created a new AbstractGraph object every time we tested subsequent neighbors in the potential PEO with the induced_subgraph function. This commit makes our implementation more performant by simply taking the vertex (sub)set and checking to see if all pairs are adjacent via iteration.

Additionally, we change inconsistent naming in certain parts ('node' vs 'vertex'), changing everything to 'vertex' where relevant.
@Luis-Varona
Copy link
Author

@simonschoelly @Krastanov I've fixed the issue regarding unnecessary allocations with induced_subgraph, instead having the _induces_clique helper take in a vertex subset and, in the context of the original graph, confirm that all possible edges exist. @simonschoelly, is there anything else I should change before I start on unit tests and docstring examples?

@Luis-Varona
Copy link
Author

Hi @simonschoelly, just following up. Is everything good enough for me to conclude my work on the actual logic and start on the docstring and unit tests? 🙂

@Luis-Varona
Copy link
Author

What do you think, @Krastanov? 🙂

@Krastanov
Copy link
Member

Thanks, @Luis-Varona ! No need to wait for anything else to be finished before adding tests on my end. I actually frequently refuse to review PRs before the tests are added, as I judge quality first by the tests and documentation.

I am adding some quality of life improvements to IGraphs.jl that should make it easy to test against their implementation as well. I will post it here shortly.

@Krastanov
Copy link
Member

Just to clarify: while I might have a particular style of review, that style is not shared by everyone, and please do not hesitate to request me approaching this differently.

@Krastanov
Copy link
Member

IGraphs.jl just got a new release in which you can use the following in order to test your implementation against the ones in the igraph C library https://igraph.org/c/html/latest/igraph-Structural.html#igraph_is_chordal

the_graph = random_regular_graph(10,5)
LibIGraph.is_chordal(IGraph(the_graph), IGNull(), IGNull(), IGNull(), IGNull())

I frequently use random sampling over appropriate ensembles as a way to test that two implementations give the same result. This can be useful here as well.

It can also be fun to compare performance (just make sure to not count the time to convert the graph from one format to the other).

@simonschoelly
Copy link
Member

There is also https://github.com/wangjie212/ChordalGraph

@simonschoelly
Copy link
Member

You resolved that conversation but might have overlooked what I wrote there about using the IsDirected trait.

@Luis-Varona
Copy link
Author

Luis-Varona commented Jun 30, 2025

Thanks for the info, @Krastanov!

You resolved that conversation but might have overlooked what I wrote there about using the IsDirected trait.

So I did, @simonschoelly. Sorry—I must've overlooked that. I expect that sort of fix shouldn't take long, anyway, so I'll try to take a crack at it later this week.

I suppose regardless of the internal workings of our version of is_chordal, I can also start right away on the test suite. Testing against only one of the two libraries suggested above (i.e., ChordalGraphs.jl or IGraphs.jl, not both) should be sufficient, right?

Edit: Certainly, benchmarking our implementation against both of the above would be useful, but I'm thinking I'll leave that to the benchmark/ folder and just use one or the other as a point of comparison in the actual test suite in test/.

@Krastanov
Copy link
Member

Yes, no need to test against multiple other libraries. Your own correctness tests are probably most important -- testing against another library with a bunch of random samples just provides a bit more certainty that we are not missing anything.

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.

3 participants