Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
5c7681b2
Unverified
Commit
5c7681b2
authored
Aug 06, 2023
by
Andrei Ivanov
Committed by
GitHub
Aug 07, 2023
Browse files
Removing warnings appearing in heterograph tests (#6095)
Co-authored-by:
Xin Yao
<
xiny@nvidia.com
>
parent
8b35cbc8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
56 deletions
+36
-56
tests/python/common/test_heterograph-kernel.py
tests/python/common/test_heterograph-kernel.py
+3
-3
tests/python/common/test_heterograph-misc.py
tests/python/common/test_heterograph-misc.py
+12
-21
tests/python/common/test_heterograph-remove.py
tests/python/common/test_heterograph-remove.py
+16
-27
tests/python/common/test_heterograph-specialization.py
tests/python/common/test_heterograph-specialization.py
+4
-4
tests/python/pytorch/test_heterograph-pickle.py
tests/python/pytorch/test_heterograph-pickle.py
+1
-1
No files found.
tests/python/common/test_heterograph-kernel.py
View file @
5c7681b2
...
...
@@ -89,7 +89,7 @@ def generate_feature(g, broadcast="none", binary_op="none"):
def
test_copy_src_reduce
():
def
_test
(
red
,
partial
):
g
=
dgl
.
DGLGraph
(
nx
.
erdos_renyi_graph
(
100
,
0.1
))
g
=
dgl
.
from_networkx
(
nx
.
erdos_renyi_graph
(
100
,
0.1
))
# NOTE(zihao): add self-loop to avoid zero-degree nodes.
# https://github.com/dmlc/dgl/issues/761
g
.
add_edges
(
g
.
nodes
(),
g
.
nodes
())
...
...
@@ -157,7 +157,7 @@ def test_copy_src_reduce():
def
test_copy_edge_reduce
():
def
_test
(
red
,
partial
):
g
=
dgl
.
DGLGraph
(
nx
.
erdos_renyi_graph
(
100
,
0.1
))
g
=
dgl
.
from_networkx
(
nx
.
erdos_renyi_graph
(
100
,
0.1
))
# NOTE(zihao): add self-loop to avoid zero-degree nodes.
g
.
add_edges
(
g
.
nodes
(),
g
.
nodes
())
g
=
g
.
to
(
F
.
ctx
())
...
...
@@ -360,7 +360,7 @@ def test_all_binary_builtins():
_print_error
(
rhs_grad_1
,
rhs_grad_2
)
assert
F
.
allclose
(
rhs_grad_1
,
rhs_grad_2
,
rtol
,
atol
)
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
.
add_nodes
(
20
)
# NOTE(zihao): add self-loop to avoid zero-degree nodes.
g
.
add_edges
(
g
.
nodes
(),
g
.
nodes
())
...
...
tests/python/common/test_heterograph-misc.py
View file @
5c7681b2
...
...
@@ -54,17 +54,13 @@ def scipy_csr_input():
def
gen_by_mutation
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
src
,
dst
=
edge_pair_input
()
g
.
add_nodes
(
10
)
g
.
add_edges
(
src
,
dst
)
return
g
def
gen_from_data
(
data
,
readonly
,
sort
):
return
dgl
.
DGLGraph
(
data
,
readonly
=
readonly
,
sort_csr
=
True
)
def
test_query
():
def
_test_one
(
g
):
assert
g
.
num_nodes
()
==
10
...
...
@@ -275,19 +271,14 @@ def test_query():
eid
=
g
.
edge_ids
(
0
,
4
)
_test
(
gen_by_mutation
())
_test
(
gen_from_data
(
elist_input
(),
False
,
False
))
_test
(
gen_from_data
(
elist_input
(),
True
,
False
))
_test
(
gen_from_data
(
elist_input
(),
True
,
True
))
_test
(
gen_from_data
(
scipy_coo_input
(),
False
,
False
))
_test
(
gen_from_data
(
scipy_coo_input
(),
True
,
False
))
_test_csr
(
gen_from_data
(
scipy_csr_input
(),
False
,
False
))
_test_csr
(
gen_from_data
(
scipy_csr_input
(),
True
,
False
))
_test
(
dgl
.
graph
(
elist_input
()))
_test
(
dgl
.
from_scipy
(
scipy_coo_input
()))
_test_csr
(
dgl
.
from_scipy
(
scipy_csr_input
()))
_test_edge_ids
()
def
test_mutation
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
=
g
.
to
(
F
.
ctx
())
# test add nodes with data
g
.
add_nodes
(
5
)
...
...
@@ -304,7 +295,7 @@ def test_mutation():
def
test_scipy_adjmat
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
.
add_nodes
(
10
)
g
.
add_edges
(
range
(
9
),
range
(
1
,
10
))
...
...
@@ -318,7 +309,7 @@ def test_scipy_adjmat():
def
test_incmat
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
.
add_nodes
(
4
)
g
.
add_edges
(
0
,
1
)
# 0
g
.
add_edges
(
0
,
2
)
# 1
...
...
@@ -367,7 +358,7 @@ def test_incmat():
def
test_find_edges
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
.
add_nodes
(
10
)
g
.
add_edges
(
range
(
9
),
range
(
1
,
10
))
e
=
g
.
find_edges
([
1
,
3
,
2
,
4
])
...
...
@@ -394,7 +385,7 @@ def test_find_edges():
def
test_ismultigraph
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
.
add_nodes
(
10
)
assert
g
.
is_multigraph
==
False
g
.
add_edges
([
0
],
[
0
])
...
...
@@ -406,7 +397,7 @@ def test_ismultigraph():
def
test_hypersparse_query
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
=
g
.
to
(
F
.
ctx
())
g
.
add_nodes
(
1000001
)
g
.
add_edges
([
0
],
[
1
])
...
...
@@ -425,7 +416,7 @@ def test_hypersparse_query():
def
test_empty_data_initialized
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
=
g
.
to
(
F
.
ctx
())
g
.
ndata
[
"ha"
]
=
F
.
tensor
([])
g
.
add_nodes
(
1
,
{
"hb"
:
F
.
tensor
([
1
])})
...
...
@@ -460,7 +451,7 @@ def test_is_sorted():
def
test_default_types
():
dg
=
dgl
.
DGLG
raph
()
dg
=
dgl
.
g
raph
(
[]
)
g
=
dgl
.
graph
(([],
[]))
assert
dg
.
ntypes
==
g
.
ntypes
assert
dg
.
etypes
==
g
.
etypes
...
...
tests/python/common/test_heterograph-remove.py
View file @
5c7681b2
...
...
@@ -5,11 +5,16 @@ import numpy as np
from
utils
import
parametrize_idtype
def
create_graph
(
idtype
,
num_node
):
g
=
dgl
.
graph
([])
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
num_node
)
return
g
@
parametrize_idtype
def
test_node_removal
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
g
=
create_graph
(
idtype
,
10
)
g
.
add_edges
(
0
,
0
)
assert
g
.
num_nodes
()
==
10
g
.
ndata
[
"id"
]
=
F
.
arange
(
0
,
10
)
...
...
@@ -38,9 +43,7 @@ def test_node_removal(idtype):
@
parametrize_idtype
def
test_multigraph_node_removal
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
5
)
g
=
create_graph
(
idtype
,
5
)
for
i
in
range
(
5
):
g
.
add_edges
(
i
,
i
)
g
.
add_edges
(
i
,
i
)
...
...
@@ -67,9 +70,7 @@ def test_multigraph_node_removal(idtype):
@
parametrize_idtype
def
test_multigraph_edge_removal
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
5
)
g
=
create_graph
(
idtype
,
5
)
for
i
in
range
(
5
):
g
.
add_edges
(
i
,
i
)
g
.
add_edges
(
i
,
i
)
...
...
@@ -95,9 +96,7 @@ def test_multigraph_edge_removal(idtype):
@
parametrize_idtype
def
test_edge_removal
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
5
)
g
=
create_graph
(
idtype
,
5
)
for
i
in
range
(
5
):
for
j
in
range
(
5
):
g
.
add_edges
(
i
,
j
)
...
...
@@ -133,9 +132,7 @@ def test_edge_removal(idtype):
@
parametrize_idtype
def
test_node_and_edge_removal
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
g
=
create_graph
(
idtype
,
10
)
for
i
in
range
(
10
):
for
j
in
range
(
10
):
g
.
add_edges
(
i
,
j
)
...
...
@@ -173,9 +170,7 @@ def test_node_and_edge_removal(idtype):
@
parametrize_idtype
def
test_node_frame
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
g
=
create_graph
(
idtype
,
10
)
data
=
np
.
random
.
rand
(
10
,
3
)
new_data
=
data
.
take
([
0
,
1
,
2
,
7
,
8
,
9
],
axis
=
0
)
g
.
ndata
[
"h"
]
=
F
.
tensor
(
data
)
...
...
@@ -187,9 +182,7 @@ def test_node_frame(idtype):
@
parametrize_idtype
def
test_edge_frame
(
idtype
):
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
g
=
create_graph
(
idtype
,
10
)
g
.
add_edges
(
list
(
range
(
10
)),
list
(
range
(
1
,
10
))
+
[
0
])
data
=
np
.
random
.
rand
(
10
,
3
)
new_data
=
data
.
take
([
0
,
1
,
2
,
7
,
8
,
9
],
axis
=
0
)
...
...
@@ -204,18 +197,14 @@ def test_edge_frame(idtype):
def
test_issue1287
(
idtype
):
# reproduce https://github.com/dmlc/dgl/issues/1287.
# setting features after remove nodes
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
5
)
g
=
create_graph
(
idtype
,
5
)
g
.
add_edges
([
0
,
2
,
3
,
1
,
1
],
[
1
,
0
,
3
,
1
,
0
])
g
.
remove_nodes
([
0
,
1
])
g
.
ndata
[
"h"
]
=
F
.
randn
((
g
.
num_nodes
(),
3
))
g
.
edata
[
"h"
]
=
F
.
randn
((
g
.
num_edges
(),
2
))
# remove edges
g
=
dgl
.
DGLGraph
()
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
5
)
g
=
create_graph
(
idtype
,
5
)
g
.
add_edges
([
0
,
2
,
3
,
1
,
1
],
[
1
,
0
,
3
,
1
,
0
])
g
.
remove_edges
([
0
,
1
])
g
=
g
.
to
(
F
.
ctx
())
...
...
tests/python/common/test_heterograph-specialization.py
View file @
5c7681b2
...
...
@@ -10,7 +10,7 @@ D = 5
def
generate_graph
(
idtype
):
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
# create a graph where 0 is the source and 9 is the sink
...
...
@@ -183,7 +183,7 @@ def test_v2v_pull(idtype):
@
parametrize_idtype
def
test_update_all_multi_fallback
(
idtype
):
# create a graph with zero in degree nodes
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
for
i
in
range
(
1
,
9
):
...
...
@@ -237,7 +237,7 @@ def test_update_all_multi_fallback(idtype):
@
parametrize_idtype
def
test_pull_multi_fallback
(
idtype
):
# create a graph with zero in degree nodes
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
for
i
in
range
(
1
,
9
):
...
...
@@ -317,7 +317,7 @@ def test_spmv_3d_feat(idtype):
n
=
100
p
=
0.1
a
=
sp
.
random
(
n
,
n
,
p
,
data_rvs
=
lambda
n
:
np
.
ones
(
n
))
g
=
dgl
.
DGLGraph
(
a
)
g
=
dgl
.
from_scipy
(
a
)
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
m
=
g
.
num_edges
()
...
...
tests/python/pytorch/test_heterograph-pickle.py
View file @
5c7681b2
...
...
@@ -20,7 +20,7 @@ def test_pickling_batched_graph():
# NOTE: this is a test for a wierd bug mentioned in
# https://github.com/dmlc/dgl/issues/438
glist
=
[
nx
.
path_graph
(
i
+
5
)
for
i
in
range
(
5
)]
glist
=
[
dgl
.
DGLGraph
(
g
)
for
g
in
glist
]
glist
=
[
dgl
.
from_networkx
(
g
)
for
g
in
glist
]
bg
=
dgl
.
batch
(
glist
)
bg
.
ndata
[
"x"
]
=
torch
.
randn
((
35
,
5
))
bg
.
edata
[
"y"
]
=
torch
.
randn
((
60
,
3
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment