Question) DGLGraph.from_networkx is deprecated


DGLError Traceback (most recent call last)
in ()
5 oh_cat_cols,
6 num_cols,
----> 7 cat_cols
8 )
9

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/ginn/core.py in init(self, features, mask, num_mask, cat_mask, oh_cat_cols, numerical_columns, categorical_columns, embedding_dim, activation, dropout, percentile, distance_metric, weight_missing, graph, skip, glob_attr)
96
97 if graph:
—> 98 g.from_networkx(nxg)
99 if skip:
100 f = dgl.DGLGraph()

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/dgl/heterograph.py in from_networkx(self, nx_graph, node_attrs, edge_attrs)
5503 which will return a new graph created from the networkx graph.
5504 “”"
-> 5505 raise DGLError(‘DGLGraph.from_networkx is deprecated. Please call the following\n\n’
5506 ‘\t dgl.from_networkx(nx_graph, node_attrs, edge_attrs)\n\n’
5507 ‘, which creates a new DGLGraph from the networkx graph.’)

DGLError: DGLGraph.from_networkx is deprecated. Please call the following

 dgl.from_networkx(nx_graph, node_attrs, edge_attrs)

, which creates a new DGLGraph from the networkx graph.

Is there a solution?

As the error message suggests, use dgl.from_networkx.

nxg = dataset2nxg(
        self.features,
        self.mask,
        self.percentile,
        self.distance_metric,
        self.weight_missing,
    )
    g = dgl.from_networkx()
    g.set_e_initializer(dgl.init.zero_initializer)
    g.set_n_initializer(dgl.init.zero_initializer)

    if graph:
        g.from_networkx(nxg)
        if skip:
            f = dgl.DGLGraph()
            f.set_e_initializer(dgl.init.zero_initializer)
            f.set_n_initializer(dgl.init.zero_initializer)
            f.from_networkx(nxg)
    else:
        g.add_nodes(self.features.shape[0])
    g.add_edges(g.nodes(), g.nodes())

How do I fix it here? I can’t find a way.

Is nxg a NetworkX graph? If so, you just need to call g = dgl.from_networkx(nx_g).

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.