Skip to content
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

nx-cugraph: add CC for undirected graphs to fix k-truss #3965

Merged
merged 5 commits into from
Oct 31, 2023

Conversation

eriknw
Copy link
Contributor

@eriknw eriknw commented Oct 31, 2023

Fixes #3963 and add connected_components, is_connected, node_connected_component, and number_connected_components.

Also updated _groupby to handle groups that are not consecutive integers starting with 0.

Also, plc.weakly_connected_components does not handle isolated nodes well, and I needed to handle this at the Python layer as was done in #3897

@eriknw eriknw requested a review from a team as a code owner October 31, 2023 03:21
Comment on lines +50 to +56
@number_connected_components._can_run
def _(G):
# NetworkX <= 3.2.1 does not check directedness for us
try:
return not G.is_directed()
except Exception:
return False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed this upstream here: networkx/networkx#7074

Copy link
Contributor

@rlratzel rlratzel left a comment

Choose a reason for hiding this comment

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

changes LGTM. Should there be a test for k_truss that passes

G=nx.Graph([(0,1), (1,2), (2,0), (3,4), (4,5), (5,3)])

and asserts that NotImplementedError is raised, which we then xfail when k_truss is updated?
OTOH, maybe that's overkill for (hopefully) temporary code that I'm assuming was at least manually tested? I'm fine either way.

@rlratzel rlratzel added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Oct 31, 2023
@eriknw
Copy link
Contributor Author

eriknw commented Oct 31, 2023

changes LGTM. Should there be a test for k_truss that passes

Thanks for providing a test case, but now we actually have the opposite problem: now we don't test the main branches of k_truss! All test graphs apparently have more than 1 connected components.

@rlratzel
Copy link
Contributor

Thanks for providing a test case, but now we actually have the opposite problem: now we don't test the main branches of k_truss! All test graphs apparently have more than 1 connected components.

Karate club has only 1 CC; maybe add a quick test for that too to make sure we at least exercise nx_cugraph->PLC->libcugraph and back?

@eriknw
Copy link
Contributor Author

eriknw commented Oct 31, 2023

Karate club has only 1 CC; maybe add a quick test for that too to make sure we at least exercise nx_cugraph->PLC->libcugraph and back?

Excellent suggestion, although we'd need #3954 to test with karate club (b/c it has string node values). Test added, and code is exercised 👍

I'm looking forward to having more graph generators to enable more comparison testing of algorithms.

Comment on lines +37 to +39
def _groupby(
groups: cp.ndarray, values: cp.ndarray, groups_are_canonical: bool = False
) -> dict[int, cp.ndarray]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm really happy with this groupby implementation btw. Using prepend with cp.diff is a little slow compared to cp.diff w/o it, but this isn't where the bulk of the time is spent.

Copy link
Contributor

@rlratzel rlratzel 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 adding the test.

@rlratzel
Copy link
Contributor

/merge

@rapids-bot rapids-bot bot merged commit eb1e515 into rapidsai:branch-23.12 Oct 31, 2023
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add limitation of one connected component within input Graph from nx_cugraph.k_truss
2 participants