Quantum Inspire performance test
We compare performance of the simulator with the circuit from
“Overview and Comparison of Gate Level Quantum Software Platforms”, https://arxiv.org/abs/1807.02500
Define the circuit
[9]:
import time
import os
import numpy as np
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from qiskit.tools.visualization import plot_histogram
from quantuminspire.credentials import get_authentication
from quantuminspire.qiskit import QI
QI_URL = os.getenv('API_URL', 'https://api.quantum-inspire.com/')
We define the circuit based on the number of qubits and the depth (e.g. the number of iterations of the unit building block).
[11]:
def pcircuit(nqubits, depth = 10):
""" Circuit to test performance of quantum computer """
q = QuantumRegister(nqubits)
ans = ClassicalRegister(nqubits)
qc = QuantumCircuit(q, ans)
for level in range(depth):
for qidx in range(nqubits):
qc.h( q[qidx] )
qc.barrier()
for qidx in range(nqubits):
qc.rx(np.pi/2, q[qidx])
qc.barrier()
for qidx in range(nqubits):
if qidx!=0:
qc.cx(q[qidx], q[0])
for qidx in range(nqubits):
qc.measure(q[qidx], ans[qidx])
return q, qc
q,qc = pcircuit(4, 1)
qc.draw(output='mpl')
[11]:
Run the cirquit on the Quantum Inspire simulator
First we make a connection to the Quantum Inspire website.
[12]:
authentication = get_authentication()
QI.set_authentication(authentication, QI_URL)
We create a QisKit backend for the Quantum Inspire interface and execute the circuit generated above.
[13]:
qi_backend = QI.get_backend('QX single-node simulator')
job = execute(qc, qi_backend)
We can wait for the results and then print them
[14]:
result = job.result()
print('Generated histogram:')
print(result.get_counts())
Generated histogram:
{'0000': 71, '0001': 77, '0010': 62, '0011': 56, '0100': 72, '0101': 48, '0110': 56, '0111': 62, '1000': 63, '1001': 60, '1010': 69, '1011': 72, '1100': 65, '1101': 73, '1110': 58, '1111': 60}
Visualization can be done with the normal Python plotting routines, or with the QisKit SDK.
[15]:
plot_histogram(result.get_counts(qc))
[15]:
To compare we will run the circuit with 20 qubits and depth 20. This takes:
QisKit: 3.7 seconds
ProjectQ: 2.0 seconds
Our simulator runs for multiple shots (unless full state projection is used). More details will follow later.
[16]:
q, qc = pcircuit(10, 10)
start_time = time.time()
job = execute(qc, qi_backend, shots=8)
job.result()
interval = time.time() - start_time
print('time needed: %.1f [s]' % (interval,))
time needed: 3.9 [s]
[ ]: