DGLHeteroGraph: How to add new edge types, especially reverse edges?

Suppose we have a HeteroGraph G with the following relations with directed edges.

(‘author’, ‘affiliated_with’, ‘institution’), (‘author’, ‘writes’, ‘paper’), (‘paper’, ‘cites’, ‘paper’), (‘paper’, ‘has_topic’, ‘field_of_study’)

I want to add a reverse relation (‘paper’, ‘written_by’, ‘author’), however, I’m limited to the following procedures:

rel = G.edge_type_subgraph([“writes”])
G.add_edges(*rel.reverse().all_edges(), etype=(‘paper’, ‘written_by’, ‘author’))

This would result in the error “DGLError: Edge type “(‘paper’, ‘written_by’, ‘author’)” does not exist.”, making it impossible to add a new edge type to the metagraph.

This procedure doesn’t solve the problem either:

dgl.transform.add_reverse_edges(G, ignore_bipartite=True)

Is there a way to add a new canonical edge type to an DGL HeteroGraph without instantiating a new one?

Currently, adding an edge type after creating a heterogeneous graph is not supported and you need to create a new graph from scratch.

Can we bypass this limitation by adding to the G.canonical_etypes list?

No, you can’t. This is also related to the internal storage of graphs and requires a lot of hacking other than modifying canonical_etypes.

1 Like