See code as follows
def build_karate_club_graph():
g = dgl.DGLGraph()
node_id = torch.arange(0, 4, dtype=torch.long).view(-1, 1)
# add 34 nodes into the graph; nodes are labeled from 0~33
g.add_nodes(4)
g.ndata[‘n_id’] = node_id
# all 78 edges as a list of tuples
edge_list = [(1,0), (2, 0), (2, 1), (3, 0), (2,1)]
# add edges two lists of nodes: src and dst
src, dst = tuple(zip(*edge_list))
g.add_edges(src, dst)
# edges are directional in DGL; make them bi-directional
# g.add_edges(dst, src)
g.edata[‘e_label’] = torch.randint(low=0, high=1, size=(1,5)).squeeze(0)
return g
#========
graph = build_karate_club_graph()
nxGraph = graph.to_networkx()
nx_dgl_graph = dgl.DGLGraph(nxGraph)