I am using dgl.from_networkx() to build a weighted undirected graph. But some graphs has no edges , So I consider two situation:
if len(edges) > 0:
g.add_weighted_edges_from(edges)
g = dgl.from_networkx(g, node_attrs=['x', 'weight'], edge_attrs=['weight'])
else:
g = dgl.from_networkx(g, node_attrs=['x', 'weight'])
when using batch_graph, I get the error :
Expect all edges[(’_N’, ‘_E’, ‘_N’)].data to have the same set of keys, but got dict_keys([‘weight’]) and dict_keys([]).