Clarification on graph.edge_type_subgraph()

On the docs here, it says the subgraph “contains all the edges of the given subset of the edge types of a graph and the nodes incident by those edges”. However, if a node is not connected via an edge type and therefore not incident, but it’s similar type nodes are, it is included in the subgraph. This is shown through a modification of the example where I remove all follows edges into node 2.

g = dgl.heterograph({
    ('user', 'plays', 'game'): ([0, 1, 1, 2], [0, 0, 2, 1]),
    ('user', 'follows', 'user'): ([0, 1, 1], [0,1,1]) # Modified to remove node 2 from these connections
})
# Set edge features
g.edges['follows'].data['h'] = torch.tensor([[0.], [1.], [2.]])
g.nodes['user'].data['feat'] = torch.tensor([[0.], [1.], [2.]]) # Added to show node 2 is included

sub_g = g.edge_type_subgraph(['follows'])
print(sub_g.number_of_nodes('user'))
print(sub_g.nodes['user'].data['feat'])

which prints:

3
tensor([[0.],
        [1.],
        [2.]])

I may be missing something but should this only have 2 user nodes? Is there a way to not include unconnected nodes?

This might be a bug and we will take a deeper look. For the time being you can use dgl.compact_graphs to remove isolated nodes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.