Converting NodeFlow to a flat DGLGraph

Hello,

Awesome library, thank you for the good work!

I have a question about working with the Sampler. In particular, it doesn’t seem obvious how I can get a flat graph from NodeFlow. I’m looking to create a subgraph from a set of vertices, and then feed that subgraph into a GCN or the likes. I think the way to do that is to use the neighborhood sampler, but it returns a NodeFlow, and it’s not clear in the documentation how I can get a regular DGLGraph from it.

Thanks!

Thank you for your question. You can’t convert a NodeFlow to a DGLGraph directly because NodeFlow represents data/computation dependency and there is a notion of layers/blocks in NodeFlow. That being said, I think it’s possible to extend the current NodeFlow API that construct a DGLGraph from a block of edges (the edges between two consecutive layers). A block of edges forms a bipartite graph (nodes in a layer only connect with the nodes in the other layer). Currently, DGLGraph doesn’t support a bipartite graph. If you want to do it now, you might need to hack a little bit. A good news is that we’ll support bipartite graphs very soon, by the end of August. Once DGL supports bipartite graphs, you can get a block of edges with block_adjacency_matrix and construct a DGLGraph with the edges.

Coming here with the same question. Specifically, I need to apply the function remove_self_connection() to my graph. How would I be able to do emulate that same kind of function using the old version of DGL with NodeFlow objects? Thanks

@nicksukie This may need a bit of hack because the old library is not supported anymore. My suggestion is to recreate the graph:

  1. Convert your NodeFlow object into edge list typically stored as a pair of plain pytorch tensors (u, v)
  2. Perform edge removal.
  3. Reconstruct new DGLGraph using the edge list.