2
$\begingroup$

I just want to use the "if" gate in IBM QX circuit composer, but I don't know how.

$\endgroup$

1 Answer 1

3
$\begingroup$

IF gate can be used for controlling gates based on value in classical register, i.e. measured values of qubits.

Lets see at this circuit:

Circuit

In this case qubit $q_0$ is in state $|1\rangle$ and qubit $q_1$ in state $|0\rangle$. After measurement you have value 1 in classical bit $c_1$ and value 0 in classical bit $c_0$. So $c_1c_0 = 10$ in binary or $2$ in decimal numbers. Then IF gate is used with condition $c=2$. Since there is the value 2 in classical register, the condition is fulfiled and gate $X$ linked to IF statement is activated. This leads to negating qubit $q_2$.

After measurement you have classical register in state $110$, where the first $1$ comes from measuring qubit $q_2$ and $10$ from measuring qubits $q_0q_1$.

Note 1: IF statement can be used only with simulator. It has not been implemented for real quantum processors yet.

Note 2: In IBM Q composer you can either use drag and drop method, take IF statement from gates list and put on gate you want to control by classical register or use direct coding in QASM, see below.

Note 3: Here is a code of above circuit:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[3];
creg c[3];

x q[0];
measure q[0] -> c[1];
measure q[1] -> c[0];

if (c==2) x q[2];
measure q[2] -> c[2];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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