Number of rows in edge data does not match the number of edges

def graph_creat(uu_dict,vv_dict):
    print("-------------------------------图结构化建模开始-------------------------------")
    nodes_u_num = len(uu_dict)
    nodes_v_num = len(vv_dict)
    G_U = dgl.DGLGraph()
    G_V = dgl.DGLGraph()
    G_U.add_nodes(nodes_u_num)
    G_V.add_nodes(nodes_v_num)
    for u_i in list(uu_dict.keys()):   #开始给图加边
        G_U.add_edges(int(u_i), list(map(int, list(uu_dict[u_i].keys()))))
    G_U_edges_num = G_U.number_of_edges()
    **G_U.edata['rela'] = torch.zeros(G_U_edges_num, 1)**
    G_U.ndata['degrees'] = G_U.out_degrees(G_U.nodes()).float() + 1.0
    for u_i in list(uu_dict.keys()):
        G_U.edata['rela'][G_U.edge_ids(int(u_i), list(map(int, list(uu_dict[u_i].keys()))))] = torch.tensor(list(uu_dict[u_i].values())).float()
    for v_i in list(vv_dict.keys()):
        G_V.add_edges(int(v_i), list(map(int, list(vv_dict[v_i].keys()))))
    G_V_edges_num = G_V.number_of_edges()
    G_V.edata['rela'] = torch.zeros(G_V_edges_num).float()
    G_V.ndata['degrees'] = G_V.out_degrees(G_V.nodes()).float() + 1.0
    for v_i in list(vv_dict.keys()):
        G_V.edata['rela'][G_V.edge_ids(int(v_i), list(map(int,list(vv_dict[v_i].keys()))))] = torch.tensor(list(vv_dict[v_i].values())).float()
    return G_U, G_V
    print("-------------------------------图结构化建模结束-------------------------------")

The above code gives error:

Traceback (most recent call last):
  File "D:\applications\pycharm\PyCharm 2019.2.4\helpers\pydev\pydevd.py", line 1415, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\applications\pycharm\PyCharm 2019.2.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/研究生工作/实验室工作/实验/GraphCluster/GraphCluster/main.py", line 51, in <module>
    G_U, G_V = graph_creat(uu_dict, vv_dict)
  File "D:\研究生工作\实验室工作\实验\GraphCluster\GraphCluster\graph_creat.py", line 16, in graph_creat
    G_U.edata['rela'] = torch.zeros(G_U_edges_num, 1)
  File "D:\applications\anaconda\lib\site-packages\dgl\view.py", line 133, in __setitem__
    self._graph.set_e_repr({key : val}, self._edges)
  File "D:\applications\anaconda\lib\site-packages\dgl\graph.py", line 2378, in set_e_repr
    self._edge_frame[key] = val
  File "D:\applications\anaconda\lib\site-packages\dgl\frame.py", line 671, in __setitem__
    self.update_data(key, val, inplace=False)
  File "D:\applications\anaconda\lib\site-packages\dgl\frame.py", line 698, in update_data
    self.update_column(key, val, inplace=inplace)
  File "D:\applications\anaconda\lib\site-packages\dgl\frame.py", line 729, in update_column
    self._frame[name] = data
  File "D:\applications\anaconda\lib\site-packages\dgl\frame.py", line 328, in __setitem__
    self.update_column(name, data)
  File "D:\applications\anaconda\lib\site-packages\dgl\frame.py", line 415, in update_column
    (self.num_rows, len(col)))
**dgl._ffi.base.DGLError: Expected data to have 1134529 rows, got 1134014.**

Your problem might be related with my problem, I guess
https://discuss.dgl.ai/t/graphindex-edge-ids-return-mismatched-shape/912

It turns out that it is a bug caused by g.add_edges(u, v) but one of u and v is an empty list.

import dgl
import torch

g = dgl.DGLGraph()
g.add_nodes(10)
g.add_edges(0, [1, 2, 3])
g.add_edges(1, [])
print(g)
g.edata['h'] = torch.randn((g.number_of_edges(), 5))

Working on a fix.

Issue: https://github.com/dmlc/dgl/issues/1476