Unverified Commit 444becf0 authored by Minjie Wang's avatar Minjie Wang Committed by GitHub
Browse files

[Misc] Move many deprecated codes to the deprecate folder (#1893)

* some file movements

* move some codes to deprecated

* more deprecation

* lint

* remove useless test
parent 68a978d4
...@@ -23,12 +23,12 @@ from .base import ALL, NTYPE, NID, ETYPE, EID ...@@ -23,12 +23,12 @@ from .base import ALL, NTYPE, NID, ETYPE, EID
from .readout import * from .readout import *
from .batch import * from .batch import *
from .convert import * from .convert import *
from .graph import DGLGraph as DGLGraphStale
from .generators import * from .generators import *
from .heterograph import DGLHeteroGraph from .heterograph import DGLHeteroGraph
from .heterograph import DGLHeteroGraph as DGLGraph # pylint: disable=reimported from .heterograph import DGLHeteroGraph as DGLGraph # pylint: disable=reimported
from .nodeflow import *
from .traversal import * from .traversal import *
from .transform import * from .transform import *
from .propagate import * from .propagate import *
from .udf import NodeBatch, EdgeBatch
from ._deprecate.graph import DGLGraph as DGLGraphStale
from ._deprecate.nodeflow import *
...@@ -9,13 +9,13 @@ from functools import wraps ...@@ -9,13 +9,13 @@ from functools import wraps
import networkx as nx import networkx as nx
import dgl import dgl
from .base import ALL, NID, EID, is_all, DGLError, dgl_warning from ..base import ALL, NID, EID, is_all, DGLError, dgl_warning
from . import backend as F from .. import backend as F
from . import init from .. import init
from .frame import FrameRef, Frame, Scheme, sync_frame_initializer from ..frame import FrameRef, Frame, Scheme, sync_frame_initializer
from . import graph_index from .. import graph_index
from .runtime import ir, scheduler, Runtime, GraphAdapter from .runtime import ir, scheduler, Runtime, GraphAdapter
from . import utils from .. import utils
from .view import NodeView, EdgeView from .view import NodeView, EdgeView
from .udf import NodeBatch, EdgeBatch from .udf import NodeBatch, EdgeBatch
......
"""Module for dgl kernels for graph computation.""" """Module for dgl kernels for graph computation."""
from __future__ import absolute_import from __future__ import absolute_import
from ._ffi.function import _init_api from .._ffi.function import _init_api
from . import ndarray as nd from .. import ndarray as nd
# pylint: disable=invalid-name # pylint: disable=invalid-name
def infer_binary_feature_shape(op, lhs, rhs): def infer_binary_feature_shape(op, lhs, rhs):
...@@ -414,4 +414,4 @@ def backward_copy_reduce(reducer, G, target, ...@@ -414,4 +414,4 @@ def backward_copy_reduce(reducer, G, target,
X, out, grad_out, grad_X, X, out, grad_out, grad_X,
X_rows, out_rows) X_rows, out_rows)
_init_api("dgl.kernel") _init_api("dgl._deprecate.kernel")
"""Class for NodeFlow data structure.""" """Class for NodeFlow data structure."""
from __future__ import absolute_import from __future__ import absolute_import
from ._ffi.object import register_object, ObjectBase from .._ffi.object import register_object, ObjectBase
from ._ffi.function import _init_api from .._ffi.function import _init_api
from .base import ALL, is_all, DGLError, dgl_warning from ..base import ALL, is_all, DGLError, dgl_warning
from . import backend as F from .. import backend as F
from .frame import Frame, FrameRef from ..frame import Frame, FrameRef
from .graph import DGLBaseGraph from .graph import DGLBaseGraph
from .graph_index import transform_ids from ..graph_index import transform_ids
from .runtime import ir, scheduler, Runtime from .runtime import ir, scheduler, Runtime
from . import utils from .. import utils
from .view import LayerView, BlockView from .view import LayerView, BlockView
__all__ = ['NodeFlow'] __all__ = ['NodeFlow']
...@@ -1053,4 +1053,4 @@ def _update_frame(frame, names, ids, new_frame): ...@@ -1053,4 +1053,4 @@ def _update_frame(frame, names, ids, new_frame):
# This will raise error for tensorflow, because inplace update is not supported # This will raise error for tensorflow, because inplace update is not supported
frame.update_rows(ids, FrameRef(Frame(col_dict)), inplace=True) frame.update_rows(ids, FrameRef(Frame(col_dict)), inplace=True)
_init_api("dgl.nodeflow", __name__) _init_api("dgl._deprecate.nodeflow", __name__)
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
from __future__ import absolute_import from __future__ import absolute_import
from functools import partial from functools import partial
from .._ffi.function import _init_api from ..._ffi.function import _init_api
from .. import backend as F from ... import backend as F
from ..udf import NodeBatch, EdgeBatch from ..udf import NodeBatch, EdgeBatch
from .. import utils from ... import utils
from . import ir from . import ir
from .ir import var from .ir import var
...@@ -314,4 +314,4 @@ def _create_per_bkt_efunc(apply_func, deg, u, v, eid, canonical_etype=(None, Non ...@@ -314,4 +314,4 @@ def _create_per_bkt_efunc(apply_func, deg, u, v, eid, canonical_etype=(None, Non
return {k: _reshape_back(v) for k, v in apply_func(ebatch).items()} return {k: _reshape_back(v) for k, v in apply_func(ebatch).items()}
return _efunc_wrapper return _efunc_wrapper
_init_api("dgl.runtime.degree_bucketing") _init_api("dgl._deprecate.runtime.degree_bucketing")
...@@ -4,9 +4,9 @@ from __future__ import absolute_import ...@@ -4,9 +4,9 @@ from __future__ import absolute_import
from abc import abstractmethod from abc import abstractmethod
from ... import backend as F from .... import backend as F
from ...frame import FrameRef, Frame from ....frame import FrameRef, Frame
from ... import utils from .... import utils
from .program import get_current_prog from .program import get_current_prog
from . import var from . import var
......
"""For different schedulers""" """For different schedulers"""
from __future__ import absolute_import from __future__ import absolute_import
from .. import utils from ... import utils
from .._ffi.function import _init_api from ..._ffi.function import _init_api
from ..base import DGLError from ...base import DGLError
from .. import backend as F from ... import backend as F
from ..frame import frame_like, FrameRef from ...frame import frame_like, FrameRef
from ..function.base import BuiltinFunction from ...function.base import BuiltinFunction
from ..udf import EdgeBatch, NodeBatch from ..udf import EdgeBatch, NodeBatch
from ... import ndarray as nd
from . import ir from . import ir
from .ir import var from .ir import var
from . import degree_bucketing as db from . import degree_bucketing as db
from . import spmv from . import spmv
from .. import ndarray as nd
__all__ = [ __all__ = [
"schedule_send", "schedule_send",
"schedule_recv", "schedule_recv",
...@@ -1050,4 +1049,4 @@ def _build_idx_map(idx, nbits): ...@@ -1050,4 +1049,4 @@ def _build_idx_map(idx, nbits):
old_to_new = F.zerocopy_to_dgl_ndarray(old_to_new) old_to_new = F.zerocopy_to_dgl_ndarray(old_to_new)
return utils.CtxCachedObject(lambda ctx: nd.array(old_to_new, ctx=ctx)) return utils.CtxCachedObject(lambda ctx: nd.array(old_to_new, ctx=ctx))
_init_api("dgl.runtime.scheduler") _init_api("dgl._deprecate.runtime.scheduler")
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
from __future__ import absolute_import from __future__ import absolute_import
from functools import partial from functools import partial
from ..base import DGLError from ...base import DGLError
from .. import backend as F from ... import backend as F
from .. import utils from ... import utils
from .. import ndarray as nd from ... import ndarray as nd
from ..heterograph_index import create_unitgraph_from_coo from ...heterograph_index import create_unitgraph_from_coo
from . import ir from . import ir
from .ir import var from .ir import var
......
"""User-defined function related data structures."""
from __future__ import absolute_import
class EdgeBatch(object):
"""The class that can represent a batch of edges.
Parameters
----------
edges : tuple of utils.Index
The edge tuple (u, v, eid). eid can be ALL
src_data : dict
The src node features, in the form of ``dict``
with ``str`` keys and ``tensor`` values
edge_data : dict
The edge features, in the form of ``dict`` with
``str`` keys and ``tensor`` values
dst_data : dict of tensors
The dst node features, in the form of ``dict``
with ``str`` keys and ``tensor`` values
canonical_etype : tuple of (str, str, str), optional
Canonical edge type of the edge batch, if UDF is
running on a heterograph.
"""
def __init__(self, edges, src_data, edge_data, dst_data,
canonical_etype=(None, None, None)):
self._edges = edges
self._src_data = src_data
self._edge_data = edge_data
self._dst_data = dst_data
self._canonical_etype = canonical_etype
@property
def src(self):
"""Return the feature data of the source nodes.
Returns
-------
dict with str keys and tensor values
Features of the source nodes.
"""
return self._src_data
@property
def dst(self):
"""Return the feature data of the destination nodes.
Returns
-------
dict with str keys and tensor values
Features of the destination nodes.
"""
return self._dst_data
@property
def data(self):
"""Return the edge feature data.
Returns
-------
dict with str keys and tensor values
Features of the edges.
"""
return self._edge_data
def edges(self):
"""Return the edges contained in this batch.
Returns
-------
tuple of three tensors
The edge tuple :math:`(src, dst, eid)`. :math:`src[i],
dst[i], eid[i]` separately specifies the source node,
destination node and the edge id for the ith edge
in the batch.
"""
u, v, eid = self._edges
return (u.tousertensor(), v.tousertensor(), eid.tousertensor())
def batch_size(self):
"""Return the number of edges in this edge batch.
Returns
-------
int
"""
return len(self._edges[0])
def __len__(self):
"""Return the number of edges in this edge batch.
Returns
-------
int
"""
return self.batch_size()
@property
def canonical_etype(self):
"""Return the canonical edge type (i.e. triplet of source, edge, and
destination node type) for this edge batch, if available."""
return self._canonical_etype
class NodeBatch(object):
"""The class that can represent a batch of nodes.
Parameters
----------
nodes : utils.Index
The node ids.
data : dict
The node features, in the form of ``dict``
with ``str`` keys and ``tensor`` values
msgs : dict, optional
The messages, , in the form of ``dict``
with ``str`` keys and ``tensor`` values
ntype : str, optional
The node type of this node batch, if running
on a heterograph.
"""
def __init__(self, nodes, data, msgs=None, ntype=None):
self._nodes = nodes
self._data = data
self._msgs = msgs
self._ntype = ntype
@property
def data(self):
"""Return the node feature data.
Returns
-------
dict with str keys and tensor values
Features of the nodes.
"""
return self._data
@property
def mailbox(self):
"""Return the received messages.
If no messages received, a ``None`` will be returned.
Returns
-------
dict or None
The messages nodes received. If dict, the keys are
``str`` and the values are ``tensor``.
"""
return self._msgs
def nodes(self):
"""Return the nodes contained in this batch.
Returns
-------
tensor
The nodes.
"""
return self._nodes.tousertensor()
def batch_size(self):
"""Return the number of nodes in this batch.
Returns
-------
int
"""
return len(self._nodes)
def __len__(self):
"""Return the number of nodes in this node batch.
Returns
-------
int
"""
return self.batch_size()
@property
def ntype(self):
"""Return the node type of this node batch, if available."""
return self._ntype
"""Views of DGLGraph."""
from __future__ import absolute_import
from collections import namedtuple
from collections.abc import MutableMapping
import numpy as np
from ..base import ALL, is_all, DGLError
from .. import backend as F
NodeSpace = namedtuple('NodeSpace', ['data'])
EdgeSpace = namedtuple('EdgeSpace', ['data'])
class NodeView(object):
"""A NodeView class to act as G.nodes for a DGLGraph.
Can be used to get a list of current nodes and get and set node data.
See Also
--------
dgl.DGLGraph.nodes
"""
__slots__ = ['_graph']
def __init__(self, graph):
self._graph = graph
def __len__(self):
return self._graph.number_of_nodes()
def __getitem__(self, nodes):
if isinstance(nodes, slice):
# slice
if not (nodes.start is None and nodes.stop is None
and nodes.step is None):
raise DGLError('Currently only full slice ":" is supported')
return NodeSpace(data=NodeDataView(self._graph, ALL))
else:
return NodeSpace(data=NodeDataView(self._graph, nodes))
def __call__(self):
"""Return the nodes."""
return F.copy_to(F.arange(0, len(self)), F.cpu())
class NodeDataView(MutableMapping):
"""The data view class when G.nodes[...].data is called.
See Also
--------
dgl.DGLGraph.nodes
"""
__slots__ = ['_graph', '_nodes']
def __init__(self, graph, nodes):
self._graph = graph
self._nodes = nodes
def __getitem__(self, key):
return self._graph.get_n_repr(self._nodes)[key]
def __setitem__(self, key, val):
if isinstance(val, np.ndarray):
val = F.zerocopy_from_numpy(val)
self._graph.set_n_repr({key : val}, self._nodes)
def __delitem__(self, key):
if not is_all(self._nodes):
raise DGLError('Delete feature data is not supported on only a subset'
' of nodes. Please use `del G.ndata[key]` instead.')
self._graph.pop_n_repr(key)
def __len__(self):
return len(self._graph._node_frame)
def __iter__(self):
return iter(self._graph._node_frame)
def __repr__(self):
data = self._graph.get_n_repr(self._nodes)
return repr({key : data[key] for key in self._graph._node_frame})
class EdgeView(object):
"""A EdgeView class to act as G.edges for a DGLGraph.
Can be used to get a list of current edges and get and set edge data.
See Also
--------
dgl.DGLGraph.edges
"""
__slots__ = ['_graph']
def __init__(self, graph):
self._graph = graph
def __len__(self):
return self._graph.number_of_edges()
def __getitem__(self, edges):
if isinstance(edges, slice):
# slice
if not (edges.start is None and edges.stop is None
and edges.step is None):
raise DGLError('Currently only full slice ":" is supported')
return EdgeSpace(data=EdgeDataView(self._graph, ALL))
else:
return EdgeSpace(data=EdgeDataView(self._graph, edges))
def __call__(self, *args, **kwargs):
"""Return all the edges."""
return self._graph.all_edges(*args, **kwargs)
class EdgeDataView(MutableMapping):
"""The data view class when G.edges[...].data is called.
See Also
--------
dgl.DGLGraph.edges
"""
__slots__ = ['_graph', '_edges']
def __init__(self, graph, edges):
self._graph = graph
self._edges = edges
def __getitem__(self, key):
return self._graph.get_e_repr(self._edges)[key]
def __setitem__(self, key, val):
if isinstance(val, np.ndarray):
val = F.zerocopy_from_numpy(val)
self._graph.set_e_repr({key : val}, self._edges)
def __delitem__(self, key):
if not is_all(self._edges):
raise DGLError('Delete feature data is not supported on only a subset'
' of nodes. Please use `del G.edata[key]` instead.')
self._graph.pop_e_repr(key)
def __len__(self):
return len(self._graph._edge_frame)
def __iter__(self):
return iter(self._graph._edge_frame)
def __repr__(self):
data = self._graph.get_e_repr(self._edges)
return repr({key : data[key] for key in self._graph._edge_frame})
class LayerView(object):
"""A LayerView class to act as nflow.layers for a NodeFlow.
Can be used to get a list of current nodes and get and set node data.
"""
__slots__ = ['_graph']
def __init__(self, graph):
self._graph = graph
def __len__(self):
return self._graph.num_layers()
def __getitem__(self, layer):
if not isinstance(layer, int):
raise DGLError('Currently we only support the view of one layer')
return NodeSpace(data=LayerDataView(self._graph, layer))
def __call__(self):
"""Return the nodes."""
return F.arange(0, len(self))
class LayerDataView(MutableMapping):
"""The data view class when G.layers[...].data is called.
"""
__slots__ = ['_graph', '_layer']
def __init__(self, graph, layer):
self._graph = graph
self._layer = layer
def __getitem__(self, key):
return self._graph._node_frames[self._layer][key]
def __setitem__(self, key, val):
self._graph._node_frames[self._layer][key] = val
def __delitem__(self, key):
del self._graph._node_frames[self._layer][key]
def __len__(self):
return len(self._graph._node_frames[self._layer])
def __iter__(self):
return iter(self._graph._node_frames[self._layer])
def __repr__(self):
data = self._graph._node_frames[self._layer]
return repr({key : data[key] for key in data})
class BlockView(object):
"""A BlockView class to act as nflow.blocks for a NodeFlow.
Can be used to get a list of current edges and get and set edge data.
"""
__slots__ = ['_graph']
def __init__(self, graph):
self._graph = graph
def __len__(self):
return self._graph.num_blocks
def __getitem__(self, flow):
if not isinstance(flow, int):
raise DGLError('Currently we only support the view of one flow')
return EdgeSpace(data=BlockDataView(self._graph, flow))
def __call__(self, *args, **kwargs):
"""Return all the edges."""
return self._graph.all_edges(*args, **kwargs)
class BlockDataView(MutableMapping):
"""The data view class when G.blocks[...].data is called.
"""
__slots__ = ['_graph', '_flow']
def __init__(self, graph, flow):
self._graph = graph
self._flow = flow
def __getitem__(self, key):
return self._graph._edge_frames[self._flow][key]
def __setitem__(self, key, val):
self._graph._edge_frames[self._flow][key] = val
def __delitem__(self, key):
del self._graph._edge_frames[self._flow][key]
def __len__(self):
return len(self._graph._edge_frames[self._flow])
def __iter__(self):
return iter(self._graph._edge_frames[self._flow])
def __repr__(self):
data = self._graph._edge_frames[self._flow]
return repr({key : data[key] for key in data})
...@@ -284,7 +284,7 @@ def _init_api_prefix(module_name, prefix): ...@@ -284,7 +284,7 @@ def _init_api_prefix(module_name, prefix):
module = sys.modules[module_name] module = sys.modules[module_name]
for name in list_global_func_names(): for name in list_global_func_names():
if name.startswith("_"): if not name.startswith('_deprecate') and name.startswith("_"):
continue continue
name_split = name.rsplit('.', 1) name_split = name.rsplit('.', 1)
if name_split[0] != prefix: if name_split[0] != prefix:
......
...@@ -9,7 +9,7 @@ import mxnet.ndarray as nd ...@@ -9,7 +9,7 @@ import mxnet.ndarray as nd
import numbers import numbers
import builtins import builtins
from ... import ndarray as dglnd from ... import ndarray as dglnd
from ... import kernel as K from ..._deprecate import kernel as K
from ...function.base import TargetCode from ...function.base import TargetCode
MX_VERSION = LooseVersion(mx.__version__) MX_VERSION = LooseVersion(mx.__version__)
......
...@@ -9,7 +9,7 @@ import numbers ...@@ -9,7 +9,7 @@ import numbers
from torch.utils import dlpack from torch.utils import dlpack
from ... import ndarray as nd from ... import ndarray as nd
from ... import kernel as K from ..._deprecate import kernel as K
from ...function.base import TargetCode from ...function.base import TargetCode
from ...base import dgl_warning from ...base import dgl_warning
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment