While I use random_walk
with metapath, I find for some given start node it will get a segmentation fault. I have tested filter out the start node not the same with metapath[0]'s node type, but it still gets segment fault. What is the possible reason?
I guess this may be caused by the random walk process because for some time the same node will not produce the error.
I use the following code to construct the graph
def convert_to_hg(nxg):
g = dgl.from_networkx(nxg)
g.ndata[dgl.NTYPE] = torch.LongTensor(list(nx.get_node_attributes(nxg, 'node_type').values())) # assign node types from nxg
g.edata[dgl.ETYPE] = torch.LongTensor(list(nx.get_edge_attributes(nxg, 'edge_type').values())) # assign edge types from nxg
ntypes = [str(i) for i in torch.unique(g.ndata['_TYPE']).tolist()] # name of each node type ID must be str
etypes = [str(i) for i in torch.unique(g.edata['_TYPE']).tolist()] # name of each edge type ID
hg = dgl.to_heterogeneous(g, ntypes, etypes)
edge_features = list(nx.get_edge_attributes(nxg, 'edge_weight').values())
for etype in hg.canonical_etypes:
# edge IDs in the original homogeneous graph (and the NetworkX graph)
nxg_edge_ids = hg.edges[etype].data[dgl.EID]
hg.edges[etype].data['edge_weight'] = torch.as_tensor([edge_features[i.item()] for i in nxg_edge_ids], dtype=torch.float32)
return hg
and then run random_walk
type_map = graph.nodes(data='node_type')
for metapath in metapaths:
print(metapath)
metapath = metapath * k
select_starters = []
for i in all_nodes:
si = str(i.item())
if str(type_map[si]) == metapath[0][0]:
select_starters.append(i.item())
select_starters = torch.as_tensor(select_starters)
traces, types = dgl.sampling.random_walk(g, nodes=select_starters, metapath=metapath)