"projects/PointRend/point_rend/point_features.py" did not exist on "5b3792fc3ef9ab6a6f8f30634ab2e52fb0941af3"
test_pipeline.py 8.18 KB
Newer Older
Mufei Li's avatar
Mufei Li committed
1
import os
2

Mufei Li's avatar
Mufei Li committed
3
4
import pytest

5
6
7
8
9
10
11
12
13
14
15
16
17
18

@pytest.mark.parametrize(
    "data",
    [
        "cora",
        "citeseer",
        "pubmed",
        "csv",
        "reddit",
        "co-buy-computer",
        "ogbn-arxiv",
        "ogbn-products",
    ],
)
Minjie Wang's avatar
Minjie Wang committed
19
def test_nodepred_data(data):
20
21
    os.system(f"dgl configure nodepred --data {data} --model gcn")
    assert os.path.exists(f"nodepred_{data}_gcn.yaml")
Minjie Wang's avatar
Minjie Wang committed
22

23
24
25
26
    custom_cfg = f"custom_{data}_gcn.yaml"
    os.system(
        f"dgl configure nodepred --data {data} --model gcn --cfg {custom_cfg}"
    )
Minjie Wang's avatar
Minjie Wang committed
27
28
    assert os.path.exists(custom_cfg)

29
30
    custom_script = f"{data}_gcn.py"
    os.system(f"dgl export --cfg {custom_cfg} --output {custom_script}")
Minjie Wang's avatar
Minjie Wang committed
31
32
    assert os.path.exists(custom_script)

33
34

@pytest.mark.parametrize("model", ["gcn", "gat", "sage", "sgc", "gin"])
Minjie Wang's avatar
Minjie Wang committed
35
def test_nodepred_model(model):
36
37
    os.system(f"dgl configure nodepred --data cora --model {model}")
    assert os.path.exists(f"nodepred_cora_{model}.yaml")
Mufei Li's avatar
Mufei Li committed
38

39
40
41
42
    custom_cfg = f"custom_cora_{model}.yaml"
    os.system(
        f"dgl configure nodepred --data cora --model {model} --cfg {custom_cfg}"
    )
Minjie Wang's avatar
Minjie Wang committed
43
    assert os.path.exists(custom_cfg)
Mufei Li's avatar
Mufei Li committed
44

45
46
    custom_script = f"cora_{model}.py"
    os.system(f"dgl export --cfg {custom_cfg} --output {custom_script}")
Mufei Li's avatar
Mufei Li committed
47
48
    assert os.path.exists(custom_script)

49
50
51
52
53
54
55
56
57
58
59
60
61
62

@pytest.mark.parametrize(
    "data",
    [
        "cora",
        "citeseer",
        "pubmed",
        "csv",
        "reddit",
        "co-buy-computer",
        "ogbn-arxiv",
        "ogbn-products",
    ],
)
Minjie Wang's avatar
Minjie Wang committed
63
def test_nodepred_ns_data(data):
64
65
    os.system(f"dgl configure nodepred-ns --data {data} --model gcn")
    assert os.path.exists(f"nodepred-ns_{data}_gcn.yaml")
Minjie Wang's avatar
Minjie Wang committed
66

67
68
69
70
    custom_cfg = f"ns-custom_{data}_gcn.yaml"
    os.system(
        f"dgl configure nodepred-ns --data {data} --model gcn --cfg {custom_cfg}"
    )
Minjie Wang's avatar
Minjie Wang committed
71
72
    assert os.path.exists(custom_cfg)

73
74
    custom_script = f"ns-{data}_gcn.py"
    os.system(f"dgl export --cfg {custom_cfg} --output {custom_script}")
Minjie Wang's avatar
Minjie Wang committed
75
76
77
    assert os.path.exists(custom_script)


78
@pytest.mark.parametrize("model", ["gcn", "gat", "sage"])
Minjie Wang's avatar
Minjie Wang committed
79
def test_nodepred_ns_model(model):
80
81
    os.system(f"dgl configure nodepred-ns --data cora --model {model}")
    assert os.path.exists(f"nodepred-ns_cora_{model}.yaml")
Mufei Li's avatar
Mufei Li committed
82

83
84
85
86
    custom_cfg = f"ns-custom_cora_{model}.yaml"
    os.system(
        f"dgl configure nodepred-ns --data cora --model {model} --cfg {custom_cfg}"
    )
Minjie Wang's avatar
Minjie Wang committed
87
    assert os.path.exists(custom_cfg)
Mufei Li's avatar
Mufei Li committed
88

89
90
    custom_script = f"ns-cora_{model}.py"
    os.system(f"dgl export --cfg {custom_cfg} --output {custom_script}")
Mufei Li's avatar
Mufei Li committed
91
92
    assert os.path.exists(custom_script)

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

@pytest.mark.parametrize(
    "data",
    [
        "cora",
        "citeseer",
        "pubmed",
        "csv",
        "reddit",
        "co-buy-computer",
        "ogbn-arxiv",
        "ogbn-products",
        "ogbl-collab",
        "ogbl-citation2",
    ],
)
Minjie Wang's avatar
Minjie Wang committed
109
def test_linkpred_data(data):
110
111
112
113
114
115
116
117
118
    node_model = "gcn"
    edge_model = "ele"
    neg_sampler = "global"
    custom_cfg = "_".join([data, node_model, edge_model, neg_sampler]) + ".yaml"
    os.system(
        "dgl configure linkpred --data {} --node-model {} --edge-model {} --neg-sampler {} --cfg {}".format(
            data, node_model, edge_model, neg_sampler, custom_cfg
        )
    )
Minjie Wang's avatar
Minjie Wang committed
119
    assert os.path.exists(custom_cfg)
Mufei Li's avatar
Mufei Li committed
120

121
122
123
124
125
126
    custom_script = (
        "_".join([data, node_model, edge_model, neg_sampler]) + ".py"
    )
    os.system(
        "dgl export --cfg {} --output {}".format(custom_cfg, custom_script)
    )
Mufei Li's avatar
Mufei Li committed
127
128
    assert os.path.exists(custom_script)

129
130

@pytest.mark.parametrize("node_model", ["gcn", "gat", "sage", "sgc", "gin"])
Minjie Wang's avatar
Minjie Wang committed
131
def test_linkpred_node_model(node_model):
132
133
134
135
136
137
138
139
140
    data = "cora"
    edge_model = "ele"
    neg_sampler = "global"
    custom_cfg = "_".join([data, node_model, edge_model, neg_sampler]) + ".yaml"
    os.system(
        "dgl configure linkpred --data {} --node-model {} --edge-model {} --neg-sampler {} --cfg {}".format(
            data, node_model, edge_model, neg_sampler, custom_cfg
        )
    )
Minjie Wang's avatar
Minjie Wang committed
141
142
    assert os.path.exists(custom_cfg)

143
144
145
146
147
148
    custom_script = (
        "_".join([data, node_model, edge_model, neg_sampler]) + ".py"
    )
    os.system(
        "dgl export --cfg {} --output {}".format(custom_cfg, custom_script)
    )
Minjie Wang's avatar
Minjie Wang committed
149
150
151
    assert os.path.exists(custom_script)


152
@pytest.mark.parametrize("edge_model", ["ele", "bilinear"])
Minjie Wang's avatar
Minjie Wang committed
153
def test_linkpred_edge_model(edge_model):
154
155
156
157
158
159
160
161
162
    data = "cora"
    node_model = "gcn"
    neg_sampler = "global"
    custom_cfg = "_".join([data, node_model, edge_model, neg_sampler]) + ".yaml"
    os.system(
        "dgl configure linkpred --data {} --node-model {} --edge-model {} --neg-sampler {} --cfg {}".format(
            data, node_model, edge_model, neg_sampler, custom_cfg
        )
    )
Minjie Wang's avatar
Minjie Wang committed
163
164
    assert os.path.exists(custom_cfg)

165
166
167
168
169
170
    custom_script = (
        "_".join([data, node_model, edge_model, neg_sampler]) + ".py"
    )
    os.system(
        "dgl export --cfg {} --output {}".format(custom_cfg, custom_script)
    )
Minjie Wang's avatar
Minjie Wang committed
171
172
173
    assert os.path.exists(custom_script)


174
@pytest.mark.parametrize("neg_sampler", ["global", "persource", ""])
Minjie Wang's avatar
Minjie Wang committed
175
def test_linkpred_neg_sampler(neg_sampler):
176
177
178
179
180
181
182
183
184
185
    data = "cora"
    node_model = "gcn"
    edge_model = "ele"
    custom_cfg = f"{data}_{node_model}_{edge_model}_{neg_sampler}.yaml"
    if neg_sampler == "":
        os.system(
            "dgl configure linkpred --data {} --node-model {} --edge-model {} --cfg {}".format(
                data, node_model, edge_model, custom_cfg
            )
        )
Minjie Wang's avatar
Minjie Wang committed
186
    else:
187
188
189
190
191
        os.system(
            "dgl configure linkpred --data {} --node-model {} --edge-model {} --neg-sampler {} --cfg {}".format(
                data, node_model, edge_model, neg_sampler, custom_cfg
            )
        )
Minjie Wang's avatar
Minjie Wang committed
192
193
    assert os.path.exists(custom_cfg)

194
195
196
197
    custom_script = f"{data}_{node_model}_{edge_model}_{neg_sampler}.py"
    os.system(
        "dgl export --cfg {} --output {}".format(custom_cfg, custom_script)
    )
Minjie Wang's avatar
Minjie Wang committed
198
    assert os.path.exists(custom_script)
Mufei Li's avatar
Mufei Li committed
199

200
201
202

@pytest.mark.parametrize("data", ["csv", "ogbg-molhiv", "ogbg-molpcba"])
@pytest.mark.parametrize("model", ["gin", "pna"])
203
def test_graphpred(data, model):
204
205
206
207
    os.system(
        "dgl configure graphpred --data {} --model {}".format(data, model)
    )
    assert os.path.exists("graphpred_{}_{}.yaml".format(data, model))
208

209
210
211
212
213
214
    custom_cfg = "custom_{}_{}.yaml".format(data, model)
    os.system(
        "dgl configure graphpred --data {} --model {} --cfg {}".format(
            data, model, custom_cfg
        )
    )
Minjie Wang's avatar
Minjie Wang committed
215
    assert os.path.exists(custom_cfg)
216

217
218
219
220
    custom_script = "_".join([data, model]) + ".py"
    os.system(
        "dgl export --cfg {} --output {}".format(custom_cfg, custom_script)
    )
221
222
    assert os.path.exists(custom_script)

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

@pytest.mark.parametrize(
    "recipe",
    [
        "graphpred_hiv_gin.yaml",
        "graphpred_hiv_pna.yaml",
        "graphpred_pcba_gin.yaml",
        "linkpred_cora_sage.yaml",
        "linkpred_citation2_sage.yaml",
        "linkpred_collab_sage.yaml",
        "nodepred_citeseer_gat.yaml",
        "nodepred_citeseer_gcn.yaml",
        "nodepred_citeseer_sage.yaml",
        "nodepred_cora_gat.yaml",
        "nodepred_cora_gcn.yaml",
        "nodepred_cora_sage.yaml",
        "nodepred_pubmed_gat.yaml",
        "nodepred_pubmed_gcn.yaml",
        "nodepred_pubmed_sage.yaml",
        "nodepred-ns_arxiv_gcn.yaml",
        "nodepred-ns_product_sage.yaml",
    ],
)
Mufei Li's avatar
Mufei Li committed
246
247
248
249
250
251
252
def test_recipe(recipe):
    # Remove all generated yaml files
    current_dir = os.listdir("./")
    for item in current_dir:
        if item.endswith(".yaml"):
            os.remove(item)

253
    os.system("dgl recipe get {}".format(recipe))
Mufei Li's avatar
Mufei Li committed
254
255
    assert os.path.exists(recipe)

256

Mufei Li's avatar
Mufei Li committed
257
def test_node_cora():
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    os.system("dgl configure nodepred --data cora --model gcn")
    os.system("dgl train --cfg nodepred_cora_gcn.yaml")
    assert os.path.exists("results")
    assert os.path.exists("results/run_0.pth")
    os.system("dgl configure-apply nodepred --cpt results/run_0.pth")
    assert os.path.exists("apply_nodepred_cora_gcn.yaml")
    os.system(
        "dgl configure-apply nodepred --data cora --cpt results/run_0.pth --cfg apply.yaml"
    )
    assert os.path.exists("apply.yaml")
    os.system("dgl apply --cfg apply.yaml")
    assert os.path.exists("apply_results/output.csv")
    os.system("dgl export --cfg apply.yaml --output apply.py")
    assert os.path.exists("apply.py")