Skip to content

Commit

Permalink
[API Deprecation] Remove candidates in DGLGraph (dmlc#4946)
Browse files Browse the repository at this point in the history
  • Loading branch information
peizhou001 authored Dec 1, 2022
1 parent e088aca commit 6113930
Show file tree
Hide file tree
Showing 61 changed files with 229 additions and 584 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def track_time(feat_size, num_relations, multi_reduce_type):
update_dict = {}
for i in range(num_relations):
update_dict['e_{}'.format(i)] = (
fn.copy_src('h', 'm'), fn.sum('m', 'h'))
fn.copy_u('h', 'm'), fn.sum('m', 'h'))
graph.multi_update_all(
update_dict,
multi_reduce_type)
Expand Down
9 changes: 0 additions & 9 deletions docs/source/api/python/dgl.function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ Here is a cheatsheet of all the DGL built-in functions.
| Unary message function | ``copy_u`` | |
| +-----------------------------------------------------------------+-----------------------+
| | ``copy_e`` | |
| +-----------------------------------------------------------------+-----------------------+
| | ``copy_src`` | alias of ``copy_u`` |
| +-----------------------------------------------------------------+-----------------------+
| | ``copy_edge`` | alias of ``copy_e`` |
+-------------------------+-----------------------------------------------------------------+-----------------------+
| Binary message function | ``u_add_v``, ``u_sub_v``, ``u_mul_v``, ``u_div_v``, ``u_dot_v`` | |
| +-----------------------------------------------------------------+-----------------------+
Expand All @@ -133,8 +129,6 @@ Here is a cheatsheet of all the DGL built-in functions.
| | ``e_add_u``, ``e_sub_u``, ``e_mul_u``, ``e_div_u``, ``e_dot_u`` | |
| +-----------------------------------------------------------------+-----------------------+
| | ``e_add_v``, ``e_sub_v``, ``e_mul_v``, ``e_div_v``, ``e_dot_v`` | |
| +-----------------------------------------------------------------+-----------------------+
| | ``src_mul_edge`` | alias of ``u_mul_e`` |
+-------------------------+-----------------------------------------------------------------+-----------------------+
| Reduce function | ``max`` | |
| +-----------------------------------------------------------------+-----------------------+
Expand All @@ -151,9 +145,6 @@ Message functions
.. autosummary::
:toctree: ../../generated/

copy_src
copy_edge
src_mul_edge
copy_u
copy_e
u_add_v
Expand Down
2 changes: 1 addition & 1 deletion examples/mxnet/gcn/gcn_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self,

def forward(self, h):
self.g.ndata['h'] = h * self.g.ndata['out_norm']
self.g.update_all(fn.copy_src(src='h', out='m'),
self.g.update_all(fn.copy_u(u='h', out='m'),
fn.sum(msg='m', out='accum'))
accum = self.g.ndata.pop('accum')
accum = self.dense(accum * self.g.ndata['in_norm'])
Expand Down
2 changes: 1 addition & 1 deletion examples/mxnet/monet/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def main(args):
pseudo = []
for i in range(g.number_of_edges()):
pseudo.append(
[1 / np.sqrt(g.in_degree(us[i])), 1 / np.sqrt(g.in_degree(vs[i]))]
[1 / np.sqrt(g.in_degrees(us[i])), 1 / np.sqrt(g.in_degrees(vs[i]))]
)
pseudo = nd.array(pseudo, ctx=ctx)

Expand Down
6 changes: 3 additions & 3 deletions examples/mxnet/tree_lstm/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def main(args):
root_ids = [
i
for i in range(batch.graph.number_of_nodes())
if batch.graph.out_degree(i) == 0
if batch.graph.out_degrees(i) == 0
]
root_acc = np.sum(
batch.label.asnumpy()[root_ids] == pred.asnumpy()[root_ids]
Expand Down Expand Up @@ -208,7 +208,7 @@ def main(args):
root_ids = [
i
for i in range(batch.graph.number_of_nodes())
if batch.graph.out_degree(i) == 0
if batch.graph.out_degrees(i) == 0
]
root_acc = np.sum(
batch.label.asnumpy()[root_ids] == pred.asnumpy()[root_ids]
Expand Down Expand Up @@ -261,7 +261,7 @@ def main(args):
root_ids = [
i
for i in range(batch.graph.number_of_nodes())
if batch.graph.out_degree(i) == 0
if batch.graph.out_degrees(i) == 0
]
root_acc = np.sum(
batch.label.asnumpy()[root_ids] == pred.asnumpy()[root_ids]
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/dgmg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def forward(self, g, dest):
if not self.training:
dest = Categorical(dests_probs).sample().item()

if not g.has_edge_between(src, dest):
if not g.has_edges_between(src, dest):
# For undirected graphs, we add edges for both directions
# so that we can perform graph propagation.
src_list = [src, dest]
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/diffpool/model/dgl_layers/gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def forward(self, g, h):
if self.use_bn and not hasattr(self, 'bn'):
device = h.device
self.bn = nn.BatchNorm1d(h.size()[1]).to(device)
g.update_all(fn.copy_src(src='h', out='m'), self.aggregator,
g.update_all(fn.copy_u(u='h', out='m'), self.aggregator,
self.bundler)
if self.use_bn:
h = self.bn(h)
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/gcmc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def forward(self, graph, feat, weight=None):

feat = feat * self.dropout(cj)
graph.srcdata['h'] = feat
graph.update_all(fn.copy_src(src='h', out='m'),
graph.update_all(fn.copy_u(u='h', out='m'),
fn.sum(msg='m', out='h'))
rst = graph.dstdata['h']
rst = rst * ci
Expand Down
12 changes: 6 additions & 6 deletions examples/pytorch/ggnn/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def _collate_fn(batch):

edge_types = []
for s, e, t in edges:
g.add_edge(nid2idx[s], nid2idx[t])
g.add_edges(nid2idx[s], nid2idx[t])
edge_types.append(e)
if e in reverse_edge:
g.add_edge(nid2idx[t], nid2idx[s])
g.add_edges(nid2idx[t], nid2idx[s])
edge_types.append(reverse_edge[e])
g.edata["type"] = torch.tensor(edge_types, dtype=torch.long)
annotation = torch.zeros(len(node_ids), dtype=torch.long)
Expand Down Expand Up @@ -234,10 +234,10 @@ def _collate_fn(batch):

edge_types = []
for s, e, t in edges:
g.add_edge(nid2idx[s], nid2idx[t])
g.add_edges(nid2idx[s], nid2idx[t])
edge_types.append(e)
if e in reverse_edge:
g.add_edge(nid2idx[t], nid2idx[s])
g.add_edges(nid2idx[t], nid2idx[s])
edge_types.append(reverse_edge[e])
g.edata["type"] = torch.tensor(edge_types, dtype=torch.long)
annotation = torch.zeros([len(node_ids), 2], dtype=torch.long)
Expand Down Expand Up @@ -361,10 +361,10 @@ def _collate_fn(batch):

edge_types = []
for s, e, t in edges:
g.add_edge(nid2idx[s], nid2idx[t])
g.add_edges(nid2idx[s], nid2idx[t])
edge_types.append(e)
if e in reverse_edge:
g.add_edge(nid2idx[t], nid2idx[s])
g.add_edges(nid2idx[t], nid2idx[s])
edge_types.append(reverse_edge[e])
g.edata["type"] = torch.tensor(edge_types, dtype=torch.long)
annotation = torch.zeros([len(node_ids), 2], dtype=torch.long)
Expand Down
10 changes: 5 additions & 5 deletions examples/pytorch/graph_matching/ged.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_edges_to_match(G, node_id, matched_nodes):
index = np.array([], dtype=int)
direction = np.array([], dtype=int)
if G.has_edge_between(node_id, node_id):
self_edge_ids = G.edge_id(node_id, node_id, return_array=True).numpy()
self_edge_ids = G.edge_ids(node_id, node_id, return_array=True).numpy()
incident_edges = np.concatenate((incident_edges, self_edge_ids))
index = np.concatenate((index, [-1] * len(self_edge_ids)))
direction = np.concatenate((direction, [0] * len(self_edge_ids)))
Expand Down Expand Up @@ -647,7 +647,7 @@ def contextual_cost_matrix_construction(
for i in range(num_G1_nodes):
if G1.has_edge_between(i, i):
self_edge_list_G1[i] = sorted(
G1.edge_id(i, i, return_array=True).numpy()
G1.edge_ids(i, i, return_array=True).numpy()
)
incoming_edges_G1[i] = G1.in_edges([i], "eid").numpy()
incoming_edges_G1[i] = np.setdiff1d(
Expand All @@ -660,7 +660,7 @@ def contextual_cost_matrix_construction(
for i in range(num_G2_nodes):
if G2.has_edge_between(i, i):
self_edge_list_G2[i] = sorted(
G2.edge_id(i, i, return_array=True).numpy()
G2.edge_ids(i, i, return_array=True).numpy()
)
incoming_edges_G2[i] = G2.in_edges([i], "eid").numpy()
incoming_edges_G2[i] = np.setdiff1d(
Expand Down Expand Up @@ -790,7 +790,7 @@ def hausdorff_matching(
for i in range(num_G1_nodes):
if G1.has_edge_between(i, i):
self_edge_list_G1[i] = sorted(
G1.edge_id(i, i, return_array=True).numpy()
G1.edge_ids(i, i, return_array=True).numpy()
)
incoming_edges_G1[i] = G1.in_edges([i], "eid").numpy()
incoming_edges_G1[i] = np.setdiff1d(
Expand All @@ -803,7 +803,7 @@ def hausdorff_matching(
for i in range(num_G2_nodes):
if G2.has_edge_between(i, i):
self_edge_list_G2[i] = sorted(
G2.edge_id(i, i, return_array=True).numpy()
G2.edge_ids(i, i, return_array=True).numpy()
)
incoming_edges_G2[i] = G2.in_edges([i], "eid").numpy()
incoming_edges_G2[i] = np.setdiff1d(
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/gxn/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def forward(self, graph:DGLGraph, node_feat:Tensor, edge_feat:Optional[Tensor]=N
edge_feat = self.e2l_lin(edge_feat)
with graph.local_scope():
graph.edata["he"] = edge_feat
graph.update_all(fn.copy_edge("he", "m"), fn.sum("m", "hn"))
graph.update_all(fn.copy_e("he", "m"), fn.sum("m", "hn"))
edge2node_feat = graph.ndata.pop("hn")
node_feat = torch.cat((node_feat, edge2node_feat), dim=1)

Expand Down
6 changes: 3 additions & 3 deletions examples/pytorch/hgp_sl/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def forward(self, graph:DGLGraph, n_feat, e_feat=None):
n_feat = n_feat * src_norm
graph.ndata["h"] = n_feat
graph.edata["e"] = e_feat
graph.update_all(fn.src_mul_edge("h", "e", "m"),
graph.update_all(fn.u_mul_e("h", "e", "m"),
fn.sum("m", "h"))
n_feat = graph.ndata.pop("h")
n_feat = n_feat * dst_norm
Expand Down Expand Up @@ -100,7 +100,7 @@ def forward(self, graph:dgl.DGLGraph, feat:Tensor, e_feat:Tensor):
graph.ndata["h"] = src_feat
graph.edata["e"] = e_feat
graph = dgl.remove_self_loop(graph)
graph.update_all(fn.src_mul_edge("h", "e", "m"), fn.sum("m", "h"))
graph.update_all(fn.u_mul_e("h", "e", "m"), fn.sum("m", "h"))

dst_feat = graph.ndata.pop("h") * dst_norm
feat = feat - dst_feat
Expand All @@ -111,7 +111,7 @@ def forward(self, graph:dgl.DGLGraph, feat:Tensor, e_feat:Tensor):
graph.ndata["h"] = feat
graph.edata["e"] = e_feat
graph = dgl.remove_self_loop(graph)
graph.update_all(fn.src_mul_edge("h", "e", "m"), fn.sum("m", "h"))
graph.update_all(fn.u_mul_e("h", "e", "m"), fn.sum("m", "h"))

feat = feat - dst_norm * graph.ndata.pop("h")

Expand Down
6 changes: 3 additions & 3 deletions examples/pytorch/jtnn/jtnn/jtmpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def forward(self, node):

if PAPER:
mpn_gather_msg = [
DGLF.copy_edge(edge='msg', out='msg'),
DGLF.copy_edge(edge='alpha', out='alpha')
DGLF.copy_e(edge='msg', out='msg'),
DGLF.copy_e(edge='alpha', out='alpha')
]
else:
mpn_gather_msg = DGLF.copy_edge(edge='msg', out='msg')
mpn_gather_msg = DGLF.copy_e(edge='msg', out='msg')


if PAPER:
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/jtnn/jtnn/jtnn_dec.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def dfs_order(forest, roots):
# using find_edges().
yield e ^ l, l

dec_tree_node_msg = DGLF.copy_edge(edge='m', out='m')
dec_tree_node_msg = DGLF.copy_e(edge='m', out='m')
dec_tree_node_reduce = DGLF.sum(msg='m', out='h')


Expand Down Expand Up @@ -353,7 +353,7 @@ def decode(self, mol_vec):
break # At root, terminate

pu, _ = stack[-2]
u_pu = mol_tree_graph.edge_id(u, pu)
u_pu = mol_tree_graph.edge_ids(u, pu)

mol_tree_graph_lg.pull(u_pu, DGLF.copy_u('m', 'm'), DGLF.sum('m', 's'))
mol_tree_graph_lg.pull(u_pu, DGLF.copy_u('rm', 'rm'), DGLF.sum('rm', 'accum_rm'))
Expand Down
6 changes: 3 additions & 3 deletions examples/pytorch/line_graph/gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def __init__(self, in_feats, out_feats, radius):
def aggregate(self, g, z):
z_list = []
g.ndata['z'] = z
g.update_all(fn.copy_src(src='z', out='m'), fn.sum(msg='m', out='z'))
g.update_all(fn.copy_u(u='z', out='m'), fn.sum(msg='m', out='z'))
z_list.append(g.ndata['z'])
for i in range(self.radius - 1):
for j in range(2 ** i):
g.update_all(fn.copy_src(src='z', out='m'), fn.sum(msg='m', out='z'))
g.update_all(fn.copy_u(u='z', out='m'), fn.sum(msg='m', out='z'))
z_list.append(g.ndata['z'])
return z_list

Expand All @@ -45,7 +45,7 @@ def forward(self, g, lg, x, y, deg_g, deg_lg, pm_pd):
sum_x = sum(theta(z) for theta, z in zip(self.theta_list, self.aggregate(g, x)))

g.edata['y'] = y
g.update_all(fn.copy_edge(edge='y', out='m'), fn.sum('m', 'pmpd_y'))
g.update_all(fn.copy_e(e='y', out='m'), fn.sum('m', 'pmpd_y'))
pmpd_y = g.ndata.pop('pmpd_y')

x = self.theta_x(x) + self.theta_deg(deg_g * x) + sum_x + self.theta_y(pmpd_y)
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/ogb/cluster-sage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def run(args, device, data):
mask[test_idx] = True
graph.ndata["test_mask"] = mask

graph.in_degree(0)
graph.out_degree(0)
graph.in_degrees(0)
graph.out_degrees(0)
graph.find_edges(0)

cluster_iter_data = ClusterIter(
Expand Down
1 change: 0 additions & 1 deletion examples/pytorch/ogb/deepwalk/reading_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def net2graph(net_sm):


def make_undirected(G):
# G.readonly(False)
G.add_edges(G.edges()[1], G.edges()[0])
return G

Expand Down
1 change: 0 additions & 1 deletion examples/pytorch/ogb/line/reading_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def net2graph(net_sm):


def make_undirected(G):
# G.readonly(False)
G.add_edges(G.edges()[1], G.edges()[0])
return G

Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/ogb/ogbn-proteins/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def forward(self, g, node_state_prev):
else:
g.ndata["feat_" + str(c)] = node_state_c
g.update_all(
fn.src_mul_edge("feat_" + str(c), "feat_" + str(c), "m"), fn.sum("m", "feat_" + str(c) + "_new")
fn.u_mul_e("feat_" + str(c), "feat_" + str(c), "m"), fn.sum("m", "feat_" + str(c) + "_new")
)
node_state_c = g.ndata.pop("feat_" + str(c) + "_new")
if self._out_feats >= self._in_feats:
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/pagerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def compute_pagerank(g):
degrees = g.out_degrees(g.nodes()).type(torch.float32)
for k in range(K):
g.ndata['pv'] = g.ndata['pv'] / degrees
g.update_all(message_func=fn.copy_src(src='pv', out='m'),
g.update_all(message_func=fn.copy_u(u='pv', out='m'),
reduce_func=fn.sum(msg='m', out='pv'))
g.ndata['pv'] = (1 - DAMP) / N + DAMP * g.ndata['pv']
return g.ndata['pv']
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/transformer/modules/act.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def propagate_attention(self, g, eids):
g.apply_edges(scaled_exp('score', np.sqrt(self.d_k)), eids)
# Send weighted values to target nodes
g.send_and_recv(eids,
[fn.src_mul_edge('v', 'score', 'v'), fn.copy_edge('score', 'score')],
[fn.u_mul_e('v', 'score', 'v'), fn.copy_e('score', 'score')],
[fn.sum('v', 'wv'), fn.sum('score', 'z')])

def update_graph(self, g, eids, pre_pairs, post_pairs):
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/transformer/modules/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def propagate_attention(self, g, eids):
g.apply_edges(src_dot_dst('k', 'q', 'score'), eids)
g.apply_edges(scaled_exp('score', np.sqrt(self.d_k)), eids)
# Send weighted values to target nodes
g.send_and_recv(eids, fn.src_mul_edge('v', 'score', 'v'), fn.sum('v', 'wv'))
g.send_and_recv(eids, fn.copy_edge('score', 'score'), fn.sum('score', 'z'))
g.send_and_recv(eids, fn.u_mul_e('v', 'score', 'v'), fn.sum('v', 'wv'))
g.send_and_recv(eids, fn.copy_e('score', 'score'), fn.sum('score', 'z'))

def update_graph(self, g, eids, pre_pairs, post_pairs):
"Update the node states and edge states of the graph."
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/transformer/modules/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_attention_map(g, src_nodes, dst_nodes, h):
for j, dst in enumerate(dst_nodes.tolist()):
if not g.has_edge_between(src, dst):
continue
eid = g.edge_id(src, dst)
eid = g.edge_ids(src, dst)
weight[i][j] = g.edata['score'][eid].squeeze(-1).cpu().detach()

weight = weight.transpose(0, 2)
Expand Down
6 changes: 3 additions & 3 deletions examples/pytorch/tree_lstm/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def main(args):
root_ids = [
i
for i in range(g.number_of_nodes())
if g.out_degree(i) == 0
if g.out_degrees(i) == 0
]
root_acc = np.sum(
batch.label.cpu().data.numpy()[root_ids]
Expand Down Expand Up @@ -170,7 +170,7 @@ def main(args):
acc = th.sum(th.eq(batch.label, pred)).item()
accs.append([acc, len(batch.label)])
root_ids = [
i for i in range(g.number_of_nodes()) if g.out_degree(i) == 0
i for i in range(g.number_of_nodes()) if g.out_degrees(i) == 0
]
root_acc = np.sum(
batch.label.cpu().data.numpy()[root_ids]
Expand Down Expand Up @@ -222,7 +222,7 @@ def main(args):
acc = th.sum(th.eq(batch.label, pred)).item()
accs.append([acc, len(batch.label)])
root_ids = [
i for i in range(g.number_of_nodes()) if g.out_degree(i) == 0
i for i in range(g.number_of_nodes()) if g.out_degrees(i) == 0
]
root_acc = np.sum(
batch.label.cpu().data.numpy()[root_ids]
Expand Down
2 changes: 1 addition & 1 deletion examples/tensorflow/gcn/gcn_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def call(self, h):
h = self.dropout(h)
self.g.ndata['h'] = tf.matmul(h, self.weight)
self.g.ndata['norm_h'] = self.g.ndata['h'] * self.g.ndata['norm']
self.g.update_all(fn.copy_src('norm_h', 'm'),
self.g.update_all(fn.copy_u('norm_h', 'm'),
fn.sum('m', 'h'))
h = self.g.ndata['h']
if self.bias is not None:
Expand Down
Loading

0 comments on commit 6113930

Please sign in to comment.