"docs/vscode:/vscode.git/clone" did not exist on "1afc21855eb1f5575bd61037a7ee44522ccf401e"
Unverified Commit 7f5da697 authored by Hongzhi (Steve), Chen's avatar Hongzhi (Steve), Chen Committed by GitHub
Browse files

[Misc] Rename number_of_edges and number_of_nodes to num_edges and num_nodes...


[Misc] Rename number_of_edges and number_of_nodes to num_edges and num_nodes in dist related python files. (#5489)
Co-authored-by: default avatarUbuntu <ubuntu@ip-172-31-28-63.ap-northeast-1.compute.internal>
parent 5b409bf7
...@@ -59,8 +59,8 @@ def libra_partition(num_community, G, resultdir): ...@@ -59,8 +59,8 @@ def libra_partition(num_community, G, resultdir):
3. The folder also contains a json file which contains partitions' information. 3. The folder also contains a json file which contains partitions' information.
""" """
num_nodes = G.number_of_nodes() # number of nodes num_nodes = G.num_nodes() # number of nodes
num_edges = G.number_of_edges() # number of edges num_edges = G.num_edges() # number of edges
print("Number of nodes in the graph: ", num_nodes) print("Number of nodes in the graph: ", num_nodes)
print("Number of edges in the graph: ", num_edges) print("Number of edges in the graph: ", num_edges)
...@@ -161,8 +161,8 @@ def libra_partition(num_community, G, resultdir): ...@@ -161,8 +161,8 @@ def libra_partition(num_community, G, resultdir):
part_metadata = { part_metadata = {
"graph_name": graph_name, "graph_name": graph_name,
"num_nodes": G.number_of_nodes(), "num_nodes": G.num_nodes(),
"num_edges": G.number_of_edges(), "num_edges": G.num_edges(),
"part_method": part_method, "part_method": part_method,
"num_parts": num_parts, "num_parts": num_parts,
"halo_hops": num_hops, "halo_hops": num_hops,
......
...@@ -88,7 +88,7 @@ def proteins_mtx2dgl(): ...@@ -88,7 +88,7 @@ def proteins_mtx2dgl():
g.add_edges(u, v) g.add_edges(u, v)
n = g.number_of_nodes() n = g.num_nodes()
feat_size = 128 ## arbitrary number feat_size = 128 ## arbitrary number
feats = th.empty([n, feat_size], dtype=th.float32) feats = th.empty([n, feat_size], dtype=th.float32)
......
...@@ -121,7 +121,7 @@ def _get_shared_mem_ndata(g, graph_name, name): ...@@ -121,7 +121,7 @@ def _get_shared_mem_ndata(g, graph_name, name):
This is called by the DistGraph client to access the node data in the DistGraph server This is called by the DistGraph client to access the node data in the DistGraph server
with shared memory. with shared memory.
""" """
shape = (g.number_of_nodes(),) shape = (g.num_nodes(),)
dtype = RESERVED_FIELD_DTYPE[name] dtype = RESERVED_FIELD_DTYPE[name]
dtype = DTYPE_DICT[dtype] dtype = DTYPE_DICT[dtype]
data = empty_shared_mem( data = empty_shared_mem(
...@@ -137,7 +137,7 @@ def _get_shared_mem_edata(g, graph_name, name): ...@@ -137,7 +137,7 @@ def _get_shared_mem_edata(g, graph_name, name):
This is called by the DistGraph client to access the edge data in the DistGraph server This is called by the DistGraph client to access the edge data in the DistGraph server
with shared memory. with shared memory.
""" """
shape = (g.number_of_edges(),) shape = (g.num_edges(),)
dtype = RESERVED_FIELD_DTYPE[name] dtype = RESERVED_FIELD_DTYPE[name]
dtype = DTYPE_DICT[dtype] dtype = DTYPE_DICT[dtype]
data = empty_shared_mem( data = empty_shared_mem(
...@@ -1079,7 +1079,7 @@ class DistGraph: ...@@ -1079,7 +1079,7 @@ class DistGraph:
in_degrees in_degrees
""" """
if is_all(u): if is_all(u):
u = F.arange(0, self.number_of_nodes()) u = F.arange(0, self.num_nodes())
return dist_out_degrees(self, u) return dist_out_degrees(self, u)
def in_degrees(self, v=ALL): def in_degrees(self, v=ALL):
...@@ -1128,7 +1128,7 @@ class DistGraph: ...@@ -1128,7 +1128,7 @@ class DistGraph:
out_degrees out_degrees
""" """
if is_all(v): if is_all(v):
v = F.arange(0, self.number_of_nodes()) v = F.arange(0, self.num_nodes())
return dist_in_degrees(self, v) return dist_in_degrees(self, v)
def node_attr_schemes(self): def node_attr_schemes(self):
...@@ -1281,16 +1281,14 @@ class DistGraph: ...@@ -1281,16 +1281,14 @@ class DistGraph:
for etype, edge in edges.items(): for etype, edge in edges.items():
etype = self.to_canonical_etype(etype) etype = self.to_canonical_etype(etype)
subg[etype] = self.find_edges(edge, etype) subg[etype] = self.find_edges(edge, etype)
num_nodes = { num_nodes = {ntype: self.num_nodes(ntype) for ntype in self.ntypes}
ntype: self.number_of_nodes(ntype) for ntype in self.ntypes
}
subg = dgl_heterograph(subg, num_nodes_dict=num_nodes) subg = dgl_heterograph(subg, num_nodes_dict=num_nodes)
for etype in edges: for etype in edges:
subg.edges[etype].data[EID] = edges[etype] subg.edges[etype].data[EID] = edges[etype]
else: else:
assert len(self.etypes) == 1 assert len(self.etypes) == 1
subg = self.find_edges(edges) subg = self.find_edges(edges)
subg = dgl_graph(subg, num_nodes=self.number_of_nodes()) subg = dgl_graph(subg, num_nodes=self.num_nodes())
subg.edata[EID] = edges subg.edata[EID] = edges
if relabel_nodes: if relabel_nodes:
......
...@@ -90,7 +90,7 @@ class DistTensor: ...@@ -90,7 +90,7 @@ class DistTensor:
Examples Examples
-------- --------
>>> init = lambda shape, dtype: th.ones(shape, dtype=dtype) >>> init = lambda shape, dtype: th.ones(shape, dtype=dtype)
>>> arr = dgl.distributed.DistTensor((g.number_of_nodes(), 2), th.int32, init_func=init) >>> arr = dgl.distributed.DistTensor((g.num_nodes(), 2), th.int32, init_func=init)
>>> print(arr[0:3]) >>> print(arr[0:3])
tensor([[1, 1], tensor([[1, 1],
[1, 1], [1, 1],
......
...@@ -525,19 +525,19 @@ def _distributed_access(g, nodes, issue_remote_req, local_access): ...@@ -525,19 +525,19 @@ def _distributed_access(g, nodes, issue_remote_req, local_access):
results = recv_responses(msgseq2pos) results = recv_responses(msgseq2pos)
res_list.extend(results) res_list.extend(results)
sampled_graph = merge_graphs(res_list, g.number_of_nodes()) sampled_graph = merge_graphs(res_list, g.num_nodes())
return sampled_graph return sampled_graph
def _frontier_to_heterogeneous_graph(g, frontier, gpb): def _frontier_to_heterogeneous_graph(g, frontier, gpb):
# We need to handle empty frontiers correctly. # We need to handle empty frontiers correctly.
if frontier.number_of_edges() == 0: if frontier.num_edges() == 0:
data_dict = { data_dict = {
etype: (np.zeros(0), np.zeros(0)) for etype in g.canonical_etypes etype: (np.zeros(0), np.zeros(0)) for etype in g.canonical_etypes
} }
return heterograph( return heterograph(
data_dict, data_dict,
{ntype: g.number_of_nodes(ntype) for ntype in g.ntypes}, {ntype: g.num_nodes(ntype) for ntype in g.ntypes},
idtype=g.idtype, idtype=g.idtype,
) )
...@@ -561,7 +561,7 @@ def _frontier_to_heterogeneous_graph(g, frontier, gpb): ...@@ -561,7 +561,7 @@ def _frontier_to_heterogeneous_graph(g, frontier, gpb):
edge_ids[etype] = F.boolean_mask(eid, type_idx) edge_ids[etype] = F.boolean_mask(eid, type_idx)
hg = heterograph( hg = heterograph(
data_dict, data_dict,
{ntype: g.number_of_nodes(ntype) for ntype in g.ntypes}, {ntype: g.num_nodes(ntype) for ntype in g.ntypes},
idtype=g.idtype, idtype=g.idtype,
) )
......
...@@ -50,7 +50,7 @@ class DistEmbedding: ...@@ -50,7 +50,7 @@ class DistEmbedding:
arr = th.zeros(shape, dtype=dtype) arr = th.zeros(shape, dtype=dtype)
arr.uniform_(-1, 1) arr.uniform_(-1, 1)
return arr return arr
>>> emb = dgl.distributed.DistEmbedding(g.number_of_nodes(), 10, init_func=initializer) >>> emb = dgl.distributed.DistEmbedding(g.num_nodes(), 10, init_func=initializer)
>>> optimizer = dgl.distributed.optim.SparseAdagrad([emb], lr=0.001) >>> optimizer = dgl.distributed.optim.SparseAdagrad([emb], lr=0.001)
>>> for blocks in dataloader: >>> for blocks in dataloader:
... feats = emb(nids) ... feats = emb(nids)
......
...@@ -748,7 +748,7 @@ def partition_graph( ...@@ -748,7 +748,7 @@ def partition_graph(
num_ntypes += len(uniq_ntypes) num_ntypes += len(uniq_ntypes)
else: else:
g.nodes[key].data["bal_ntype"] = ( g.nodes[key].data["bal_ntype"] = (
F.ones((g.number_of_nodes(key),), F.int32, F.cpu()) F.ones((g.num_nodes(key),), F.int32, F.cpu())
* num_ntypes * num_ntypes
) )
num_ntypes += 1 num_ntypes += 1
...@@ -798,34 +798,33 @@ def partition_graph( ...@@ -798,34 +798,33 @@ def partition_graph(
) )
) )
node_parts = F.zeros((sim_g.number_of_nodes(),), F.int64, F.cpu()) node_parts = F.zeros((sim_g.num_nodes(),), F.int64, F.cpu())
parts = {0: sim_g.clone()} parts = {0: sim_g.clone()}
orig_nids = parts[0].ndata[NID] = F.arange(0, sim_g.number_of_nodes()) orig_nids = parts[0].ndata[NID] = F.arange(0, sim_g.num_nodes())
orig_eids = parts[0].edata[EID] = F.arange(0, sim_g.number_of_edges()) orig_eids = parts[0].edata[EID] = F.arange(0, sim_g.num_edges())
# For one partition, we don't really shuffle nodes and edges. We just need to simulate # For one partition, we don't really shuffle nodes and edges. We just need to simulate
# it and set node data and edge data of orig_id. # it and set node data and edge data of orig_id.
parts[0].ndata["orig_id"] = orig_nids parts[0].ndata["orig_id"] = orig_nids
parts[0].edata["orig_id"] = orig_eids parts[0].edata["orig_id"] = orig_eids
if return_mapping: if return_mapping:
if g.is_homogeneous: if g.is_homogeneous:
orig_nids = F.arange(0, sim_g.number_of_nodes()) orig_nids = F.arange(0, sim_g.num_nodes())
orig_eids = F.arange(0, sim_g.number_of_edges()) orig_eids = F.arange(0, sim_g.num_edges())
else: else:
orig_nids = { orig_nids = {
ntype: F.arange(0, g.number_of_nodes(ntype)) ntype: F.arange(0, g.num_nodes(ntype)) for ntype in g.ntypes
for ntype in g.ntypes
} }
orig_eids = { orig_eids = {
etype: F.arange(0, g.number_of_edges(etype)) etype: F.arange(0, g.num_edges(etype))
for etype in g.canonical_etypes for etype in g.canonical_etypes
} }
parts[0].ndata["inner_node"] = F.ones( parts[0].ndata["inner_node"] = F.ones(
(sim_g.number_of_nodes(),), (sim_g.num_nodes(),),
RESERVED_FIELD_DTYPE["inner_node"], RESERVED_FIELD_DTYPE["inner_node"],
F.cpu(), F.cpu(),
) )
parts[0].edata["inner_edge"] = F.ones( parts[0].edata["inner_edge"] = F.ones(
(sim_g.number_of_edges(),), (sim_g.num_edges(),),
RESERVED_FIELD_DTYPE["inner_edge"], RESERVED_FIELD_DTYPE["inner_edge"],
F.cpu(), F.cpu(),
) )
...@@ -870,7 +869,7 @@ def partition_graph( ...@@ -870,7 +869,7 @@ def partition_graph(
) )
) )
else: else:
node_parts = random_choice(num_parts, sim_g.number_of_nodes()) node_parts = random_choice(num_parts, sim_g.num_nodes())
start = time.time() start = time.time()
parts, orig_nids, orig_eids = partition_graph_with_halo( parts, orig_nids, orig_eids = partition_graph_with_halo(
sim_g, node_parts, num_hops, reshuffle=True sim_g, node_parts, num_hops, reshuffle=True
...@@ -971,7 +970,7 @@ def partition_graph( ...@@ -971,7 +970,7 @@ def partition_graph(
] ]
) )
val = np.cumsum(val).tolist() val = np.cumsum(val).tolist()
assert val[-1] == g.number_of_nodes(ntype) assert val[-1] == g.num_nodes(ntype)
for etype in g.canonical_etypes: for etype in g.canonical_etypes:
etype_id = g.get_etype_id(etype) etype_id = g.get_etype_id(etype)
val = [] val = []
...@@ -990,7 +989,7 @@ def partition_graph( ...@@ -990,7 +989,7 @@ def partition_graph(
[int(inner_eids[0]), int(inner_eids[-1]) + 1] [int(inner_eids[0]), int(inner_eids[-1]) + 1]
) )
val = np.cumsum(val).tolist() val = np.cumsum(val).tolist()
assert val[-1] == g.number_of_edges(etype) assert val[-1] == g.num_edges(etype)
else: else:
node_map_val = {} node_map_val = {}
edge_map_val = {} edge_map_val = {}
...@@ -1028,8 +1027,8 @@ def partition_graph( ...@@ -1028,8 +1027,8 @@ def partition_graph(
etypes = {etype: g.get_etype_id(etype) for etype in g.canonical_etypes} etypes = {etype: g.get_etype_id(etype) for etype in g.canonical_etypes}
part_metadata = { part_metadata = {
"graph_name": graph_name, "graph_name": graph_name,
"num_nodes": g.number_of_nodes(), "num_nodes": g.num_nodes(),
"num_edges": g.number_of_edges(), "num_edges": g.num_edges(),
"part_method": part_method, "part_method": part_method,
"num_parts": num_parts, "num_parts": num_parts,
"halo_hops": num_hops, "halo_hops": num_hops,
...@@ -1071,7 +1070,7 @@ def partition_graph( ...@@ -1071,7 +1070,7 @@ def partition_graph(
else: else:
print( print(
"part {} has {} nodes and {} are inside the partition".format( "part {} has {} nodes and {} are inside the partition".format(
part_id, part.number_of_nodes(), len(local_nodes) part_id, part.num_nodes(), len(local_nodes)
) )
) )
...@@ -1105,7 +1104,7 @@ def partition_graph( ...@@ -1105,7 +1104,7 @@ def partition_graph(
else: else:
print( print(
"part {} has {} edges and {} are inside the partition".format( "part {} has {} edges and {} are inside the partition".format(
part_id, part.number_of_edges(), len(local_edges) part_id, part.num_edges(), len(local_edges)
) )
) )
tot_num_inner_edges += len(local_edges) tot_num_inner_edges += len(local_edges)
...@@ -1185,12 +1184,12 @@ def partition_graph( ...@@ -1185,12 +1184,12 @@ def partition_graph(
_dump_part_config(f"{out_path}/{graph_name}.json", part_metadata) _dump_part_config(f"{out_path}/{graph_name}.json", part_metadata)
num_cuts = sim_g.number_of_edges() - tot_num_inner_edges num_cuts = sim_g.num_edges() - tot_num_inner_edges
if num_parts == 1: if num_parts == 1:
num_cuts = 0 num_cuts = 0
print( print(
"There are {} edges in the graph and {} edge cuts for {} partitions.".format( "There are {} edges in the graph and {} edge cuts for {} partitions.".format(
g.number_of_edges(), num_cuts, num_parts g.num_edges(), num_cuts, num_parts
) )
) )
......
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