iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🪐

Exploring Bloch Vectors

に公開

Objective

There is a concept called a Bloch vector, which maps a state vector onto the Bloch sphere. We often see the computational basis \ket{0}, \ket{1} or the X basis \ket{+}, \ket{-} being mapped, but I want to see how the Bloch vector is affected when a rotation gate is applied.
Since a rotation gate itself is not an operation on the Bloch vector but on the corresponding state vector \in \mathbb{C}^2\!/\!\!\sim\ \simeq \mathbb{C}P^1, the result is not entirely trivial.

Bloch Vector

\begin{align*} I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix},\ X = \begin{bmatrix} 0. & 1 \\ 1 & 0 \end{bmatrix},\ Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix},\ Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} \end{align*}

Let \vec{\sigma} = (X\ Y\ Z)^T \in \mathrm{Mat}(2, \mathbb{C})^3.

A state vector \ket{\psi} \in \mathbb{C} P^1 can be associated with a vector \vec{r} = (x\ y\ z)^T \in [-1, 1]^3 on the Bloch sphere, and this \vec{r} is called the "Bloch vector."

More specifically, let the density matrix of a pure state \ket{\psi} be

\begin{align*} \rho = \ket{\psi} \bra{\psi} \tag{1} \end{align*}

In this case, if we define

\begin{align*} x &= \braket{X} = \operatorname{tr}(X \rho), \\ y &= \braket{Y} = \operatorname{tr}(Y \rho), \\ z &= \braket{Z} = \operatorname{tr}(Z \rho) \tag{2} \end{align*}

then the relationship \rho = \frac{1}{2}(I + \vec{r}\cdot\vec{\sigma}) = \frac{1}{2}(I + xX + yY + zZ) is satisfied. For more details, refer to Exercise 2.72 in [NC1] or Section 8.4.2 "Quantum Process Tomography" in [NC3].

Bloch Vector Samples

Below, the state vector \ket{0} and the one rotated by \frac{\pi}{4} around the X-axis are rendered as Bloch vectors on the Bloch sphere.

\ket{0} R_X(\frac{\pi}{4}) \ket{0}

Intuitively, if we view the Bloch sphere within the ordinary Euclidean space \R^3, it is expected to be in a position as if it were rotated by \frac{\pi}{4} in the YZ plane. Indeed, that is what happens. However, something like "what happens when R_X(\frac{\pi}{4}) is applied after the Bloch vector has been lifted from the YZ plane by an R_Y gate?" is not trivial.

Verification by Actual Calculation

In this post, we will only verify the application of R_X(\lambda).[1]

A pure state, that is, a state vector corresponding to a point on the Bloch sphere, can be written as \ket{\psi} = \cos \frac{\theta}{2} \ket{0} + e^{i \phi} \sin \frac{\theta}{2} \ket{1}, excluding the global phase. The corresponding Bloch vector, derived from equations (1) and (2), is:

\begin{align*} x &= \sin \theta \cos \phi \\ y &= \sin \theta \sin \phi \\ z &= \cos \theta \tag{3} \end{align*}

In short, it is the familiar spherical coordinate representation of a point on a unit sphere in \R^3.

Also, the R_X(\lambda) gate can be written as:

\begin{align*} R_X(\lambda) = \cos \frac{\lambda}{2} I -i \sin \frac{\lambda}{2} X = \begin{bmatrix} \cos \frac{\lambda}{2} & -i \sin \frac{\lambda}{2} \\ -i \sin \frac{\lambda}{2} & \cos \frac{\lambda}{2} \end{bmatrix} \end{align*}

Therefore, the result of rotating an arbitrary pure state vector along the X-axis is:

\begin{align*} \ket{\psi^\prime} = R_X(\lambda) \ket{\psi} = \begin{bmatrix} \cos \frac{\lambda}{2} \cos \frac{\theta}{2} -i e^{i \phi} \sin \frac{\lambda}{2} \sin \frac{\theta}{2} \\ -i \sin \frac{\lambda}{2} \cos \frac{\theta}{2} + e^{i \phi} \cos \frac{\lambda}{2} \sin \frac{\theta}{2} \end{bmatrix} = \begin{bmatrix} a \\ b \end{bmatrix} \end{align*}

We want to represent this as a Bloch vector \vec{r^\prime} = (x^\prime\ y^\prime\ z^\prime)^T. The tools we can use for this are again equations (1) and (2).

Calculation of x^\prime

We calculate x^\prime = \operatorname{tr}(X \ket{\psi^\prime} \bra{\psi^\prime}) = \operatorname{tr}(X \begin{bmatrix} a a^* & a b^* \\ b a^* & b b^* \end{bmatrix}) = b a^* + a b^* = 2 \operatorname{Re}(a b^*).

\begin{align*} x^\prime &= 2 \operatorname{Re} \left( (\cos \frac{\lambda}{2} \cos \frac{\theta}{2} -i e^{i \phi} \sin \frac{\lambda}{2} \sin \frac{\theta}{2}) (i \sin \frac{\lambda}{2} \cos \frac{\theta}{2} + e^{-i \phi} \cos \frac{\lambda}{2} \sin \frac{\theta}{2}) \right) \\ &= 2 (\cos \frac{\lambda}{2} \cos \frac{\theta}{2} \cos \phi \cos \frac{\lambda}{2} \sin \frac{\theta}{2} + \cos \phi \sin \frac{\lambda}{2} \sin \frac{\theta}{2} \sin \frac{\lambda}{2} \cos \frac{\theta}{2}) \\ &= 2 \cos \phi \sin \frac{\theta}{2} \cos \frac{\lambda}{2} = \sin \theta \cos \phi \end{align*}

Thus, comparing with equation (3), we find that x^\prime = x. In other words, no movement in the X direction occurs.

Calculation of y^\prime and z^\prime

Calculating these two together makes it easier to consider the results, so we'll do them as a set.[2]

We calculate y^\prime = \operatorname{tr}(Y \ket{\psi^\prime} \bra{\psi^\prime}) = \operatorname{tr}(Y \begin{bmatrix} a a^* & a b^* \\ b a^* & b b^* \end{bmatrix}) = i (a b^* - (a b^*)^*) = - 2 \operatorname{Im}(a b^*).

\begin{align*} y^\prime &= -2 \operatorname{Im} \left( (\cos \frac{\lambda}{2} \cos \frac{\theta}{2} -i e^{i \phi} \sin \frac{\lambda}{2} \sin \frac{\theta}{2}) (i \sin \frac{\lambda}{2} \cos \frac{\theta}{2} + e^{- i \phi} \cos \frac{\lambda}{2} \sin \frac{\theta}{2}) \right) \\ &= -2(\sin \frac{\lambda}{2} \cos \frac{\lambda}{2} \cos \theta - \sin \phi \cos \lambda \sin \frac{\theta}{2} \cos \frac{\theta}{2}) \\ &= \cos \lambda \sin \theta \sin \phi - \sin \lambda \cos \theta \end{align*}

We calculate z^\prime = \operatorname{tr}(Z \ket{\psi^\prime} \bra{\psi^\prime}) = \operatorname{tr}(Z \begin{bmatrix} a a^* & a b^* \\ b a^* & b b^* \end{bmatrix}) = a a^* - b b^*.

\begin{align*} z^\prime &= \cos^2 \frac{\lambda}{2} \cos \theta + \sin \phi (2 \sin \frac{\lambda}{2} \cos \frac{\lambda}{2}) (2 \sin \frac{\theta}{2} \cos \frac{\theta}{2}) - \sin^2 \frac{\lambda}{2} \cos \theta \\ &= \sin \lambda \sin \theta \sin \phi + \cos \lambda \cos \theta \end{align*}

Therefore,

\begin{align*} \begin{bmatrix} y^\prime \\ z^\prime \end{bmatrix} = \begin{bmatrix} \cos \lambda & - \sin \lambda \\ \sin \lambda & \cos \lambda \end{bmatrix} \begin{bmatrix} \sin \theta \sin \phi \\ \cos \theta \end{bmatrix} \end{align*}

This indicates that a rotation of angle \lambda has been applied within the YZ plane.

Trying with Python

Since this is a quick-and-dirty implementation, there might be some edge cases, but I think it should work for the most part.

import numpy as np

I = np.array([
    [1., 0.],
    [0., 1.]
])
X = np.array([
    [0., 1.],
    [1., 0.]
])
Y = np.array([
    [0., -1.j],
    [1.j, 0.]
])
Z = np.array([
    [1., 0.],
    [0., -1.]
])
def Rx(theta):
    return np.cos(theta/2) * I - 1.j * np.sin(theta/2) * X
def Ry(theta):
    return np.cos(theta/2) * I - 1.j * np.sin(theta/2) * Y
def Rz(theta):
    return np.cos(theta/2) * I - 1.j * np.sin(theta/2) * Z

def density_matrix(state):
    if len(state.shape) == 1:
        state = state.reshape(-1, 1)
    return state * np.conjugate(state.T)

def state2bloch(state):
    rho = density_matrix(state)
    x, y, z = np.trace(X @ rho), np.trace(Y @ rho), np.trace(Z @ rho)
    return np.real(np.array([x, y, z]))

def bloch2state(vec, epsilon = 1e-10):
    x, y, z = np.real(vec)
    cos = np.sqrt((1 + z)/2)
    if z > 1 - epsilon: # theta = 0
        return np.array([1., 0.])
    elif z < -1 + epsilon: # theta = pi
        return np.array([0., 1.])
    else:
        sin = np.sqrt(x**2 + y**2) / (2*cos)
        if x < 0:
            sin = -sin
        if abs(x) < epsilon: # phi = pi/2, 3pi/2
            if y >= 0:
                phi = np.pi/2
            else:
                phi = 3 * np.pi/2
        else:
            phi = np.arctan(y/x)
        return np.array([cos, np.exp(1.j*phi)*sin])

Experiment

Using My Own APIs

Let's experiment with what I mentioned at the beginning: "What happens when R_X(\frac{\pi}{4}) is applied after the Bloch vector has been lifted from the YZ plane by an R_Y gate?" We will rotate by \frac{\pi}{4} around the Y-axis and then by \frac{\pi}{4} around the X-axis.

init_state = np.array([1., 0.])
final_state = Rx(np.pi/4) @ Ry(np.pi/4) @ init_state
final_vec = state2bloch(final_state)
print(final_vec)
display(plot_bloch_vector(final_vec))

Calculating with NumPy Only

As we have already calculated, rotation operations can be performed as intuitive rotations in Euclidean space, so they can be written as follows:

def rot(theta):
    return np.array([
        [np.cos(theta), -np.sin(theta)],
        [np.sin(theta), np.cos(theta)],
    ])

init_vec = np.array([0., 0., 1.])

vec = init_vec[:]
vec[[2,0]] = rot(np.pi/4)@vec[[2,0]] # rotate only 2:z, 0:x around Y-axis
vec[[1,2]] = rot(np.pi/4)@vec[[1,2]] # rotate only 1:y, 2:z around X-axis
print(vec)
display(plot_bloch_vector(vec))

The displayed image is the same as the one above, so it is omitted.

Comparison with Calculation in Qiskit

Just to be sure, let's render the result from the state vector obtained by executing a quantum circuit using plot_bloch_multivector.

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_bloch_multivector

qc = QuantumCircuit(1)
qc.ry(np.pi/4, 0)
qc.rx(np.pi/4, 0)
state = Statevector.from_instruction(qc)
display(plot_bloch_multivector(state))

Since the visualization APIs are different, there are slight differences in the details, but it looks quite similar, doesn't it?

Summary

I understood that applying a rotation gate to a state vector somehow moves it on the Bloch sphere, and since it moves to easy-to-understand positions for rotations of \frac{\pi}{2} or \pi, I didn't have much doubt[3]. However, I was not at all confident about what would happen for more arbitrary angles or when combining multiple axes of rotation. In this post, although only for the R_X gate, I found that rotation "in an intuitive sense" acts on the Bloch vector on the Bloch sphere.

Originally, I should also calculate for R_Y and R_Z, but since R_X alone was quite a task, I haven't calculated them yet. I am thinking about whether I can simplify the process using something like SymPy.

The code used for the experiments is available on GitHub as bloch_vector.ipynb.

References

[NC1] M. A. Nielsen, I. L. Chuang. Quantum Computation and Quantum Information I, Ohmsha, 2004
[NC3] M. A. Nielsen, I. L. Chuang. Quantum Computation and Quantum Information III, Ohmsha, 2004

脚注
  1. The calculation results were quite exhausting, so I don't have the energy to check other gates. ↩︎

  2. The calculation details are tedious and long, so I will omit most of them. ↩︎

  3. Or rather, I was able to just not worry about it. ↩︎

GitHubで編集を提案

Discussion