I have a 2 qubit circuit where I wish to measure the first qubit and the measurement outcome determines what operation to implement on qubit 2. The whole process can be simulated using the following operation

\begin{equation} |0\rangle\langle0|\otimes H+|1\rangle\langle1|\otimes HS \end{equation} where H is a Hadamard gate and S is the phase gate, i.e. if the result is 0 I will measure in X basis and if it is 1 I will measure in Y basis. As a unitary this is \begin{equation} \begin{pmatrix} \frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&0&0\\ \frac{1}{\sqrt{2}}&-\frac{1}{\sqrt{2}}&0&0\\ 0&0&\frac{1}{\sqrt{2}}&\frac{i}{\sqrt{2}}\\ 0&0&\frac{1}{\sqrt{2}}&\frac{-i}{\sqrt{2}}\\ \end{pmatrix} \end{equation}

This can be implemented on IBM's simulator using c_if but does anyone know how to implement this on the real IBM devices? I tried using transpile to see what gates it can be decomposed into. However this gave a very complicated matrix. Is there a simpler way to implement conditional operations on real IBM devices?



If you want to implement something like this, which can be visualized as:

enter image description here

qc= QuantumCircuit(q, c)

then I don't think you will be able to run it as it on the hardware, since the c_if operation is not yet implementable directly.

So to side step this, you need to use deferred measurement principle, which is what you mentioned... as you have determined that the whole process can be simulated by the unitary matrix

\begin{equation} U = \begin{pmatrix} \frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&0&0\\ \frac{1}{\sqrt{2}}&-\frac{1}{\sqrt{2}}&0&0\\ 0&0&\frac{1}{\sqrt{2}}&\frac{i}{\sqrt{2}}\\ 0&0&\frac{1}{\sqrt{2}}&\frac{-i}{\sqrt{2}}\\ \end{pmatrix} \end{equation}

which you can decomposed into:

enter image description here

I don't think this is too long of a circuit. Although the transpiled circuit (based on the new native gates set of IBM's hardware $\{CX, ID, RZ, SX, X \}$),

enter image description here

looks quite long... however, I think it is still doable. I don't think there is any other way around in general if you want to perform conditional statement at the moment though so this is probably the only way.


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.