Spaces:
Runtime error
Runtime error
Amit
commited on
Commit
·
d17e7e7
1
Parent(s):
5624d67
Compare packages added.
Browse files
plot_scripts/plot_display_com_cap.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import h5py
|
3 |
+
import os
|
4 |
+
|
5 |
+
import mercury as mr
|
6 |
+
|
7 |
+
import sys
|
8 |
+
sys.path.append('/plot_scripts/')
|
9 |
+
from map_packages_colors_1v1 import *
|
10 |
+
from plot_scripts_1v1 import *
|
11 |
+
|
12 |
+
# package_str = ['qiskit' , 'cirq', 'qsimcirq', 'pennylane', 'pennylane_l', 'qibo', 'qibojit', 'yao', 'quest', 'qulacs', 'intel_qs_cpp', 'projectq', 'svsim', 'hybridq', 'hiq', 'qcgpu', 'qrack_sch', 'cuquantum_qiskit', 'cuquantum_qsimcirq', 'qpanda']
|
13 |
+
|
14 |
+
|
15 |
+
def abs_time_pack(task, package, pr, N_end):
|
16 |
+
|
17 |
+
if task == "Heisenberg dynamics":
|
18 |
+
task = "hdyn"
|
19 |
+
elif task == "Random Quantum Circuit":
|
20 |
+
task = "rqc"
|
21 |
+
elif task == "Quantum Fourier Transform":
|
22 |
+
task = "qft"
|
23 |
+
|
24 |
+
if pr == "Single":
|
25 |
+
pr = "sp"
|
26 |
+
elif pr == "Double":
|
27 |
+
pr = "dp"
|
28 |
+
|
29 |
+
fig, ax = plt.subplots()
|
30 |
+
|
31 |
+
dir = os.getcwd()
|
32 |
+
|
33 |
+
if task == 'hdyn' or task == 'qft':
|
34 |
+
N_arr = np.arange(6, N_end, 2)
|
35 |
+
elif task == 'rqc':
|
36 |
+
N_arr = np.arange(12, N_end, 2)
|
37 |
+
|
38 |
+
|
39 |
+
dat_fst = dir + '/data/{}/{}_singlethread_{}.h5'.format(task, package, pr)
|
40 |
+
dat_fmt = dir + '/data/{}/{}_multithread_{}.h5'.format(task, package, pr)
|
41 |
+
dat_fgpu = dir + '/data/{}/{}_gpu_{}.h5'.format(task, package, pr)
|
42 |
+
|
43 |
+
if not os.path.isfile(dat_fst) and not os.path.isfile(dat_fmt) and not os.path.isfile(dat_fgpu):
|
44 |
+
return mr.Md(f"Precision {pr} possibly not supported")
|
45 |
+
|
46 |
+
mr.Md(f"TtS performance of simulation packages with different compute capabilities")
|
47 |
+
|
48 |
+
if os.path.isfile(dat_fst):
|
49 |
+
h5f_st = h5py.File(dat_fst, 'r')
|
50 |
+
dat_st = h5f_st[storage_dict[package]][:]
|
51 |
+
h5f_st.close()
|
52 |
+
plot_abs_data_n_arr(N_arr, dat_st, package+'_'+task+'_singlethread_'+pr)
|
53 |
+
|
54 |
+
if os.path.isfile(dat_fmt):
|
55 |
+
h5f_mt = h5py.File(dat_fmt, 'r')
|
56 |
+
dat_mt = h5f_mt[storage_dict[package]][:]
|
57 |
+
h5f_mt.close()
|
58 |
+
plot_abs_data_n_arr(N_arr, dat_mt, package+'_'+task+'_multithread_'+pr)
|
59 |
+
|
60 |
+
if os.path.isfile(dat_fgpu):
|
61 |
+
h5f_gpu = h5py.File(dat_fgpu, 'r')
|
62 |
+
dat_gpu = h5f_gpu[storage_dict[package]][:]
|
63 |
+
h5f_gpu.close()
|
64 |
+
plot_abs_data_n_arr(N_arr, dat_gpu, package+'_'+task+'_gpu_'+pr)
|
65 |
+
|
66 |
+
gen_settings(fig, ax, r"N (system size)", r"Time ($t_{package}$)", False, True, True, N_arr[0]-2, N_arr[-1], True, 10**-1, 10**5, "out", None)
|
67 |
+
|
68 |
+
mr.Md("___")
|
69 |
+
mr.Md(f"Relative performance to singlethread performance")
|
70 |
+
|
71 |
+
fig, ax = plt.subplots()
|
72 |
+
|
73 |
+
if os.path.isfile(dat_fst) and os.path.isfile(dat_fmt):
|
74 |
+
plot_comp_data_n_arr(N_arr, dat_st, dat_st, package+'_'+task+'_singlethread_'+pr)
|
75 |
+
plot_comp_data_n_arr(N_arr, dat_st, dat_mt, package+'_'+task+'_multithread_'+pr)
|
76 |
+
|
77 |
+
if os.path.isfile(dat_fst) and os.path.isfile(dat_fgpu):
|
78 |
+
plot_comp_data_n_arr(N_arr, dat_st, dat_gpu, package+'_'+task+'_gpu_'+pr)
|
79 |
+
|
80 |
+
gen_settings(fig, ax, r"N (system size)", r"Relative to singlethread", False, True, True, N_arr[0]-2, N_arr[-1], True, 10**-1, 10**3, "out", None)
|
81 |
+
|
82 |
+
mr.Md("___")
|
83 |
+
mr.Md(f"Relative performance to multithread performance")
|
84 |
+
|
85 |
+
fig, ax = plt.subplots()
|
86 |
+
|
87 |
+
if os.path.isfile(dat_fmt) and os.path.isfile(dat_fgpu):
|
88 |
+
plot_comp_data_n_arr(N_arr, dat_mt, dat_gpu, package+'_'+task+'_gpu_'+pr)
|
89 |
+
plot_comp_data_n_arr(N_arr, dat_mt, dat_mt, package+'_'+task+'_multithread_'+pr)
|
90 |
+
|
91 |
+
gen_settings(fig, ax, r"N (system size)", r"Relative to multithread", False, True, True, N_arr[0]-2, N_arr[-1], True, 10**-1, 10**2, "out", None)
|
92 |
+
|
93 |
+
# else:
|
94 |
+
# print(" Re-select the options as the requested option data is not available.")
|
95 |
+
|
96 |
+
# pkg_str = ['qiskit' , 'cirq', 'qsimcirq', 'pennylane', 'pennylane_l', 'qibo', 'qibojit', 'yao', 'quest', 'qulacs', 'intel_qs_cpp', 'projectq', 'svsim', 'hybridq', 'hiq', 'qcgpu', 'qrack_sch']
|
97 |
+
|
98 |
+
# abs_time_pack("Heisenberg dynamics", 'qsimcirq', 'Double', 36)
|
99 |
+
|
100 |
+
# abs_time(pkg_str, task_1, p_com_cap, p_prec)
|
101 |
+
# abs_time("Heisenberg dynamics", "Singlethread", "Single", 'qsimcirq')
|
102 |
+
# abs_time_pack("Heisenberg dynamics", "Random Quantum Circuit", "Singlethread", "Single", 34)
|
103 |
+
# abs_time_pack("Heisenberg dynamics", "Quantum Fourier Transform", "GPU", "Single", 38)
|
plot_scripts/plot_display_com_cap_all.py
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import h5py
|
3 |
+
import os
|
4 |
+
|
5 |
+
import mercury as mr
|
6 |
+
|
7 |
+
import sys
|
8 |
+
sys.path.append('/plot_scripts/')
|
9 |
+
from map_packages_colors_all import *
|
10 |
+
from plot_scripts_all import *
|
11 |
+
|
12 |
+
package_str = ['qiskit' , 'cirq', 'qsimcirq', 'pennylane', 'pennylane_l', 'qibo', 'qibojit', 'yao', 'quest', 'qulacs', 'intel_qs_cpp', 'projectq', 'svsim', 'hybridq', 'hiq', 'qcgpu', 'qrack_sch', 'cuquantum_qiskit', 'cuquantum_qsimcirq', 'qpanda']
|
13 |
+
|
14 |
+
|
15 |
+
def _build_data_mat(task, cc_1, cc_2, pr, _n_arr):
|
16 |
+
|
17 |
+
dir = os.getcwd()
|
18 |
+
|
19 |
+
data_mat = np.zeros((len(package_str), len(_n_arr)))
|
20 |
+
|
21 |
+
for p_i, pack in enumerate(package_str):
|
22 |
+
|
23 |
+
dat_cc1 = dir + '/data/{}/{}_{}_{}.h5'.format(task, pack, cc_1, pr)
|
24 |
+
dat_cc2 = dir + '/data/{}/{}_{}_{}.h5'.format(task, pack, cc_2, pr)
|
25 |
+
|
26 |
+
if os.path.isfile(dat_cc1) and os.path.isfile(dat_cc2):
|
27 |
+
|
28 |
+
h5f_cc1 = h5py.File(dat_cc1, 'r')
|
29 |
+
dat_cc1 = h5f_cc1[storage_dict[pack]][:]
|
30 |
+
h5f_cc1.close()
|
31 |
+
|
32 |
+
h5f_cc2 = h5py.File(dat_cc2, 'r')
|
33 |
+
dat_cc2 = h5f_cc2[storage_dict[pack]][:]
|
34 |
+
h5f_cc2.close()
|
35 |
+
|
36 |
+
ratio_arr = []
|
37 |
+
|
38 |
+
if len(dat_cc1) == len(dat_cc2):
|
39 |
+
for i, elem in enumerate(dat_cc1):
|
40 |
+
ratio_arr.append(elem/float(dat_cc2[i]))
|
41 |
+
elif len(dat_cc1) > len(dat_cc2):
|
42 |
+
for i, elem in enumerate(dat_cc2):
|
43 |
+
ratio_arr.append(dat_cc1[i]/float(elem))
|
44 |
+
elif len(dat_cc2) > len(dat_cc1):
|
45 |
+
for i, elem in enumerate(dat_cc1):
|
46 |
+
ratio_arr.append(elem/float(dat_cc2[i]))
|
47 |
+
|
48 |
+
if len(_n_arr) > len(ratio_arr):
|
49 |
+
for r_i, rat in enumerate(ratio_arr):
|
50 |
+
data_mat[p_i, r_i] = rat
|
51 |
+
elif len(_n_arr) < len(ratio_arr):
|
52 |
+
for n_i in range(len(_n_arr)):
|
53 |
+
data_mat[p_i, n_i] = ratio_arr[n_i]
|
54 |
+
else:
|
55 |
+
for ri, rat_v in enumerate(ratio_arr):
|
56 |
+
data_mat[p_i, ri] = rat_v
|
57 |
+
|
58 |
+
return data_mat
|
59 |
+
|
60 |
+
def abs_time_pack(task, pr, N_end, cc_1, cc_2):
|
61 |
+
|
62 |
+
if task == "Heisenberg dynamics":
|
63 |
+
task = "hdyn"
|
64 |
+
elif task == "Random Quantum Circuit":
|
65 |
+
task = "rqc"
|
66 |
+
elif task == "Quantum Fourier Transform":
|
67 |
+
task = "qft"
|
68 |
+
|
69 |
+
if cc_1 == "Singlethread":
|
70 |
+
cc_1 = 'singlethread'
|
71 |
+
elif cc_1 == "Multithread":
|
72 |
+
cc_1 = 'multithread'
|
73 |
+
elif cc_1 == "GPU":
|
74 |
+
cc_1 = 'gpu'
|
75 |
+
|
76 |
+
if cc_2 == "Singlethread":
|
77 |
+
cc_2 = 'singlethread'
|
78 |
+
elif cc_2 == "Multithread":
|
79 |
+
cc_2 = 'multithread'
|
80 |
+
elif cc_2 == "GPU":
|
81 |
+
cc_2 = 'gpu'
|
82 |
+
|
83 |
+
if pr == "Single":
|
84 |
+
pr = "sp"
|
85 |
+
elif pr == "Double":
|
86 |
+
pr = "dp"
|
87 |
+
|
88 |
+
fig, ax = plt.subplots()
|
89 |
+
|
90 |
+
dir = os.getcwd()
|
91 |
+
|
92 |
+
if task == 'hdyn' or task == 'qft':
|
93 |
+
N_arr = np.arange(6, N_end, 2)
|
94 |
+
elif task == 'rqc':
|
95 |
+
N_arr = np.arange(12, N_end, 2)
|
96 |
+
|
97 |
+
# if not os.path.isfile(dat_fst) and not os.path.isfile(dat_fmt) and not os.path.isfile(dat_fgpu):
|
98 |
+
# return mr.Md(f"Precision {pr} possibly not supported")
|
99 |
+
|
100 |
+
data_mat = _build_data_mat(task, cc_1, cc_2, pr, N_arr)
|
101 |
+
|
102 |
+
# params = {'figure.figsize': (10, 10)}
|
103 |
+
# plt.rcParams.update(params)
|
104 |
+
plt.imshow(data_mat, cmap='OrRd')#, vmin=-16, vmax=0)
|
105 |
+
|
106 |
+
plt.yticks(range(len(pkg_str)), package_str)
|
107 |
+
locs, labels = plt.yticks()
|
108 |
+
|
109 |
+
# plt.setp(labels, rotation=90)
|
110 |
+
plt.xticks(range(len(N_arr)), N_arr)
|
111 |
+
# locs, labels = plt.xticks()
|
112 |
+
|
113 |
+
ax.xaxis.set_major_locator(ticker.AutoLocator())
|
114 |
+
ax.xaxis.set_minor_locator(ticker.AutoMinorLocator())
|
115 |
+
|
116 |
+
plt.colorbar()
|
117 |
+
plt.tight_layout()
|
118 |
+
# plt.savefig(fn)
|
119 |
+
plt.show()
|
120 |
+
|
121 |
+
# abs_time_pack("Heisenberg dynamics", "Double", 36, "Singlethread", "Multithread")
|
122 |
+
# abs_time_pack("Random Quantum Circuit", "Double", 36, "Singlethread", "Multithread")
|
123 |
+
|
124 |
+
def comp_time_pack(task_1, task_2, pr, N_end, cc_1, cc_2):
|
125 |
+
|
126 |
+
if task_1 == "Heisenberg dynamics":
|
127 |
+
task_1 = "hdyn"
|
128 |
+
elif task_1 == "Random Quantum Circuit":
|
129 |
+
task_1 = "rqc"
|
130 |
+
elif task_1 == "Quantum Fourier Transform":
|
131 |
+
task_1 = "qft"
|
132 |
+
|
133 |
+
if task_2 == "Heisenberg dynamics":
|
134 |
+
task_2 = "hdyn"
|
135 |
+
elif task_2 == "Random Quantum Circuit":
|
136 |
+
task_2 = "rqc"
|
137 |
+
elif task_2 == "Quantum Fourier Transform":
|
138 |
+
task_2 = "qft"
|
139 |
+
|
140 |
+
if cc_1 == "Singlethread":
|
141 |
+
cc_1 = 'singlethread'
|
142 |
+
elif cc_1 == "Multithread":
|
143 |
+
cc_1 = 'multithread'
|
144 |
+
elif cc_1 == "GPU":
|
145 |
+
cc_1 = 'gpu'
|
146 |
+
|
147 |
+
if cc_2 == "Singlethread":
|
148 |
+
cc_2 = 'singlethread'
|
149 |
+
elif cc_2 == "Multithread":
|
150 |
+
cc_2 = 'multithread'
|
151 |
+
elif cc_2 == "GPU":
|
152 |
+
cc_2 = 'gpu'
|
153 |
+
|
154 |
+
if pr == "Single":
|
155 |
+
pr = "sp"
|
156 |
+
elif pr == "Double":
|
157 |
+
pr = "dp"
|
158 |
+
|
159 |
+
fig, ax = plt.subplots()
|
160 |
+
|
161 |
+
|
162 |
+
dir = os.getcwd()
|
163 |
+
|
164 |
+
if task_1 == 'hdyn' or task_1 == 'qft':
|
165 |
+
N_arr_1 = np.arange(6, N_end, 2)
|
166 |
+
elif task_1 == 'rqc':
|
167 |
+
N_arr_1 = np.arange(12, N_end, 2)
|
168 |
+
|
169 |
+
if task_2 == 'hdyn' or task_2 == 'qft':
|
170 |
+
N_arr_2 = np.arange(6, N_end, 2)
|
171 |
+
elif task_2 == 'rqc':
|
172 |
+
N_arr_2 = np.arange(12, N_end, 2)
|
173 |
+
|
174 |
+
data_mat_1 = np.matrix(_build_data_mat(task_1, cc_1, cc_2, pr, N_arr_1))
|
175 |
+
data_mat_2 = np.matrix(_build_data_mat(task_2, cc_1, cc_2, pr, N_arr_2))
|
176 |
+
|
177 |
+
if N_arr_1[0] > N_arr_2[0]:
|
178 |
+
data_mat_2 = data_mat_2[:,3:]
|
179 |
+
|
180 |
+
elif N_arr_1[0] < N_arr_2[0]:
|
181 |
+
data_mat_1 = data_mat_1[:,3:]
|
182 |
+
|
183 |
+
# print(data_mat_1.shape)
|
184 |
+
# print(data_mat_2.shape)
|
185 |
+
|
186 |
+
# plt.imshow(data_mat_1, cmap='OrRd')#, vmin=-16, vmax=0)
|
187 |
+
# plt.show()
|
188 |
+
# plt.imshow(data_mat_2, cmap='OrRd')#, vmin=-16, vmax=0)
|
189 |
+
# plt.show()
|
190 |
+
|
191 |
+
comp_data_mat = np.zeros(data_mat_1.shape)
|
192 |
+
|
193 |
+
for ri in range(comp_data_mat.shape[0]):
|
194 |
+
for ci in range(comp_data_mat.shape[1]):
|
195 |
+
comp_data_mat[ri, ci] = data_mat_1[ri, ci]/data_mat_2[ri, ci]
|
196 |
+
|
197 |
+
# comp_data_mat = np.matrix(data_mat_1) - np.matrix(data_mat_2)
|
198 |
+
|
199 |
+
# params = {'figure.figsize': (10, 10)}
|
200 |
+
# plt.rcParams.update(params)
|
201 |
+
|
202 |
+
plt.imshow(comp_data_mat, cmap='Spectral')#, vmin=-16, vmax=0)
|
203 |
+
|
204 |
+
plt.yticks(range(len(pkg_str)), package_str)
|
205 |
+
locs, labels = plt.yticks()
|
206 |
+
|
207 |
+
# plt.setp(labels, rotation=90)
|
208 |
+
if N_arr_1[0] > N_arr_2[0]:
|
209 |
+
plt.xticks(range(len(N_arr_1)), N_arr_1)
|
210 |
+
elif N_arr_1[0] < N_arr_2[0]:
|
211 |
+
plt.xticks(range(len(N_arr_2)), N_arr_2)
|
212 |
+
else:
|
213 |
+
plt.xticks(range(len(N_arr_1)), N_arr_1)
|
214 |
+
# locs, labels = plt.xticks()
|
215 |
+
|
216 |
+
ax.xaxis.set_major_locator(ticker.AutoLocator())
|
217 |
+
ax.xaxis.set_minor_locator(ticker.AutoMinorLocator())
|
218 |
+
|
219 |
+
plt.colorbar()
|
220 |
+
plt.tight_layout()
|
221 |
+
# plt.savefig(fn)
|
222 |
+
plt.show()
|
223 |
+
|
224 |
+
# comp_time_pack("Heisenberg dynamics", "Random Quantum Circuit", "Double", 36, "Singlethread", "Multithread")
|