# Controlled-U operation in IBMQ

Suppose we have any matrix in $\mathrm U(2)$ and we need to construct a Controlled-$U$ operation with the $H,T,S$ gates. Then I am aware of the construction given in N&C of decomposing $U$ into $e^{ia}AXBXC$. My question is how to implement gates $A,B,C$ using the gates from library set $\left\lbrace H,T,S,X,Y,Z\right\rbrace$.

Also, any sequence of the gates induces some phase to the matrix (while $A,B,C \in \mathrm{SU}(2)$), so how is that phase removed from the circuit?

In general, it is not possible to implement every single-qubit operation exactly. However, it is possible to construct a quantum circuit whose action is approximately equal to this single-qubit operation. This can be done in many different ways, but I'm not sure if it is known which one is most efficient. I do not know of any efficient way to construct such a circuit, however, there is a pretty inefficient method that is well-known. I'll leave it to the OP to decide if it is efficient enough for his/her purposes.

Nielsen and Chuang explain one construction using just the $H$ and $T$ gates. This is done in chapter 4, especially in section 4.5.3. This section builds on earlier results of chapter 4, one of them being exercise 4.11. It is important to note that this exercise is wrong in some editions (have a look at the errata if this is true for your edition). Another source that provides this construction is this, section 4.3, where the $\pi/8$-gate is just a different notation for the $T$-gate.

The construction is difficult to present concisely in this answer. The main idea is to consider the following two gate sequences $HTHT$ and $THTH$. These two gate sequences can be visualized as rotations in the Bloch sphere, where the angle of rotation is an irrational multiple of $\pi$ for both of these gate sequences. Consecutive applications of these two rotations are enough to implement any rotation, and hence the gate sequences $HTHT$ and $THTH$ can be used to construct any single-qubit gate.

You asked for a decomposition using the $$\left\lbrace H,T,S,X,Y,Z\right\rbrace$$. I assume that's because you think that's all that IBMQ offers. However, it is also possible to do rotations around the $$x$$, $$y$$ and $$z$$ axes, which make things a lot easier.

Any single qubit unitary matrix may be decomposed as a sequence of rotations around two, non-parallel axes. For example

$$U = e^{i\alpha} \,\, R_z(\beta) \,\, R_y(\gamma) \,\, R_z(\delta)$$

Here the global phase $$\alpha$$ is undetectable and usually can be ignored, but not in cases like adding control to a unitary gate. The $$\beta$$ and $$\delta$$ are angles of rotation around the $$z$$ axis, and $$\gamma$$ is the angle for the $$y$$ axis.

The $$z$$ axes rotation is called RZ and is implemented by U1 (they are differ by a global phase only) on the IBM Q Experience and in QISKit. It takes a single parameter as an argument, which is the angle of rotation expressed in radians.

The $$y$$ axis rotation can be done using U3. This takes three arguments. The first of which is the angle in radians for the $$y$$ rotation, and the other two should be set to zero.

So if you want to do a rotation with $$\beta=0.1$$, $$\gamma=0.2$$ and $$\delta=0.3$$, for example, this could be done using the QASM editor of the IBM Q Experience with

u1(0.3) q;
u3(0.2,0,0) q;
u1(0.1) q;


It can also be done using the composer. You just need to tick the 'advanced' checkbox to see these gates.

If the global phase is important for your purposes, then you can use RZ gates instead U1 gates (on the assumption that when a Controlled-U will be constructed then the correct version of the cRZ gate will be used in IBM Q):

rz(0.3) q;
u3(0.2,0,0) q;
rz(0.1) q;


Let's pretend that the global phase is 0.4, then we can append the circuit e.g. like this:

x q;
u3(pi,0.4,pi+0.4) q;

• If you already use the u3 gate, your 3-gates circuit (u1;u3;u1 or rz;u3;rz) can be simplified to a single u3 gate. The angles for it (together with the phase) can be obtained from the original unitary matrix e.g. using the function: OneQubitEulerDecomposer('U3').angles_and_phase(unitary_matrix) from qiskit.quantum_info.synthesis or calculate it yourself, e.g. according to the algorithm given in the source code of the same function. Aug 6, 2020 at 4:12