# Different results with the same circuit depending on whether executed on a simulator or on a real backend. Could you help me in understanding why?

The same 4 qubits circuit yields different results whether it runs on a simulator or on a real system and I would appreciate if you could help me in understanding the reason of this difference or point me in the right direction.

The purpose of the experiment is to eliminate (almost) all probabilities for measuring state |0000> (or more exactly state |000> as qbit 3 has an ancilliary role). I observe that this works on a simulator (even though I haven't yet suceeded in reshufling probabilities evenly) but state |0000> is still alive an well with the real backend.

Below are the two extract of the code differing only by the instructions relative to the backend. The attached picture show the output of both cases.

In the two documented cases the backend is Ibmq_Bogota, Qiskit version 1.6.20

Extract 1.1 : simulator

simulator = Aer.get_backend('aer_simulator')

#Circuit definition
qcMq = QuantumRegister(3,'qcMq')
qcMa = QuantumRegister(1,'qcMa')
qcMc = ClassicalRegister(4, 'qcMc')
qcM = QuantumCircuit(qcMq, qcMa, qcMc)

#Init
qcM.reset(qcMq)
qcM.reset(qcMa)
qcM.x(0)
qcM.h(0)
qcM.h(1)
qcM.h(2)
#qcM.h(1)

qcM.x(1)
qcM.x(2)
#qcM.h(2)

#swap test
qcM.h(qcMa[0])
qcM.cswap(qcMa[0], qcMq[1], qcMq[2],ctrl_state='1')
qcM.h(qcMa[0])
qcM.x(qcMa[0])
qcM.barrier()

#H on qubit 0 if all other qubits in state |1>
qcMz = MCMT('h', num_ctrl_qubits=3, num_target_qubits=1) #ok
qcMf = qcM.compose(qcMz,qubits=[3,2,1,0])
qcMf.barrier()

qcMf.x(1)
qcMf.x(2)
qcMf.barrier()

# Hadamard on qbit 1 et 2 if result swap test = 1 and qbubit 0 = 1
qcMy = MCMT('h', num_ctrl_qubits=2, num_target_qubits=2) #ok
qcMr = qcMf.compose(qcMy,qubits=[3,0,1,2]) #ok
qcMr.barrier()

#qcMr.cx(2,1)

#Statevector du circuit décrit =============
st1 = Statevector.from_instruction(qcMr)
D=st1.draw(output='bloch')
show_figure(D)
print('')
print(st1)

D=plot_state_qsphere(st1)
show_figure(D)
#==========================
qcMr.reset(3)
#measure
qcMr.measure([0,1,2],[0,1,2])

#Print circuit ; print(qcM) also works
qcMP = qcMr.draw(output='mpl')
show_figure(qcMP)

#If simulator
simulator = Aer.get_backend('aer_simulator')
qcMr = transpile(qcMr, simulator)
 end of extract 1.1
Extract 1.2 - simulator

# if simulator
result = simulator.run(qcMr, memory = True).result()
counts = result.get_counts(qcMf)
mem=result.get_memory()
plot_histogram(counts, title='test')


 Extract 2.2 - real backend
#Circuit definition
qcMq = QuantumRegister(3,'qcMq')
qcMa = QuantumRegister(1,'qcMa')
qcMc = ClassicalRegister(4, 'qcMc')
qcM = QuantumCircuit(qcMq, qcMa, qcMc)

#Init
qcM.reset(qcMq)
qcM.reset(qcMa)
qcM.x(0)
qcM.h(0)
qcM.h(1)
qcM.h(2)
#qcM.h(1)

qcM.x(1)
qcM.x(2)
#qcM.h(2)

#swap test
qcM.h(qcMa[0])
qcM.cswap(qcMa[0], qcMq[1], qcMq[2],ctrl_state='1')
qcM.h(qcMa[0])
qcM.x(qcMa[0])
qcM.barrier()

#H on qubit 0 if all other qubits in state |1>
qcMz = MCMT('h', num_ctrl_qubits=3, num_target_qubits=1) #ok
qcMf = qcM.compose(qcMz,qubits=[3,2,1,0])
qcMf.barrier()

qcMf.x(1)
qcMf.x(2)
qcMf.barrier()

##Hadamard on qhbit 1 et 2 if result swap test = 1 and qbubit 0 = 1
qcMy = MCMT('h', num_ctrl_qubits=2, num_target_qubits=2) #ok
qcMr = qcMf.compose(qcMy,qubits=[3,0,1,2]) #ok
qcMr.barrier()

#qcMr.cx(2,1)

#Statevector from the declared circuit
st1 = Statevector.from_instruction(qcMr)
D=st1.draw(output='bloch')
show_figure(D)
print('')
print(st1)

D=plot_state_qsphere(st1)
show_figure(D)
#===
qcMr.reset(3)
#mesure
qcMr.measure([0,1,2],[0,1,2])
 End of extract 2.1 - real backend

 Extract 2.2 - real backend

#If real system *******
job_exp = execute(qcMr, backend, shots=nbshots, max_credits=max_credits, memory=True)
job_monitor(job_exp)
result = job_exp.result()
counts = result.get_counts()
mem = result.get_memory()
 End of extract 2.2 - real backend
END OF QUESTION

[1]: https://i.sstatic.net/FaE2X.png
`
• Try running a circuit with says 5 qubit and apply an $X$ gate to each of the 5 qubits. Theoretically, you should always observe the state $|11111\rangle$. Run this on the hardware and see what you get. What I am trying to say is what you expect to get is not always what you get on the hardware due to noise. Commented Feb 21, 2022 at 0:17
• Thanks a lot Graig. I'll try this to realize the gap you mention. Commented Feb 21, 2022 at 10:58