test_pipeline.py 8.02 KB
Newer Older
Mufei Li's avatar
Mufei Li committed
1
2
3
4
5
import os
import pytest

@pytest.mark.parametrize('data', ['cora', 'citeseer', 'pubmed', 'csv', 'reddit',
                                  'co-buy-computer', 'ogbn-arxiv', 'ogbn-products'])
Minjie Wang's avatar
Minjie Wang committed
6
7
8
9
10
11
12
13
14
15
16
17
def test_nodepred_data(data):
    os.system(f'dgl configure nodepred --data {data} --model gcn')
    assert os.path.exists(f'nodepred_{data}_gcn.yaml')

    custom_cfg = f'custom_{data}_gcn.yaml'
    os.system(f'dgl configure nodepred --data {data} --model gcn --cfg {custom_cfg}')
    assert os.path.exists(custom_cfg)

    custom_script = f'{data}_gcn.py'
    os.system(f'dgl export --cfg {custom_cfg} --output {custom_script}')
    assert os.path.exists(custom_script)

Mufei Li's avatar
Mufei Li committed
18
@pytest.mark.parametrize('model', ['gcn', 'gat', 'sage', 'sgc', 'gin'])
Minjie Wang's avatar
Minjie Wang committed
19
20
21
def test_nodepred_model(model):
    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
22

Minjie Wang's avatar
Minjie Wang committed
23
24
25
    custom_cfg = f'custom_cora_{model}.yaml'
    os.system(f'dgl configure nodepred --data cora --model {model} --cfg {custom_cfg}')
    assert os.path.exists(custom_cfg)
Mufei Li's avatar
Mufei Li committed
26

Minjie Wang's avatar
Minjie Wang committed
27
28
    custom_script = f'cora_{model}.py'
    os.system(f'dgl export --cfg {custom_cfg} --output {custom_script}')
Mufei Li's avatar
Mufei Li committed
29
30
31
32
    assert os.path.exists(custom_script)

@pytest.mark.parametrize('data', ['cora', 'citeseer', 'pubmed', 'csv', 'reddit',
                                  'co-buy-computer', 'ogbn-arxiv', 'ogbn-products'])
Minjie Wang's avatar
Minjie Wang committed
33
34
35
36
37
38
39
40
41
42
43
44
45
def test_nodepred_ns_data(data):
    os.system(f'dgl configure nodepred-ns --data {data} --model gcn')
    assert os.path.exists(f'nodepred-ns_{data}_gcn.yaml')

    custom_cfg = f'ns-custom_{data}_gcn.yaml'
    os.system(f'dgl configure nodepred-ns --data {data} --model gcn --cfg {custom_cfg}')
    assert os.path.exists(custom_cfg)

    custom_script = f'ns-{data}_gcn.py'
    os.system(f'dgl export --cfg {custom_cfg} --output {custom_script}')
    assert os.path.exists(custom_script)


Mufei Li's avatar
Mufei Li committed
46
@pytest.mark.parametrize('model', ['gcn', 'gat', 'sage'])
Minjie Wang's avatar
Minjie Wang committed
47
48
49
def test_nodepred_ns_model(model):
    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
50

Minjie Wang's avatar
Minjie Wang committed
51
52
53
    custom_cfg = f'ns-custom_cora_{model}.yaml'
    os.system(f'dgl configure nodepred-ns --data cora --model {model} --cfg {custom_cfg}')
    assert os.path.exists(custom_cfg)
Mufei Li's avatar
Mufei Li committed
54

Minjie Wang's avatar
Minjie Wang committed
55
56
    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
57
58
59
60
61
    assert os.path.exists(custom_script)

@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
62
63
64
65
66
def test_linkpred_data(data):
    node_model = 'gcn'
    edge_model = 'ele'
    neg_sampler = 'global'
    custom_cfg = '_'.join([data, node_model, edge_model, neg_sampler]) + '.yaml'
Mufei Li's avatar
Mufei Li committed
67
    os.system('dgl configure linkpred --data {} --node-model {} --edge-model {} --neg-sampler {} --cfg {}'.format(
Minjie Wang's avatar
Minjie Wang committed
68
69
        data, node_model, edge_model, neg_sampler, custom_cfg))
    assert os.path.exists(custom_cfg)
Mufei Li's avatar
Mufei Li committed
70
71

    custom_script = '_'.join([data, node_model, edge_model, neg_sampler]) + '.py'
Minjie Wang's avatar
Minjie Wang committed
72
    os.system('dgl export --cfg {} --output {}'.format(custom_cfg, custom_script))
Mufei Li's avatar
Mufei Li committed
73
74
75
    assert os.path.exists(custom_script)

@pytest.mark.parametrize('node_model', ['gcn' ,'gat', 'sage', 'sgc', 'gin'])
Minjie Wang's avatar
Minjie Wang committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def test_linkpred_node_model(node_model):
    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))
    assert os.path.exists(custom_cfg)

    custom_script = '_'.join([data, node_model, edge_model, neg_sampler]) + '.py'
    os.system('dgl export --cfg {} --output {}'.format(custom_cfg, custom_script))
    assert os.path.exists(custom_script)


Mufei Li's avatar
Mufei Li committed
90
@pytest.mark.parametrize('edge_model', ['ele', 'bilinear'])
Minjie Wang's avatar
Minjie Wang committed
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
def test_linkpred_edge_model(edge_model):
    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))
    assert os.path.exists(custom_cfg)

    custom_script = '_'.join([data, node_model, edge_model, neg_sampler]) + '.py'
    os.system('dgl export --cfg {} --output {}'.format(custom_cfg, custom_script))
    assert os.path.exists(custom_script)


@pytest.mark.parametrize('neg_sampler', ['global', 'persource', ''])
def test_linkpred_neg_sampler(neg_sampler):
    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))
    else:
        os.system('dgl configure linkpred --data {} --node-model {} --edge-model {} --neg-sampler {} --cfg {}'.format(
            data, node_model, edge_model, neg_sampler, custom_cfg))
    assert os.path.exists(custom_cfg)

    custom_script = f'{data}_{node_model}_{edge_model}_{neg_sampler}.py'
    os.system('dgl export --cfg {} --output {}'.format(custom_cfg, custom_script))
    assert os.path.exists(custom_script)
Mufei Li's avatar
Mufei Li committed
122

123
124
125
126
127
128
@pytest.mark.parametrize('data', ['csv', 'ogbg-molhiv', 'ogbg-molpcba'])
@pytest.mark.parametrize('model', ['gin', 'pna'])
def test_graphpred(data, model):
    os.system('dgl configure graphpred --data {} --model {}'.format(data, model))
    assert os.path.exists('graphpred_{}_{}.yaml'.format(data, model))

Minjie Wang's avatar
Minjie Wang committed
129
    custom_cfg = 'custom_{}_{}.yaml'.format(data, model)
130
    os.system('dgl configure graphpred --data {} --model {} --cfg {}'.format(data, model,
Minjie Wang's avatar
Minjie Wang committed
131
132
                                                                             custom_cfg))
    assert os.path.exists(custom_cfg)
133
134

    custom_script = '_'.join([data, model]) + '.py'
Minjie Wang's avatar
Minjie Wang committed
135
    os.system('dgl export --cfg {} --output {}'.format(custom_cfg, custom_script))
136
137
    assert os.path.exists(custom_script)

Mufei Li's avatar
Mufei Li committed
138
@pytest.mark.parametrize('recipe',
139
140
141
142
                         ['graphpred_hiv_gin.yaml',
                          'graphpred_hiv_pna.yaml',
                          'graphpred_pcba_gin.yaml',
                          'linkpred_cora_sage.yaml',
Mufei Li's avatar
Mufei Li committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
                          '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'])
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)

    os.system('dgl recipe get {}'.format(recipe))
    assert os.path.exists(recipe)

def test_node_cora():
    os.system('dgl configure nodepred --data cora --model gcn')
    os.system('dgl train --cfg nodepred_cora_gcn.yaml')
169
170
171
172
173
174
175
176
177
178
    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')