-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeedtest.py
50 lines (40 loc) · 1.8 KB
/
speedtest.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
import sys
import numpy as np
from time import perf_counter
from circuit import pcircuit_run, batch_run
def speedtest(simulator, nbqubits, depth, batchsize):
if simulator == "qiskit": from qiskitsim import QuantumRegister
elif simulator == "oqsim": from oqsim import QuantumRegister
elif simulator == "oqmany": from oqmany import QuantumRegister
before = perf_counter()
if batchsize==1:
params= np.pi* np.random.rand(depth,nbqubits)
pcircuit_run(params, QR=QuantumRegister) #type:ignore
else:
params= np.pi* np.random.rand(depth,nbqubits, batchsize)
batch_run(params, QR=QuantumRegister) #type:ignore
totaltime=perf_counter()-before
return totaltime
if __name__=='__main__':
depth = nbcircuits= 1
try:
simulator=sys.argv[1]
nbqubits=int(sys.argv[2])
try:depth=int(sys.argv[3])
except:pass
try:nbcircuits=int(sys.argv[4])
except:pass
except:
print(f"usage: python {sys.argv[0]} (qiskit|oqsim|oqmany) nbqubits [depth [nbcircuits]]")
print(f"example: python {sys.argv[0]} oqsim 14 1 1000")
print(f"example: python {sys.argv[0]} qiskit 14")
sys.exit(0)
if simulator not in {"qiskit","oqsim","oqmany"}:
print(f"Simulator '{simulator}' not available. Available simulators: 'qiskit' 'oqsim' 'oqmany')")
sys.exit(0)
print(f"speedtest for {simulator} with nbqubits:{nbqubits} - depth:{depth} - nbcircuits:{nbcircuits}")
totaltime = speedtest(simulator, nbqubits, depth,nbcircuits)
print(f"total time:{totaltime:.2f}s")
print(f"time per circuit:{totaltime/nbcircuits:.2f}s")
print(f"in milliseconds {1000*totaltime/nbcircuits:.2f}ms ")
print(f"in microseconds {1000000*totaltime/nbcircuits:.2f}μs ")