-
Notifications
You must be signed in to change notification settings - Fork 309
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: adds ancestors
, descendants
, and BFS algos
#4029
Merged
rapids-bot
merged 10 commits into
rapidsai:branch-24.02
from
eriknw:ancestors_and_descendants
Dec 21, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22e317c
nx-cugraph: add `ancestors` and `descendants`
eriknw da1c3a1
Add `bfs_successors` and `bfs_predecessors`; is there a bug in `plc.b…
eriknw 601f8b3
Add bfs_edges, bfs_tree, generic_bfs_edges
eriknw d36af26
Add `descendants_at_distance` and `bfs_layers`
eriknw 0daffcc
Clean up based on review
eriknw a19ed3d
Merge branch 'branch-24.02' into ancestors_and_descendants
eriknw 4fc915e
Merge branch 'branch-24.02' into ancestors_and_descendants
eriknw 04dcf6d
Skip tests that may OOM, but also test them individually in CI
eriknw cf14f99
Merge branch 'branch-24.02' into ancestors_and_descendants
eriknw 2742cf7
oops fix
eriknw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import cupy as cp | ||
import networkx as nx | ||
import numpy as np | ||
import pylibcugraph as plc | ||
|
||
from nx_cugraph.convert import _to_graph | ||
from nx_cugraph.utils import index_dtype, networkx_algorithm | ||
|
||
__all__ = [ | ||
"descendants", | ||
"ancestors", | ||
] | ||
|
||
|
||
def _ancestors_and_descendants(G, source, *, is_ancestors): | ||
G = _to_graph(G) | ||
if source not in G: | ||
hash(source) # To raise TypeError if appropriate | ||
rlratzel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise nx.NetworkXError( | ||
f"The node {source} is not in the {G.__class__.__name__.lower()}." | ||
) | ||
src_index = source if G.key_to_id is None else G.key_to_id[source] | ||
distances, predecessors, node_ids = plc.bfs( | ||
handle=plc.ResourceHandle(), | ||
graph=G._get_plc_graph(switch_indices=is_ancestors), | ||
sources=cp.array([src_index], dtype=index_dtype), | ||
direction_optimizing=False, | ||
depth_limit=-1, | ||
compute_predecessors=False, | ||
do_expensive_check=False, | ||
) | ||
mask = (distances != np.iinfo(distances.dtype).max) & (distances != 0) | ||
return G._nodearray_to_set(node_ids[mask]) | ||
|
||
|
||
@networkx_algorithm | ||
def descendants(G, source): | ||
return _ancestors_and_descendants(G, source, is_ancestors=False) | ||
|
||
|
||
@networkx_algorithm | ||
def ancestors(G, source): | ||
return _ancestors_and_descendants(G, source, is_ancestors=True) |
13 changes: 13 additions & 0 deletions
13
python/nx-cugraph/nx_cugraph/algorithms/traversal/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from .breadth_first_search import * |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave this in place in order to get this PR merged, but I think this is masking a bug (likely in pylibcugraph/libcugraph, not in nx-cugraph).
I filed this issue and I'll open a PR to remove these lines and the skipped tests separately, which will be merged when the bug is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR to eventually fix the bug is #4068