-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathqml_benchmark.py
96 lines (89 loc) · 2 KB
/
qml_benchmark.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import uuid
import os
import utils
if __name__ == "__main__":
_uuid = str(uuid.uuid4())
nwires, nlayer, nitrs, timeLimit, isgpu, minus, path, nbatch = utils.arg(qml=True)
if isgpu == 0:
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
else:
import tensorflow as tf
gpu = tf.config.list_physical_devices("GPU")
tf.config.experimental.set_memory_growth(device=gpu[0], enable=True)
train_img, test_img, train_lbl, test_lbl = utils.mnist_data_preprocessing(
nwires - 1
)
from qml_pennylane import pennylane_benchmark
from qml_tc_tf import tensorcircuit_tf_benchmark
from qml_tc_jax import tensorcircuit_jax_benchmark
from qml_tfquantum import tfquantum_benchmark
pl_json = pennylane_benchmark(
_uuid,
nwires,
nlayer,
nitrs,
timeLimit,
isgpu,
train_img,
test_img,
train_lbl,
test_lbl,
nbatch,
False,
)
tfq_json = tfquantum_benchmark(
_uuid,
nwires,
nlayer,
nitrs,
timeLimit,
isgpu,
train_img,
test_img,
train_lbl,
test_lbl,
nbatch,
)
tc32_json = tensorcircuit_tf_benchmark(
_uuid,
nwires,
nlayer,
nitrs,
timeLimit,
isgpu,
train_img,
test_img,
train_lbl,
test_lbl,
nbatch,
"32",
)
tc64_json = tensorcircuit_tf_benchmark(
_uuid,
nwires,
nlayer,
nitrs,
timeLimit,
isgpu,
train_img,
test_img,
train_lbl,
test_lbl,
nbatch,
"64",
)
tcjax_json = tensorcircuit_jax_benchmark(
_uuid,
nwires,
nlayer,
nitrs,
timeLimit,
isgpu,
train_img,
test_img,
train_lbl,
test_lbl,
nbatch,
"64",
)
utils.save([pl_json, tfq_json, tc32_json, tc64_json, tcjax_json], _uuid, path)