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[0];
u3(0.2,0,0) q[0];
u1(0.1) q[0];
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[0];
u3(0.2,0,0) q[0];
rz(0.1) q[0];
Let's pretend that the global phase is 0.4, then we can append the circuit e.g. like this:
x q[0];
u3(pi,0.4,pi+0.4) q[0];