7.0 KiB
Migration Guide for DGL 0.5
Breaking changes
The following changes may break existing codes if the related APIs are used. Note that most of the removed APIs have quite rare use cases and have quite easy replacements.
-
DGLGraph now requires the graph structure and feature data to have the same device placement. If the given node/edge feature tensors have different devices as the graph’s, dgl.ndata and dgl.edata will raise an error as follow:
dgl._ffi.base.DGLError: Cannot assign node feature "x" on device cpu to a graph on device cuda:0. Call DGLGraph.to() to copy the graph to the same device.To fix it, copy either the graph (using the
DGLGraph.toAPI) or the feature tensors to the same device. -
Changes to
dgl.graph:- No longer accept SciPy matrix/NetworkX graph as the input data. Use
dgl.from_scipy/dgl.from_networkxinstead. ntypeandetypeare removed from the arguments. To construct graphs with named node/edge types, usedgl.heterograph.g = dgl.heterograph(('user', 'follows', 'user') : ...)validateis removed from the arguments. DGL now always checks whether the num_nodes is greater than the largest node ID if specified.
- No longer accept SciPy matrix/NetworkX graph as the input data. Use
-
dgl.bipartiteis removed.- To create a uni-directional bipartite graph, use
dgl.heterograph. E.g.,g = dgl.hetrograph(('user', 'rates', 'movie'): ...) - To create a uni-directional bipartite graph from a SciPy matrix, use the new API
dgl.bipartite_from_scipy. - To create a uni-directional bipartite graph from a NetworkX graph, use the new API
dgl.bipartite_from_networkx.
- To create a uni-directional bipartite graph, use
-
Changes to
dgl.heterograph:- No longer accept SciPy matrix/NetworkX graph as the input data. Use the
from_*APIs to create graphs first and then pass their edges to thedgl.heterographAPI. E.g.,nx_g = ... # some networkx graph spmat = ... # some scipy matrix g1 = dgl.from_networkx(nx_g) g2 = dgl.bipartite_from_scipy(spmat) g = dgl.heterograph({('user', 'follows', 'user') : g1.edges(), ('user', 'rates', 'movie') : g2.edges()})
- No longer accept SciPy matrix/NetworkX graph as the input data. Use the
-
dgl.hetero_from_relationsis removed. Usedgl.heterographinstead. -
From 0.5, subgraphs extracted via DGL APIs automatically inherits node and edge features from the parent graph. DGL also saves the original nodes/edge IDs in
subg.ndata[dgl.NID]andsubg.edata[dgl.EID]if nodes/edges are relabeled. This new behavior makes the followingDGLGraphmethods useless and we thus remove them:DGLGraph.parent,DGLGraph.parent_nid,DGLGraph.parent_eid,DGLGraph.map_to_subgraph_nid,DGLGraph.copy_from_parent,DGLGraph.copy_to_parentandDGLGraph.detach_parent.
-
Other removed DGLGraph APIs:
DGLGraph.from_networkx. Usedgl.from_networkxto construct a DGLGraph from a NetworkX graph.DGLGraph.from_scipy_sparse_matrix. Usedgl.from_scipyto construct a DGLGraph from a SciPy matrix.DGLGraph.register_apply_node_func,DGLGraph.register_apply_edge_func,DGLGraph.register_message_funcandDGLGraph.register_reduce_func. Please specify them directly as the arguments of the message passing APIs.g = ... # some graph # before 0.5 g.register_message_func(mfunc) g.register_reduce_func(rfunc) g.update_all() # starting from 0.5 g.update_all(mfunc, rfunc)DGLGraph.group_apply_edges. To normalize edge weights within the neighborhood of each destination node, usedgl.nn.edge_softmax. To normalize edge weights within the neighborhood of each source node, usedgl.reversefirst before the edge softmax.DGLGraph.sendandDGLGraph.recv. There are rarely any cases where send and recv must be invoked separately. UseDGLGraph.send_and_recvorDGLGraph.update_allfor message passing.DGLGraph.multi_recv,DGLGraph.multi_pull,DGLGraph.multi_send_and_recv. To perform message passing on a part of the nodes and edges, usedgl.node_subgraphordgl.edge_subgraphto extract the subset first and then callDGLGraph.multi_update_all.DGLGraph.clear. Use `dgl.graph(([], []))`` to create a new empty graph.DGLGraph.subgraphs. UseDGLGraph.subgraph.DGLGraph.batch_num_nodesandDGLGraph.batch_num_edgesare now functions that accept node/edge type as the only argument for getting batching information of a heterograph.DGLGraph.flatten. To create a new graph without batching information, use `new_g = gl.graph(old_g.edges())``.
-
The reduce function
dgl.function.prodis removed. -
dgl.add_self_loopwill NOT remove existing self loops automatically. It is recommanded to calldgl.remove_self_loopbefore invokingdgl.add_self_loop.
Deprecations
Will not break old codes but will throw deprecation warning.
Core APIs
- Creating a graph using
dgl.DGLGraph(data)is deprecated. Usedgl.graph(data). - Deprecated
DGLGraphmethods:DGLGraph.to_networkx->dgl.to_networkxDGLGraph.readonlyandDGLGraph.is_readonly. Before 0.5, this flag is a hint for more efficient implementation. From 0.5, the efficiency issue has been resolved so they become useless.DGLGraph.__len__->DGLGraph.number_of_nodesdgl.DGLGraph.__contains__->DGLGraph.has_nodesDGLGraph.add_node->DGLGraph.add_nodesDGLGraph.add_edge->DGLGraph.add_edgesDGLGraph.has_node->DGLGraph.has_nodesDGLGraph.has_edge_between->DGLGraph.has_edges_betweenDGLGraph.edge_id->dgl.DGLGraph.edge_ids.DGLGraph.in_degree->dgl.DGLGraph.in_degrees.DGLGraph.out_degree->dgl.DGLGraph.out_degrees.
dgl.to_simple_graph->dgl.to_simple.dgl.to_homo->dgl.to_homogeneous.dgl.to_hetero->dgl.to_heterogeneous.dgl.as_heterographanddgl.as_immutable_graphare deprecated asdgl.DGLGraphanddgl.DGLHeteroGraphare now merged.dgl.batch_hetero->dgl.batchdgl.unbatch_hetero->dgl.unbatch- The
node_attrs/edge_attrsarguments ofdgl.batchare renamed tondata/edata. - The arguments
share_ndataandshare_edataofdgl.reverseare renamed tocopy_ndataandcopy_edata.
Dataset APIs
For all the current datsets, their class attributes such as graph, feat, etc. are deprecated. The recommended usage is to get them from each sample:
# Before 0.5
dataset = dgl.data.CoraFull()
g = dataset.graph
feat = dataset.feat
...
# From 0.5
dataset = dgl.data.CoraFullDataset() # in 0.5, all the classes have a "Dataset" in the name.
g = dataset[0] # is directly a DGLGraph object
feat = g.ndata['feat']
...
Other changes
dgl.data.SSTis deprecated and replaced bydgl.data.SSTDataset. The attributetreesis deprecated and replaced by__getitem__. The attributenum_vocabsis deprecated and replaced byvocab_size