I'm using the following piece of python code:
import matplotlib.pyplot as plt
from qiskit import *
from qiskit.tools.visualization import plot_bloch_multivector, plot_histogram
from qiskit import execute, IBMQ, BasicAer
from qiskit.providers.ibmq import least_busy
from qiskit.tools.monitor import job_monitor
secret_number = "1010"
n = len(secret_number)
circuit = QuantumCircuit(n+1, n)
circuit.h(range(n))
circuit.x(n)
circuit.h(n)
circuit.barrier()
for i,v in enumerate(reversed(secret_number)):
if v=="1":
circuit.cx(i, n)
circuit.barrier()
circuit.h(range(n))
circuit.barrier()
circuit.measure(range(n), range(n))
simulator = Aer.get_backend("qasm_simulator")
sim_result = execute(circuit, backend=simulator, shots=4096).result()
IBMQ.load_account()
provider = IBMQ.get_provider("ibm-q")
# qcomp = provider.get_backend("ibmq_16_melbourne")
qcomp = provider.get_backend("ibmq_burlington")
job = execute(circuit, backend=qcomp, shots=4096)
job_monitor(job)
real_result = job.result()
counts = real_result.get_counts(circuit)
import collections
c = collections.Counter(counts)
# printing
print(circuit.draw())
print("result simulation:")
print(sim_result.get_counts())
print("results (top 5):")
print(c.most_common(5))
The results are shown here:
As you can see, the expected result is 1010
, which is correctly the value that the quantum simulator gives me. However, I find this result on the fifth position for this execution in the real quantum computer. Is this due to noise? How can I get around this?
As complementary information, I tried the same code with secret_number = "1011001"
and the ibmq_16_melbourne
server. These are the results:
As you see. The error is amplified.
secret_number
. $\endgroup$