# How to not optimize the quantum gates in a qiskit circuit when running it in the real device?

I have been trying to run two circuits in the ibmq_london device, the one resulting of applying one X gate on qubit $$0$$ and the one that applies two X gates. I know that applying two X gates is the same as doing nothing because of its properties, but I am interested in the study of noise so I really want Qiskit to apply both gates. I have tried to place a barrier between both X gates but it does not seem to be working because I obtain the following results:

X circuit

XX circuit I have tried to write the following code:

job_device = execute(qc, device,shots=8192,basis_gates=None,optimization_level=0)

for the execution, but it does not seem to be working as due to the effect of noise I will expect a lower value for the XX circuit (two gates applied), even taking into account the thermal relaxation.

• I repeated your experiments using melbourne backend and I got the following results: applying $X$, p(00001)=95.313% and p(00000)=4.688; with $XX$, p(00001)=0.195% and p(00000)=99.805%. I think the reason is that the hardware is more "precise" in setting the qubits to $|0\rangle$ than to any other state. With $XX$ you are basically re-initializing the system. – Michele Amoretti Jun 6 at 14:41
• Yes, that probably has to do with another types of errors, such as the thermal relaxation error which makes the system tend to the 0 state. Thank you! – Paula G Jun 6 at 14:49
• I just tried $XXXX$ and I got p(00001)=0.684% and p(00000)=99.316%. In this and previous experiments, the number of runs was 1024, for the sake of completeness. – Michele Amoretti Jun 6 at 14:53
• Okay, thank you so much!! – Paula G Jun 6 at 15:15
• can anyone send code for real device like ibmq_vigo – Md Hasnain Jul 25 at 9:47

Optimization level 0 does not perform 1 qubit gate optimization and it will send 2 X gates (well 2 U3 gates after it unrolls to the basis set). You can see the passes optimization level 0 runs here: https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/transpiler/preset_passmanagers/level0.py It will only map the circuit to the device and unroll the gates to the basis set. You can see what the compiled circuit which will be sent to the device looks like with:

print(transpile(qc, device, optimization_level=0))

Which should show you 2 U3(pi,0,pi) gates next to each other. For example, when I ran it locally it shows:

>>> print(transpile(qc, backend, optimization_level=0))
┌─────────────┐┌─────────────┐ ░ ┌─┐
q_0 -> 0 ┤ U3(pi,0,pi) ├┤ U3(pi,0,pi) ├─░─┤M├──────
└─────────────┘└─────────────┘ ░ └╥┘┌─┐
q_1 -> 1 ───────────────────────────────░──╫─┤M├───
░  ║ └╥┘┌─┐
q_2 -> 2 ───────────────────────────────░──╫──╫─┤M├
░  ║  ║ └╥┘
ancilla_0 -> 3 ──────────────────────────────────╫──╫──╫─
║  ║  ║
ancilla_1 -> 4 ──────────────────────────────────╫──╫──╫─
║  ║  ║
meas_0: ══════════════════════════════════╩══╬══╬═
║  ║
meas_1: ═════════════════════════════════════╩══╬═
║
meas_2: ════════════════════════════════════════╩═

• I did not understand you quite well. So you are saying that as I am already indicating optimization_level=0 I am sending 2 X gates and that both are being performed? I do not thing that the results I have obtained (the ones you can see in the second picture) make any sense if that is true. Thank you for your help, if you could clarify this to me it would be extremely helpful as I am really interested in achieving this, it is important to the study of noise and I want to compare it with the result of the noise models (which in qiskit will act on both gates if a barrier is placed) – Paula G Jun 6 at 12:53
• Yes, that is what I was saying. If you use optimization level 0 it is sending 2 x gates to the backend. I can only really comment on the qiskit side though. – Matthew Treinish Jun 6 at 13:03
• Thank you for your help with the code. Then I still do not know why am I getting this result, I hope something can answer me to the real device part. – Paula G Jun 6 at 13:45