DGLSubGraph – Class for subgraph data structure

class dgl.subgraph.DGLSubGraph(parent, parent_nid, parent_eid, graph_idx, shared=False)[source]

The subgraph class.

There are two subgraph modes: shared and non-shared.

For the “non-shared” mode, the user needs to explicitly call copy_from_parent to copy node/edge features from its parent graph. * If the user tries to get node/edge features before copy_from_parent,

s/he will get nothing.
  • If the subgraph already has its own node/edge features, copy_from_parent will override them.
  • Any update on the subgraph’s node/edge features will not be seen by the parent graph. As such, the memory consumption is of the order of the subgraph size.
  • To write the subgraph’s node/edge features back to parent graph. There are two options: (1) Use copy_to_parent API to write node/edge features back. (2) [TODO] Use dgl.merge to merge multiple subgraphs back to one parent.

The “shared” mode is currently not supported.

The subgraph is read-only on structure; graph mutation is not allowed.

Parameters:
  • parent (DGLGraph) – The parent graph
  • parent_nid (utils.Index) – The induced parent node ids in this subgraph.
  • parent_eid (utils.Index) – The induced parent edge ids in this subgraph.
  • graph_idx (GraphIndex) – The graph index.
  • shared (bool, optional) – Whether the subgraph shares node/edge features with the parent graph.

Mapping between subgraph and parent graph

DGLSubGraph.parent_nid Get the parent node ids.
DGLSubGraph.parent_eid Get the parent edge ids.
DGLSubGraph.map_to_subgraph_nid(parent_vids) Map the node Ids in the parent graph to the node Ids in the subgraph.

Synchronize features between subgraph and parent graph

DGLSubGraph.copy_from_parent() Copy node/edge features from the parent graph.
DGLSubGraph.copy_to_parent([inplace]) Write node/edge features to the parent graph.