dgl.transform.metapath_reachable_graph(g, metapath)[source]

Return a graph where the successors of any node u are nodes reachable from u by the given metapath.

If the beginning node type s and ending node type t are the same, it will return a homogeneous graph with node type s = t. Otherwise, a unidirectional bipartite graph with source node type s and destination node type t is returned.

In both cases, two nodes u and v will be connected with an edge (u, v) if there exists one path matching the metapath from u to v.

The result graph keeps the node set of type s and t in the original graph even if they might have no neighbor.

The features of the source/destination node type in the original graph would be copied to the new graph.

  • g (DGLHeteroGraph) – The input graph
  • metapath (list[str or tuple of str]) – Metapath in the form of a list of edge types

A homogeneous or bipartite graph.

Return type: