How to get the k-hop neighbor nodes of the given node in dgl?

How to get the k-hop neighbor nodes of the given node in dgl?

The nightly build contains dgl.khop_in_subgraph and dgl.khop_out_subgraph that can find induced subgraphs of (the union of) k-hop neighbors of a batch of nodes. Say

sg, khop_neighbors = dgl.khop_in_subgraph(g, seeds, k)
# sg contains the subgraph of seeds as well as their 1-hop to k-hop neighbors
# khop_neighbors contains all the k-hop neighbors.
1 Like

Thank you so much! And which version has these functions ? 0.7.2 ?

No it’s in nightly.

# replace cuXX with your CUDA version like cu111 for 11.1
pip install --pre -U dgl-cuXX -f https://data.dgl.ai/wheels-test/repo.html