Remove Edges/Nodes without re-indexing them?

The current documentation for the function to remove edges from the DGL graph (https://docs.dgl.ai/en/latest/generated/dgl.DGLGraph.remove_edges.html) says that the edges will be re-indexed using consecutive integers from 0. Is there a way to make this not happen, or preserve the original edge ordering somehow? Same for nodes?

You can save the original edge IDs as an additional edge feature.

1 Like

Thanks. I’m assuming also that removing an edge doesn’t affect the node count or remove the node if it has no incident edges anymore, but this node will now not be trained as part of the graph. Please let me know if I’m wrong.

Thanks. I’m assuming also that removing an edge doesn’t affect the node count or remove the node if it has no incident edges anymore, but this node will now not be trained as part of the graph. Please let me know if I’m wrong.

If you remove an edge/node. Then g.num_edges()/g.num_nodes() will change accordingly. This is why you need to store the edge/node IDs as additional feature.

@hockeybro12 You can use dgl.edge_subgraph and set preserve_nodes=True.

1 Like