**Contents**

**Superposition** ⚙️

**A qubit is represented as a combination of two quantum states are expressed as|0> for the “ground state” and |1> for the “excited state”, equivalent to 0 or 1 when translated to classical bits.**

Both states are combined like this to define a qubit:

Where α y β are complex numbers defining probability amplitudes. Hence, we can calculate:

For instance, a qubit defined by

has a 50-50 probability of becoming 0 or 1 when measured since

**Since α y β and are complex, the qubit can be represented as a point on the surface of a sphere, called the “Bloch Sphere”**. This graph is very useful to understand the behavior of a single qubit when modified by some gates.

Using this math, we can calculate the probability that a qubit shows up as 0 or 1 when measured. But be aware, the Bloch sphere does not work when you entangle two qubits.

**Sample quantum gates** 🚪

#### Hadamard Gate 🧲

**The Hadamard gate creates a basic 50-50 superposition. Hence, measuring it will (theoretically) provide a result of 0 or 1 with a probability of 50% for each of the states.**

Figure 2 shows a basic circuit built in** IBM Quantum Experience**, a highly recommended resource to learn about and experiment with quantum computing. Here we take a qubit initialized in “ground state”, , and apply a Hadamard gate (blue box) to it. At this step, the qubit is in superposition. Then, we measure it (pink box) and take the result as a classic bit: either 0 or 1.

The histogram below the circuit represents the results: Roughly 50% of the measures provided a 0 and 50% provided a 1, as expected.

Looking at this on the Bloch sphere we start with the qubit on the top of the Z axis

The Hadamard gate maps the Z axis into the X axis and vice versa. Hence, we have moved the qubit like this:

But measurements only happen on the Z axis. Hence, since our qubit is aligned with the X axis, it has no definite value on Z. When measuring, it will be like projecting it on Z and the result may be |0> or |1> with identical probability.

#### Undoing randomness with two Hadamard gates 💪

**One of the many weird things you can find when playing around with qubits in superposition is that applying a second Hadamard gate results in a |0> with 100% probability.**

Isn’t it weird if you think about it? We take a gate that converts a|0> into something that, when measured provides a perfectly random result. And if we apply the same gate to that perfectly random result, we get a 0 with absolute certainty. Why is that? The Bloch sphere can help us understand what is happening at quantum level.

We start with the qubit on the top of the Z axis

The Hadamard gate maps the Z axis into the X axis and vice versa. Hence, we have moved the qubit like this:

When we apply the Hadamard gate again we map X on Z.

Hence, we finish with the qubit again on Z and state|0> .

#### CNOT Gate 🛸

**Thanks to entanglement, two qubits will always provide correlated measurements**. Take for example the 50-50 qubit we saw before and consider that we have a second qubit entangled with it. Since the first qubit has equal probability to provide a 0 or 1 when measured we can’t predict what it will be. However, we can be sure that the value of the second qubit will have a known relationship with the first one when we measure it.

Take for example the CNOT (controlled NOT) quantum gate. It works with two qubits. The first qubit is known as the “control” and the gate applies a NOT to the second qubit when the control (the first qubit) is in state |1> . So, the CNOT gate will provide the following results:

|00> →|00>

|01> →|01>

|10> →|11>

|11> →|10>

**You might think that this looks pretty much like classical logical gates, but the core concept here is that it is applied to qubits while in superposition.**

Take Figure 4. We consider two qubits (q[0] and q[1]), both initialized at ground state.

As a first step we put q[0] in superposition using a Hadamard gate (blue box). We also put q[1] in “excited state” by using a NOT gate (green box).

Then, we apply the CNOT gate, making q[0] the control. Hence, since q[0] can be either |0> or |1> with 50% probability and q[1] is started as|1> the only transitions that we can get are:

|01> →|01>

|11> →|10>

And they once measured they show in the histogram 50% probability as expected due to the 50-50 probability of q[0].

Remember, the Bloch sphere can’t be used to represent two qubits after using a CNOT gate, because they have been entangled.

**Manipulating probabilities 😅**

I won’t go much deeper on quantum gates. If you are interested, I recommend you study the guides available in IBM Quantum Experience. **I’d just like to show you that probabilities in the result can be manipulated using different gates like in Figure 5 where the probability of measuring a 0 is much larger than that of obtaining a 1.**

Looking at this with the Bloch sphere, we start with the qubit in |0>.

We then apply a Hadamard gate, which maps Z on X.

Then we apply a T gate, which rotates the qubit π/4 around the Z axis.

By applying the Hadamard gate again we remap X on Z, hence the qubit rotates again:

**And when measuring it on Z we get that the probability of getting is not 100% because the projection comes somewhere to the top of the axis, but not at the top. The theoretical probability of obtaining 0 is 0.85, and of obtaining 1 it is 0.15.**

**The QSphere** 🌕

**The Bloch sphere is a particularly good tool to represent a single qubit, but it can’t represent two entangled qubits because their state is something “shared” and not particular of each one of them**. Once two qubits are entangled, they can’t be thought of like two independent entities. Their state is something that spans both qubits.

The qsphere can represent in a single visualization all the states of multiqubit system. For this reason it has been recently included as the default visualization in IBM Q Experience.

Take for instance this circuit:

We now know this represents 4 qubits that, before being measured can be in any of states with equal probability.

This is the histogram:

And this is the qsphere showing in a single diagram all 16 states.

**The size of the dots representing each state also show their probability to be measured. The larger the dot, the more likely that result would be if measured**. In this case all dots have the same size as they are equally probable. And the color of the dot represents the phase of that state.

The qsphere’s north pole represents the state where all qubits are |0>. The south pole represents the state where all qubits are |1>. And each of the parallels in the sphere represent from north to south states with a growing number of |1>’s: The northmost parallel represents all states with just one |1>, the next parallel southwards includes all states with two |1>’s, etc.

You can find a great thread by **@abe_asfaw** explaining the qsphere on **Twitter**. The very first video in the thread **shows how the qubit states interfere with each other to increase the probability of measuring a specific result in different phases of the Grover’s algorithm, a quantum search procedure**.

There is a growing trend to deprecate the Bloch sphere to teach and show qubit states in favor of the qsphere.

#### Where to go from here

Quantum computing algorithms and programming is a complex subject. Looking at the examples provided here you can think of the current state of quantum computing as if classic computing was wiring some tens of logic gates (AND, OR, XOR, etc). However, it is a new and promising paradigm in computing that will surely bring a new era to science and technology.

You can learn more about quantum computing at:

**IBM Quantum Experience**, where you can program real quantum computers from home using the timelines like the ones shown in this article.**Qiskit**, an open-source quantum computing software development framework for leveraging today’s quantum processors in research, education, and business.

Thanks to María José Ruiz Félez for the illustrations! 🙌