-
Notifications
You must be signed in to change notification settings - Fork 345
Refactor MG neighborhood sampling and add SG implementation #2285
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
Merged
rapids-bot
merged 28 commits into
rapidsai:branch-22.06
from
jnke2016:branch-22.06-fea_neighborhood_sampling
Jun 1, 2022
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
98fd1b2
move the current implementation of mg neighborhood sampling to proto
063e443
remove experimental prefix
e6ed994
refactor mg neighborhood sampling bindings
4581645
add and test mechanism for creating graph with edge index as weight
ChuckHastings 57680f6
Merge mechanism for creating graph with edge index as weight
16cea30
rename create*_with_ids to create*_with_edge_ids
ChuckHastings 2fd99b5
rename create*_with_ids to create*_with_edge_ids from Chuck
3f90963
update python bindings to create graph with edge index as weight
d460193
fix bug in MG case... cugraph_ops function doesn't handle an empty re…
ChuckHastings c7d0a11
merge bug fix in MG case by Chuck
e6210a2
Merge remote-tracking branch 'upstream/branch-22.06' into branch-22.0…
3b76a49
add bindings for SG uniform_neighbor_sample
e3b5fe4
Merge remote-tracking branch 'upstream/branch-22.06' into branch-22.0…
9933120
remove debug print
604ab0f
update pylibcugraph uniform_neighbor_sample tests because of the API …
c579261
drop the directory proto
626a833
enable support for weigths
6d91c39
remove debug prints, address PR comments
f038688
move uniform_neighbor_sample to stable API, convert edge_ids to weigh…
d97ce67
update uniform neighborhood sampling tests
c9482c2
merge latest change and update branch
jnke2016 720b05d
remove uniform neighbor sample older mechanism
78f7dd6
add end of line
ce97653
resolve merge conflict
jnke2016 7fdc09d
remove merge labels
jnke2016 b629ca9
remove outdated fixme
jnke2016 8a8f063
remove unused import
jnke2016 1af8e7b
add end of line
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
132 changes: 132 additions & 0 deletions
132
python/cugraph/cugraph/sampling/uniform_neighbor_sample.py
This file contains hidden or 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,132 @@ | ||
| # Copyright (c) 2022, 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 pylibcugraph import (ResourceHandle, | ||
| GraphProperties, | ||
| SGGraph, | ||
| ) | ||
| from pylibcugraph import uniform_neighbor_sample as \ | ||
| pylibcugraph_uniform_neighbor_sample | ||
|
|
||
| import numpy | ||
|
|
||
| import cudf | ||
|
|
||
|
|
||
| def uniform_neighbor_sample(G, | ||
| start_list, | ||
| fanout_vals, | ||
| with_replacement=True, | ||
| is_edge_ids=False): | ||
| """ | ||
| Does neighborhood sampling, which samples nodes from a graph based on the | ||
| current node's neighbors, with a corresponding fanout value at each hop. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| G : cugraph.Graph | ||
| cuGraph graph, which contains connectivity information as dask cudf | ||
| edge list dataframe | ||
|
|
||
| start_list : list or cudf.Series (int32) | ||
| a list of starting vertices for sampling | ||
|
|
||
| fanout_vals : list (int32) | ||
| List of branching out (fan-out) degrees per starting vertex for each | ||
| hop level. | ||
|
|
||
| with_replacement: bool, optional (default=True) | ||
| Flag to specify if the random sampling is done with replacement | ||
|
|
||
| Returns | ||
| ------- | ||
| result : cudf.DataFrame | ||
| GPU data frame containing two cudf.Series | ||
|
|
||
| df['sources']: cudf.Series | ||
| Contains the source vertices from the sampling result | ||
| df['destinations']: cudf.Series | ||
| Contains the destination vertices from the sampling result | ||
| df['indices']: cudf.Series | ||
| Contains the indices from the sampling result for path | ||
| reconstruction | ||
| """ | ||
|
|
||
| if isinstance(start_list, int): | ||
| start_list = [start_list] | ||
|
|
||
| if isinstance(start_list, list): | ||
| start_list = cudf.Series(start_list, dtype="int32") | ||
| if start_list.dtype != "int32": | ||
| raise ValueError(f"'start_list' must have int32 values, " | ||
| f"got: {start_list.dtype}") | ||
|
|
||
| # fanout_vals must be a host array! | ||
| # FIXME: ensure other sequence types (eg. cudf Series) can be handled. | ||
| if isinstance(fanout_vals, list): | ||
| fanout_vals = numpy.asarray(fanout_vals, dtype="int32") | ||
| else: | ||
| raise TypeError("fanout_vals must be a list, " | ||
| f"got: {type(fanout_vals)}") | ||
|
|
||
| if G.renumbered is True: | ||
| if isinstance(start_list, cudf.DataFrame): | ||
| start_list = G.lookup_internal_vertex_id( | ||
| start_list, start_list.columns) | ||
| else: | ||
| start_list = G.lookup_internal_vertex_id(start_list) | ||
|
|
||
| srcs = G.edgelist.edgelist_df['src'] | ||
| dsts = G.edgelist.edgelist_df['dst'] | ||
| weights = G.edgelist.edgelist_df['weights'] | ||
| weight_t = weights.dtype | ||
|
|
||
| if weight_t == "int32": | ||
| weights = weights.astype("float32") | ||
| if weight_t == "int64": | ||
| weights = weights.astype("float64") | ||
|
|
||
| if srcs.dtype != 'int32': | ||
| raise ValueError(f"Graph vertices must have int32 values, " | ||
| f"got: {srcs.dtype}") | ||
|
|
||
| resource_handle = ResourceHandle() | ||
| graph_props = GraphProperties(is_multigraph=G.is_multigraph()) | ||
| store_transposed = False | ||
| renumber = False | ||
| do_expensive_check = False | ||
|
|
||
| sg = SGGraph(resource_handle, graph_props, srcs, dsts, weights, | ||
| store_transposed, renumber, do_expensive_check) | ||
|
|
||
| sources, destinations, indices = \ | ||
| pylibcugraph_uniform_neighbor_sample(resource_handle, sg, start_list, | ||
| fanout_vals, with_replacement, | ||
| do_expensive_check) | ||
|
|
||
| df = cudf.DataFrame() | ||
| df["sources"] = sources | ||
| df["destinations"] = destinations | ||
| df["indices"] = indices | ||
| if weight_t == "int32": | ||
| df["indices"] = indices.astype("int32") | ||
| elif weight_t == "int64": | ||
| df["indices"] = indices.astype("int64") | ||
| else: | ||
| df["indices"] = indices | ||
|
|
||
| if G.renumbered: | ||
| df = G.unrenumber(df, "sources", preserve_order=True) | ||
| df = G.unrenumber(df, "destinations", preserve_order=True) | ||
|
|
||
| return df | ||
This file contains hidden or 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
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.
Might want to add both this SG and the MG
uniform_neighbor_sampleto the API docs