I have some text labels that I would like to keep (apart from tensor features) so that I could calculate some basic similarity/validation checks on. Is there a way to create a name for each node/edge?
Hi, this is a part of our heterogeneous graph plan (WIP, not done yet), you may find the python interface here: https://github.com/dmlc/dgl/blob/master/python/dgl/heterograph.py.
For now, I think a workaround is to record the edge ids for each type of node/edge, and use our
edge_subgraph to get the subgraph correspond to some type of nodes/edges, for example:
import dgl import torch as th g = dgl.DGLGraph() g.add_nodes(10) type_self_ids =  type_forward_ids =  type_backward_ids =  for i in range(10): for j in range(10): eid = g.number_of_edges() if i == j: type_self_ids.append(eid) elif i < j: type_forward_ids.append(eid) else: # i > j type_backward_ids.append(eid) g.add_edge(i, j) g_self = g.edge_subgraph(type_self_ids) print(g_self.number_of_edges()) g_forward = g.edge_subgraph(type_forward_ids) print(g_forward.number_of_edges()) g_backward = g.edge_subgraph(type_backward_ids) print(g_backward.number_of_edges())
and remember to call
copy_to_parent when necessary.
I’ve got this error when I tried that code:
TypeError Traceback (most recent call last)
----> 1 g_self = g.edge_subgraph(type_self_ids)
~/anaconda3/envs/Pytorch/lib/python3.6/site-packages/dgl/graph.py in edge_subgraph(self, edges)
2831 def prop_edges(self,
-> 2832 edges_generator,
TypeError: init() takes from 3 to 4 positional arguments but 5 were given
Could you please tell me the version of DGL you are using? In DGL 0.3 this shouldn’t happen…
edge_subgraph does not call
I updated to 0.3 before running that code
Sorry was a env. issue. Working now