dgl.DGLGraph.metagraph

DGLGraph.metagraph()

Return the metagraph of the heterograph.

The metagraph (or network schema) of a heterogeneous network specifies type constraints on the sets of nodes and edges between the nodes. For a formal definition, refer to Yizhou et al..

Returns

The metagraph.

Return type

networkx.MultiDiGraph

Examples

The following example uses PyTorch backend.

>>> import dgl
>>> import torch
>>> g = dgl.heterograph({
...     ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
...     ('user', 'follows', 'game'): (torch.tensor([0, 1, 2]), torch.tensor([1, 2, 3])),
...     ('user', 'plays', 'game'): (torch.tensor([1, 3]), torch.tensor([2, 3]))
... })
>>> meta_g = g.metagraph()
>>> meta_g.nodes()
NodeView(('user', 'game'))
>>> meta_g.edges()
OutMultiEdgeDataView([('user', 'user'), ('user', 'game'), ('user', 'game')])