Quickest way to do subgraph extraction


I am wondering that given an entire DGL Graph G, and a node i, I want to return a 2-hops neighborhood subgraphs around the node i, what’s the quickest way to do it?

Currently, i first use G.in_edges(i)[0] to get 1st hop neighbor and apply the same operation to each first-hop neighbor to get the second. And then use g.subgraph(). Please let me know what’s a better way.

Thanks a lot!


If you want to extract without sampling you can use dgl.in_subgraph(g, seed_nodes) for twice