# Play With One Qubit

In this post we introduce the qubit and some ways to manipulate it.

A qubit is a two level quantum mechanical system. Our qubit starts off straightforward enough: if it is in state $|1\rangle$, when we want to see what bit it represents it will be a 1, and if it is in state $|0\rangle$, when we measure it to store it in a classical bit, we will always get a 0.

But the qubit is special because it allows for superpositions. A superposition is when the qubit is in a combination of state $|1\rangle$ and state $|0\rangle$. For example let's think about an unknown superposition, we will call it $\lvert\psi\rangle$. The state can be written as $|\psi\rangle = \alpha |0\rangle + \beta | 1 \rangle$, where $\alpha,$$\;\beta$ are parameters to describe the superposition. We are now not so sure about what we will get when we measure our qubit. We will still get 0 or 1, but the chances our qubit is found at 0 is related to the size of $\alpha,$ and the chances our qubit is found at 1 is related to the size of $\beta$.

To understand this we can visualize one qubit using what is called the Bloch sphere.

The state $\vert \psi \rangle$ can be represented by any point on the sphere, depending on $\alpha, \beta$. In quantum mechanics, we cannot observe a quantum state directly. We can only do a measurement that will give us a 0 or a 1. That is, we can store the measurement of the qubit in a classical bit. Imagine now that we can make repeated measurements. We will get a picture of how likely we are to measure 1 and how likely we are to measure 0. For the state$|\psi\rangle = \alpha |0\rangle + \beta | 1 \rangle$ our measurement to determine if it is $|0\rangle$ or $|1\rangle$ will tell us the probabilities are $\alpha^2$ to be $|0\rangle$ and $\beta^2$ to be $|1\rangle$.

Measuring superpositions gives probabilistic outcomes.

A qubit by itself is not very useful unless we can control it. For this, we apply operations to a qubit to change the state. The operations can be represented as gates on a quantum circuit gates.

Here we introduce some of the most common gates.

This is the X gate. It rotates $|\psi\rangle$ by $\pi$ or $180^\circ$ about the X-axis.

Can you guess what the Y gate does?

Right, it rotates $|\psi\rangle$ by $\pi$ about the Y-axis. Similarly the Z gate would rotate $|\psi\rangle$ by $\pi$ around the Z-axis.

There's one more gate we should discuss, the Hadamard gate. It's a combination of two rotations, $\pi$ about the Z-axis and $\pi/2$ about the Y-axis. The H gate takes a state $|0\rangle$ and creates a equal superpositions of $|0\rangle$ and $|1\rangle$.

When you look at quantum circuits, note this gate appears often at the beginning of many circuits, as creating superpositions is a common step to start doing quantum computations.

There are a few other common single-qubit gates such as S and T, among others.

In the project linked here, you can get started with one-qubit quantum circuit operations using *QASM*. Yeah, go ahead. All you need start playing with qubits is to change with the code there. Delete the "//" of some the commented lines to play with some of the gates in the code, and see the effect on the qubit. Then run the code. Due to the probabilistic nature of quantum mechanics, make sure to play with different numbers of iterations. 10 or more work well, but try also 1 and 100. Think of this as your one-qubit sandbox.

For more details on QASM, check out its documentation here.

Here is a list of some of the one-qubit gates featured in this exercise.

z // pi rotation about the Z-axis x // pi rotation about the X-axis y // pi rotation about the Y-axis h // The combination of two rotations, pi about the Z-axis followed by pi/2 about the Y-axis s // S-gate, square root of Z gate sdg // conjugate of S-gate t // Phase-gate, conjugate of square root of S-gate tdg // conjugate of Phase-gate x(0) // rotation around X-axis y(0) // rotation around Y-axis z(0) // rotation around Z axis

Think you've got the hang of it? Try solving the RubiQ's Sphere!