How to traverse all the nodes in HeteroGraph via node ids of a specific node type?

I just wanna get all the node ids of a specific node type in heterogeneous graph

Does the example below help?

import dgl

g = dgl.heterograph({
    ('user', 'follows', 'user'): [(0, 1), (1, 2)],
    ('user', 'plays', 'game'): [(0, 0), (1, 0), (1, 1), (2, 1)],
    ('developer', 'develops', 'game'): [(0, 0), (1, 1)],
# Get node ids for 'user' node
# tensor([0, 1, 2])

But if I wanna select a specific node, e.g., node with ID=1 for the type of ‘user’, how can I do that? Thank you.

We refer to a node with its id and type, what do you want to do with a particular node?

What I want to do is not to propagate information across all nodes, but for some particular nodes which are selected based on the type of their 1st-order and 2nd-order neighbors. Thank you.

Can you elaborate more? Is it possible to filter out these nodes first based on message passing?

Take DBLP as an example, after constructing the HIN using the heterograph API, I want to select the nodes with author type, whose 1st-order neighbors are paper type and 2nd-order neighbors are venue type.

My question is that is it possible to select specific nodes with some constrains?

Thank you.

Let A_1 be an n-by-m matrix with n being the number of author nodes and m being the number of paper nodes. Then the author nodes whose 1st order neighbors are paper type are simply ids corresponding to the rows with nonzero entries.

The case for finding author nodes whose 2nd-order neighbors are venue nodes is more complex, in particular if their 1st-order neighbors can be nodes for various types. But in general you can raise the adjacency matrices to power 2 and combine them.

As a result, you will also be able to express the matrix multiplications I mention above with message passing in DGL. Hope it helps.

I’ll try this solution. Thank you for your help.