-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest_gds_EdgeNeighborLoader.py
166 lines (152 loc) · 5.54 KB
/
test_gds_EdgeNeighborLoader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import unittest
from pyTigerGraphUnitTest import make_connection
from torch_geometric.data import Data as pygData
from pyTigerGraph.gds.dataloaders import EdgeNeighborLoader
from pyTigerGraph.gds.utilities import is_query_installed
class TestGDSEdgeNeighborLoaderKafka(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.conn = make_connection(graphname="Cora")
def test_iterate_pyg(self):
loader = EdgeNeighborLoader(
graph=self.conn,
v_in_feats=["x"],
e_extra_feats=["is_train"],
batch_size=1024,
num_neighbors=10,
num_hops=2,
shuffle=False,
filter_by=None,
output_format="PyG",
add_self_loop=False,
loader_id=None,
buffer_size=4,
kafka_address="kafka:9092",
)
num_batches = 0
for data in loader:
# print(num_batches, data)
self.assertIsInstance(data, pygData)
self.assertIn("x", data)
self.assertIn("is_seed", data)
self.assertIn("is_train", data)
self.assertGreater(data["x"].shape[0], 0)
self.assertGreater(data["edge_index"].shape[1], 0)
num_batches += 1
self.assertEqual(num_batches, 11)
def test_sasl_ssl(self):
loader = EdgeNeighborLoader(
graph=self.conn,
v_in_feats=["x"],
e_extra_feats=["is_train"],
batch_size=1024,
num_neighbors=10,
num_hops=2,
shuffle=False,
filter_by=None,
output_format="PyG",
add_self_loop=False,
loader_id=None,
buffer_size=4,
kafka_address="pkc-6ojv2.us-west4.gcp.confluent.cloud:9092",
kafka_replica_factor=3,
kafka_max_msg_size=8388608,
kafka_security_protocol="SASL_SSL",
kafka_sasl_mechanism="PLAIN",
kafka_sasl_plain_username="YIQM66T3BZZLSXBJ",
kafka_sasl_plain_password="UgRdpSS34e2kYe8jZ9m7py4LgjkjxsGrePiaaMv/YCHRIjRmTJMpodS/0og8SYe8",
kafka_producer_ca_location="/home/tigergraph/mlworkbench/ssl/cert.pem",
)
num_batches = 0
for data in loader:
# print(num_batches, data)
self.assertIsInstance(data, pygData)
self.assertIn("x", data)
self.assertIn("is_seed", data)
self.assertIn("is_train", data)
self.assertGreater(data["x"].shape[0], 0)
self.assertGreater(data["edge_index"].shape[1], 0)
num_batches += 1
self.assertEqual(num_batches, 11)
class TestGDSEdgeNeighborLoaderREST(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.conn = make_connection(graphname="Cora")
def test_init(self):
loader = EdgeNeighborLoader(
graph=self.conn,
v_in_feats=["x"],
e_extra_feats=["is_train"],
batch_size=1024,
num_neighbors=10,
num_hops=2,
shuffle=False,
filter_by=None,
output_format="PyG",
add_self_loop=False,
loader_id=None,
buffer_size=4,
)
self.assertTrue(is_query_installed(self.conn, loader.query_name))
self.assertEqual(loader.num_batches, 11)
def test_iterate_pyg(self):
loader = EdgeNeighborLoader(
graph=self.conn,
v_in_feats=["x"],
e_extra_feats=["is_train"],
batch_size=1024,
num_neighbors=10,
num_hops=2,
shuffle=False,
filter_by=None,
output_format="PyG",
add_self_loop=False,
loader_id=None,
buffer_size=4,
)
num_batches = 0
for data in loader:
# print(num_batches, data)
self.assertIsInstance(data, pygData)
self.assertIn("x", data)
self.assertIn("is_seed", data)
self.assertIn("is_train", data)
self.assertGreater(data["x"].shape[0], 0)
self.assertGreater(data["edge_index"].shape[1], 0)
num_batches += 1
self.assertEqual(num_batches, 11)
def test_iterate_spektral(self):
loader = EdgeNeighborLoader(
graph=self.conn,
v_in_feats=["x"],
e_extra_feats=["is_train"],
batch_size=1024,
num_neighbors=10,
num_hops=2,
shuffle=False,
filter_by=None,
output_format="spektral",
add_self_loop=False,
loader_id=None,
buffer_size=4,
)
num_batches = 0
for data in loader:
# print(num_batches, data)
# self.assertIsInstance(data, spData)
self.assertIn("x", data)
self.assertIn("is_seed", data)
self.assertIn("is_train", data)
self.assertGreater(data["x"].shape[0], 0)
self.assertGreater(data["A"].shape[1], 0)
num_batches += 1
self.assertEqual(num_batches, 11)
if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(TestGDSEdgeNeighborLoaderKafka("test_iterate_pyg"))
# suite.addTest(TestGDSEdgeNeighborLoaderKafka("test_sasl_ssl"))
suite.addTest(TestGDSEdgeNeighborLoaderREST("test_init"))
suite.addTest(TestGDSEdgeNeighborLoaderREST("test_iterate_pyg"))
# suite.addTest(TestGDSEdgeNeighborLoaderREST("test_iterate_spektral"))
runner = unittest.TextTestRunner(verbosity=2, failfast=True)
runner.run(suite)