-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
58 lines (49 loc) · 1.82 KB
/
test.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
# -*- coding: utf-8 -*-
import scipy.stats as stats
from graph_of_network import GraphOfNetwork
# import matplotlib.pyplot as plt
# import line_profiler
def correlation_calc_ibmpg(solution, calc_solution):
print("\n-----Correlation coefficient calc for ibmpg------")
file1 = open(solution, 'r')
file2 = open(calc_solution, 'r')
list1 = []
list2 = []
for line in file1.readlines():
if line.strip("\n"):
value = line.strip("\n").split(" ")[1]
list1.append(eval(value))
for line in file2.readlines():
if line.strip("\n"):
value = line.strip("\n").split(" ")[1]
list2.append(eval(value))
file1.close()
file2.close()
list1.sort()
list2.sort()
co = stats.pearsonr(list1, list2)[0]
print("The correlation coefficient between {} and {} is:{}".format(solution, calc_solution, co))
return co
# @profile
def test():
print("------------------------START-------------------------")
filepath = "./example/data/"
output_path = "./example/output/"
filename = "ibmpg1.spice"
methods = ["LU", "CG", "cholesky"]
method = methods[0]
graph = GraphOfNetwork(method)
graph.convert_network_into_graph(filename, filepath)
graph.fill_sparse_matrix()
# plt.spy(graph.sparseMatrix)
# plt.show()
# savemat('{}.mat'.format(graph.name), {'A': graph.sparseMatrix})
graph.node_voltage_solver()
graph.print_solution(output_path)
if "ibmpg" in filename:
solution = filepath + filename[:6]+".solution"
calc_solution = output_path + filename[:6]+"_"+method+".solution"
correlation_calc_ibmpg(solution, calc_solution)
print("-------------------------END--------------------------")
if __name__ == '__main__':
test()