Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit d6d5544

Browse files
committed
[Test] Add grid test
1 parent f1b909c commit d6d5544

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

test/grid_test.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import io
2+
import sys
3+
from pathlib import Path
4+
from time import time
5+
6+
from SubgraphDetection import detect_subgraph
7+
8+
9+
def _build_config_grid():
10+
return [
11+
{
12+
"DETAILED_ISOMORPHIC_CHECK": DETAILED_ISOMORPHIC_CHECK,
13+
"SCOPE_BOUNDARY": SCOPE_BOUNDARY,
14+
"MAX_SUBGRAPH_NODE_NUMBER": MAX_SUBGRAPH_NODE_NUMBER,
15+
"MIN_SUBGRAPH_NODE_NUMBER": MIN_SUBGRAPH_NODE_NUMBER,
16+
"MIN_SUBGRAPH_INSTANCE_NUMBER": MIN_SUBGRAPH_INSTANCE_NUMBER,
17+
}
18+
for DETAILED_ISOMORPHIC_CHECK in (True, False)
19+
for SCOPE_BOUNDARY in (True, False)
20+
for MAX_SUBGRAPH_NODE_NUMBER in range(24, 49, 12)
21+
for MIN_SUBGRAPH_NODE_NUMBER in range(3, 6)
22+
for MIN_SUBGRAPH_INSTANCE_NUMBER in range(2, 5)
23+
]
24+
25+
26+
def mean(array):
27+
return sum(array) / len(array) if array else 0
28+
29+
30+
def write_result_header():
31+
with open("./test_result.csv", "w") as f:
32+
f.write(
33+
",".join(
34+
[
35+
"DETAILED_ISOMORPHIC_CHECK",
36+
"SCOPE_BOUNDARY",
37+
"MAX_SUBGRAPH_NODE_NUMBER",
38+
"MIN_SUBGRAPH_NODE_NUMBER",
39+
"MIN_SUBGRAPH_INSTANCE_NUMBER",
40+
"pb_name",
41+
"time",
42+
"graph_size",
43+
"num_subgraph",
44+
"ave_num_subgraph_instance",
45+
"ave_subgraph_size",
46+
"MDL",
47+
"reduce_ratio",
48+
]
49+
) + "\n"
50+
)
51+
52+
53+
def write_result(test_result):
54+
with open("./test_result.csv", "a") as f:
55+
f.write(",".join(map(str, test_result[-1].values())) + "\n")
56+
57+
58+
def test_detect():
59+
# Do not print!
60+
stdout, sys.stdout = sys.stdout, io.StringIO()
61+
62+
config = _build_config_grid()
63+
result = []
64+
write_result_header()
65+
66+
for c in config:
67+
# test the config item on every pb fies we got
68+
for pb_file in Path("./pb").iterdir():
69+
if pb_file.suffix == ".pb":
70+
time_st = time()
71+
res_check = detect_subgraph(
72+
graph_path=str(pb_file.absolute()),
73+
result_path=f"./result/{pb_file.name}.json",
74+
check_result=True,
75+
**c,
76+
)
77+
time_use = time() - time_st
78+
result.append(
79+
{
80+
**c,
81+
"pb_name": pb_file.name,
82+
"time": time_use,
83+
"graph_size": res_check.graph_size,
84+
"num_subgraph": res_check.num_subgraph,
85+
"ave_num_subgraph_instance": mean(res_check.subgraph_count),
86+
"ave_subgraph_size": mean(res_check.subgraph_size),
87+
"MDL": res_check.MDL,
88+
"reduce_ratio": res_check.reduce_ratio
89+
}
90+
)
91+
write_result(result)
92+
print(pb_file, round(time_use, 2), file=stdout)
93+
94+
sys.stdout = stdout
95+
96+
97+
test_detect()

test/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apt install python3.7 python3.7-pip python3.7-dev
2+
python3.7 -m pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/0.7.0-beta/MindSpore/ascend/ubuntu_x86/mindspore_ascend-0.7.0-cp37-cp37m-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
3+
python3.7 -m pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/0.7.0-beta/MindInsight/ascend/ubuntu_x86/mindinsight-0.7.0-cp37-cp37m-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
4+
5+
python3.7 setup.py install
6+
rm test_result.csv
7+
python3.7 grid_test.py

0 commit comments

Comments
 (0)