2
$\begingroup$

I am implementing the teleportation algorithm on IBM Q Experience (GUI interface). Certain operations on the third qubit are only performed if the classical measurement result is 1, for example

if (c==1) x q[2];

However, it removes all the if statements after it is transpiled (lines 19 and 21). Do you know what I did wrong?

enter image description here

$\endgroup$
3
$\begingroup$

Currently IBM Q does not support IF statement on real quantum processor. The IF can be used on simulator only. However, there is a theorem stating that quantum gates controlled by classical register can be replaced by those controlled by qubits before measurement.

So, you can simply replace the statement

measure q[1] -> c[1];
if (c == 1) x q[2];

by

cx q[1], q[2];

i.e. qubit $q_1$ controls CNOT acting on $q_2$.

Similarly, you can do that for controlled $Z$ gate. In the end, you will get same results as with IF statement.

$\endgroup$
4
  • $\begingroup$ Thank you! It works. But I am submitting to software simulator. So you mean even the simulator tries to restrict this option? Thanks! $\endgroup$
    – HYW
    Mar 14 '20 at 23:53
  • $\begingroup$ I did not have such problem on simulator, only on real quantum processors. $\endgroup$ Mar 14 '20 at 23:54
  • $\begingroup$ Thank you! Just to confirm, do you know if "ibmq_qasm_simulator in ibm-q/open/main" is simulator or experimemt? $\endgroup$
    – HYW
    Mar 15 '20 at 5:58
  • 1
    $\begingroup$ It is a simulator - i.e. classical computer simulating quantum one. $\endgroup$ Mar 15 '20 at 7:57
1
$\begingroup$

I contacted @fran-cabrera from the IBMQ team and he could reproduce the bug!

The problem is with the visualization of the transpiled circuit, not the execution (the result should be correct). The team is working on solving it and they expect to deploy a fix at the end of the week.

I ran you example in Qiskit and it seems to work

IBMQ.load_account()
provider = IBMQ.get_provider(group='open')
device = provider.get_backend('ibmq_16_melbourne')

qasm_string = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
creg c[3];
h q[1];
cx q[1],q[2];
cx q[0],q[1];
h q[0];
measure q[1] -> c[1];
if(c==1) x q[2];
measure q[0] -> c[0];
if(c==1) z q[2];
measure q[2] -> c[2];
"""

circuit = QuantumCircuit.from_qasm_str(qasm_string)
circuit.draw('text')
                         ┌───┐┌─┐          
q_0: |0>─────────────■───┤ H ├┤M├──────────
        ┌───┐      ┌─┴─┐ └┬─┬┘└╥┘          
q_1: |0>┤ H ├──■───┤ X ├──┤M├──╫───────────
        └───┘┌─┴─┐ ├───┤  └╥┘  ║  ┌───┐ ┌─┐
q_2: |0>─────┤ X ├─┤ X ├───╫───╫──┤ Z ├─┤M├
             └───┘ └─┬─┘   ║   ║  └─┬─┘ └╥┘
                  ┌──┴──┐  ║   ║ ┌──┴──┐ ║ 
 c_0: 0 ══════════╡     ╞══╬═══╩═╡     ╞═╬═
                  │     │  ║     │     │ ║ 
 c_1: 0 ══════════╡ = 1 ╞══╩═════╡ = 1 ╞═╬═
                  │     │        │     │ ║ 
 c_2: 0 ══════════╡     ╞════════╡     ╞═╩═
                  └─────┘        └─────┘   
result = transpile(circuit,
                   backend=provider.get_backend('ibmq_16_melbourne'),
                   seed_transpiler=42)
result.draw('text', idle_wires=False)
                                            ┌──────────┐┌─┐             
q_0 -> 0 |0>────────────────────────■───────┤ U2(0,pi) ├┤M├─────────────
            ┌──────────┐          ┌─┴─┐     └───┬─┬────┘└╥┘             
q_1 -> 1 |0>┤ U2(0,pi) ├──■───────┤ X ├─────────┤M├──────╫──────────────
            └──────────┘┌─┴─┐┌────┴───┴────┐    └╥┘      ║ ┌────────┐┌─┐
q_2 -> 2 |0>────────────┤ X ├┤ U3(pi,0,pi) ├─────╫───────╫─┤ U1(pi) ├┤M├
                        └───┘└──────┬──────┘     ║       ║ └───┬────┘└╥┘
                                 ┌──┴──┐         ║       ║  ┌──┴──┐   ║ 
     c_0: 0 ═════════════════════╡     ╞═════════╬═══════╩══╡     ╞═══╬═
                                 │     │         ║          │     │   ║ 
     c_1: 0 ═════════════════════╡ = 1 ╞═════════╩══════════╡ = 1 ╞═══╬═
                                 │     │                    │     │   ║ 
     c_2: 0 ═════════════════════╡     ╞════════════════════╡     ╞═══╩═
                                 └─────┘                    └─────┘     

Based on this, I think your example should work in the IQX jupyter notebooks, included in the IBM Quantum Experience.

$\endgroup$
1
  • $\begingroup$ @fran-cabrera says the issue is solved already! $\endgroup$
    – luciano
    Mar 25 '20 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.