1
$\begingroup$

What is eqivalent matrix to qc.rx(np.pi, 0):

import numpy as np
from qiskit import QuantumCircuit, Aer, execute
from qiskit.quantum_info import Operator

qc = QuantumCircuit(1)

qc.rx(np.pi, 0)
print('Final matrix:', np.round(Operator(qc).data, 3))

I thought it is the following:

$$X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 0 \\ \end{pmatrix} =\begin{pmatrix} 0 & 1 \\ 0 & 0 \\ \end{pmatrix} $$

but it is not, because of different result. And what would be equivalent matrices in case:

qc.rx(np.pi, 0)
qc.ry(np.pi, 0)
$\endgroup$
3
  • $\begingroup$ Sorry for formatting matrices, for some reason LaTex formatting doesn't work here(( $\endgroup$
    – Curious
    Oct 5, 2021 at 14:12
  • $\begingroup$ I edited so the Latex showed up correctly, please have a look to make sure I didn't mess with the original equations you were going for $\endgroup$
    – epelaez
    Oct 5, 2021 at 14:50
  • $\begingroup$ @epelaaez thank you so much! all is absolutely correct!) $\endgroup$
    – Curious
    Oct 5, 2021 at 18:05

1 Answer 1

2
$\begingroup$

Qiskit defines the $RX$ gate as follows:

$$ RX(\theta) = \exp\left(-i \frac{\theta}{2} X\right) = \begin{pmatrix} \cos{\frac{\theta}{2}} & -i\sin{\frac{\theta}{2}} \\ -i\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{pmatrix} $$

Thus, setting $\theta = \pi$, would give us:

$$ RX(\pi) = \begin{pmatrix} 0 & -i \\ -i & 0 \end{pmatrix} = -iX $$

Which is what I suspect you got as output to Operator(qc).data in the first code cell. Thus, a rotation of $\pi$ radians about the $x$-axis is equivalent to the normal bit flip gate $X$ up to a global phase of $-i$.

I thought it is the following: $$X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 0 \\ \end{pmatrix} =\begin{pmatrix} 0 & 1 \\ 0 & 0 \\ \end{pmatrix} $$

I think you got confused about matrix multiplication here. First of all, $X$ is only $\begin{pmatrix} 0 & 1 \\ 1& 0 \end{pmatrix}$. I suspect you are trying to get the final state of the circuit, which would correspond to the operation you do in the middle of the above equation (up to the global phase we discussed earlier). But, remember that the product of a matrix of size $2 \times 2$ with a vector of size $2 \times 1$ is another vector of size $2 \times 1$. Thus, you can't get a matrix from this operation.

The correct operation to get the final state of your circuit would be the following:

$$ RX(\pi)|0\rangle = \begin{pmatrix} 0 & -i \\ -i & 0 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ -i \end{pmatrix} = -i|1\rangle $$

Which is equivalent to $|1\rangle$ up to a global phase that we can ignore here since we only have one qubit. If there were more qubits, this global phase would turn into a relative phase.

And what would be equivalent matrices in case:

qc.rx(np.pi, 0)
qc.ry(np.pi, 0)

The $RY$ gate is defined as follows:

$$ RY(\theta) = \exp\left(-i \frac{\theta}{2} Y\right) = \begin{pmatrix} \cos{\frac{\theta}{2}} & -\sin{\frac{\theta}{2}} \\ \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{pmatrix} $$

Thus, to get the unitary corresponding to that circuit, plug in the angle to each of the gates definition and perform matrix multiplication. The operation you need to do is $RY(\pi)RX(\pi)$. And then you could get the final state of the circuit following the same steps as with the first example.

$\endgroup$
1
  • $\begingroup$ thank you so much fo such a comprhensive and detailed explanation!!) $\endgroup$
    – Curious
    Oct 6, 2021 at 14:11

Your Answer

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

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