dgl.DGLHeteroGraph.metagraph

DGLHeteroGraph.metagraph

Return the metagraph as networkx.MultiDiGraph.

The nodes are labeled with node type names. The edges have their keys holding the edge type names.

Returns:
Return type:networkx.MultiDiGraph

Examples

>>> follows_g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
>>> plays_g = dgl.bipartite([(0, 0), (1, 0), (1, 1), (2, 1)], 'user', 'plays', 'game')
>>> g = dgl.hetero_from_relations([follows_g, plays_g])
>>> meta_g = g.metagraph

The metagraph then has two nodes and two edges.

>>> meta_g.nodes()
NodeView(('user', 'game'))
>>> meta_g.number_of_nodes()
2
>>> meta_g.edges()
OutMultiEdgeDataView([('user', 'user'), ('user', 'game')])
>>> meta_g.number_of_edges()
2