##### Introduction

The Bloch sphere is a powerful geometric representation frequently employed in quantum mechanics to visualize and analyze quantum states of a two-level quantum system, often referred to as a qubit. The Bloch sphere is named after the Swiss phycisist Felix Bloch, the father of Nuclear Magnetic Resonance (NMR), who introduced it as an intuitive way to depict the quantum state of the $SU(2)$ Hilbert space. Typically, the qubit state is described for a pure system by a 2-dimensional, complex valued vector of length 1.

The Bloch sphere provides a 3D representation of this quantum state space, where the north and south poles represent the basis states $|0\rangle$ and $|1\rangle$, while the equator embodies the superposition of these states. Unitary transformations, which encompass quantum gates and operations, are elegantly visualized on the Bloch sphere as rotations. A rotation about any axis corresponds to a specific unitary transformation applied to the quantum state. This is because of the isomorphic relationship between the $SU(2)$ group and the group of rotations in 3D space, $SO(3)$. This makes the Bloch sphere a valuable tool for designing and comprehending quantum algorithms and quantum gates.

This online tool aims at providing an easily and readily available tool to visualize quantum states and operations on the Bloch sphere. It is ideal for presentations, publications, and teaching. The tool is based on the open-source JavaScript library plotly.js.

##### Mathematical background

Using the two basis states $$|0\rangle =\begin{pmatrix}1\\0\end{pmatrix} \qquad \mathrm{and} \qquad |1\rangle=\begin{pmatrix}0\\1\end{pmatrix}, $$ any pure state $|\psi\rangle$ of a qubit can be written (up to an irrelevant global phase) as a linear combination $$ |\psi\rangle = \cos\left(\frac{\theta}{2}\right) |0\rangle + \sin\left(\frac{\theta}{2}\right) e^{\mathrm{i} \varphi} |1\rangle = \begin{pmatrix}\alpha \\ \beta\end{pmatrix}. $$ The state can be represented as a vector on the Bloch sphere, where the angles $\theta$ and $\varphi$ are the polar and azimuthal angles, respectively. The Bloch vector representation is given by $$ \vec{r} = \begin{pmatrix} \sin\theta \cos\varphi \\ \sin\theta \sin\varphi \\ \cos\theta \end{pmatrix} = \begin{pmatrix}u \\ v \\ w\end{pmatrix}.$$ The Bloch vector is normalized to length 1,*i.e.*$|\vec{r}| = 1$. To compute this representation numerically from a given state $|\psi\rangle$, we use the mapping $$ \begin{align*} u &= -2\,\mathrm{Re}(\alpha \beta^*) \\ v &= 2\,\mathrm{Im}(\alpha \beta^*) \\ w &= \mathrm{Re}(\alpha\alpha^*-\beta\beta^*). \end{align*} $$ Rotations around the axis $i$ are performed by applying the corresponding unitary operator to the current state $|\psi\rangle$, $$ |\psi'\rangle = R_i(\phi) |\psi\rangle. $$ The visualizer tool stores the state state $|\psi\rangle$, performes the quantum actions on it and uses the above mapping to compute the Bloch vector representation after every manipulation. The Bloch vector is then used to plot the state on the Bloch sphere. For the three Cartesian axes $i \in {x,y,z}$, the rotation operators are given by $$ \begin{align*} R_x(\phi) &= \begin{pmatrix} \cos\left(\frac{\phi}{2}\right) & -\mathrm{i} \sin\left(\frac{\phi}{2}\right) \\ -\mathrm{i} \sin\left(\frac{\phi}{2}\right) & \cos\left(\frac{\phi}{2}\right) \end{pmatrix} \\ R_y(\phi) &= \begin{pmatrix} \cos\left(\frac{\phi}{2}\right) & - \sin\left(\frac{\phi}{2}\right) \\ \sin\left(\frac{\phi}{2}\right) & \cos\left(\frac{\phi}{2}\right) \end{pmatrix} \\ R_z(\phi) &= \begin{pmatrix} e^{-\mathrm{i}\frac{\phi}{2}} & 0 \\ 0 & e^{\mathrm{i}\frac{\phi}{2}} \end{pmatrix}, \end{align*} $$ where we use the matrix exponential. For an arbitrary rotation axis $\vec{n} = (n_x,n_y,n_z)$, the rotation operator is given by $$ R_{\vec{n}}(\phi) = \exp\left(-\mathrm{i} \frac{\phi}{2} \vec{n} \cdot \vec{\sigma}\right), $$ where $\vec{\sigma} = (\sigma_x,\sigma_y,\sigma_z)$ are the Pauli matrices. The rotation operator can be written as $$ R_{\vec{n}}(\phi) = \cos\left(\frac{\phi}{2}\right) \mathbb{1} - \mathrm{i} \sin\left(\frac{\phi}{2}\right) \vec{n} \cdot \vec{\sigma}. $$ This convention results in a right-handed coordinate system, where the rotation around the $z$-axis is a clockwise rotation when looking along the positive $z$-axis. The rotation around the $x$-axis is a clockwise rotation when looking along the positive $x$-axis. The rotation around the $y$-axis is a clockwise rotation when looking along the positive $y$-axis.

##### How to use this tool

The tab *Rotation around default axis*, allows to perform rotation operations around the three Cartesian axes. The rotation angle can be chosen by the user. The rotation is performed by applying the corresponding unitary operator to the current state $|\psi\rangle$, Most common rotation angles have separate buttons.

The tab *Rotation around custom axis*, allows to perform a rotation operation around an axis that can be specified by the user entering a polar angle $\theta$ and an azimuthal angle $\varphi$. The rotation angle can be chosen by the user. The rotation is performed by applying the corresponding unitary operator to the current state $|\psi\rangle$. All units are in degrees.

The tab *Gates*, allows to apply the most common quantum gates to the current state. They are defined as follows:

- Pauli gates: $X = R_x(\pi)$ (NOT / bit flip), $Y = R_y(\pi)$, $Z = R_z(\pi)$ (phase filip)
- Hadamard gate: $H = R_x(\pi) R_y(\pi/2)$
- S gate: $S = R_z(\pi/2)$
- $\pi/8$ gate: $T = R_z(\pi/4)$

The tab *Pulses* computes the action of am rf pulse in the rotating frame. All units are dimensionless. A pulse with the amplitude 1 and a duration of 1 corrersponds to a $2\pi$ rotation. To apply pulses along different axes in the conventional sense, use the phase in degrees. The pulse is applied by multiplying the current state with the corresponding unitary operator. The buttons "apply pulse along x" and "apply pulse along y" apply a pulse with the given amplitude and duration along the $x$- and $y$-axis, respectively. Typically, in the phyical implementation, the pulse is only applied along one axis and phase differences between pulses are realized in the rotating frame.