May 9, 2021

Quantum Bits

Quantum computing guides can be frustratingly high level or heavily mathematical. This is a middle ground explanation of Qubit (q-bit) superposition, entanglement and phase for developers who want to get started composing quantum circuits.

Quantum Bits

This article will tackle quantum bits / qubits, and why they are so interesting. For this guide, I will be using the terminology and interface offered by IBM's truly marvelous Quantum Composer, which you can find here:

https://quantum-computing.ibm.com

If you sign up for a free account, your quantum "circuits" will even be run on a real quantum computers. In this series of experiments, where real measurements are cited, I used the imbq_armonk r1.2, which is one of the IBM Quantum Canary Processors.

Superposition

Quantum bits can be either 0 or 1, but they can also be in superposition; where the state of the bit cannot be known until it is measured.

A circuit graph showing q-buit (0) with a H-Gate (Hadamard Gate)
A q-buit (0) with a H-Gate (Hadamard Gate) will be put into superposition.

Taking a normal q-bit and applying a Hadamard (H) Gate to it will make it equally likely that it will have a 0 or 1 value when measured.

A probability graph showing states 0 and 1 both have a 50% probability
While in superposition, the q-bit could be equally likely to be 0 or 1

When we measure the value, the end result could either be a 0 or 1, but the state of the qubit is no longer uncertain once measured:

Adding a measurement will cause the superposition to resolve to an actual value
A graph showing state 0 has a probability of 100%, while state 1 has a probability of 0
In this example, the q-bit was measured as 0. However, it could have also been 1.

Digging Deeper into Superpositions

When a qubit is in superposition, its value is unknown until it is measured. However, we can influence the value it will be through many operations, and we can influence the likelihood of a 0 value or 1 value. We can therefore express the "state" of the qubit in superposition as a sum of two "amplitudes" of possible values (0 and 1). A greater amplitude in one means that it's more likely that amplitude will be captured during measurement. This can be represented via the below form:

|ψ⧽ = α|0⧽ + β|1⧽

Amplitudes in quantum mechanics are related to probabilities, but they are not identical. Amplitudes are complex numbers. When squared, any complex number becomes a normal/real number, and handily - the value of the square of an amplitude is the probability (ignoring negative signs) . That is: the probability of "0" appearing in the above system is:

|α|2

and further,
|α|2 + |β|2 = 1

Note "amplitudes" are complex numbers, which is necessary to describe a lot of unintuative behavior. However, we don't even need to consider them as complex numbers to demonstrate their unintuitive nature. For instance, consider that a single Hadamard gate would appear to randomly make a 0 or 1 appear, but using two Hadamard gates in sequence "cancel out" and the result is the original value of the qubit.

Left, a quantum circuit of two Hadamard Gates, on the right, the same circuit with the bit flipped before entering the H-Gates.
Resulting probability graphs of both above circuits side-by-side shows the qubit end-state is seemingly unaffected by the two Hadamard gates

This proves that although it would appear the effect of a Hadamard gate is random, this is not the case; the qubit itself is supplying the randomness when it is in superposition - the Hadamard gate is merely changing amplitudes, allowing the qubits randomness to be expressed or suppressed. That to one side, the question remains - how is the qubit "remembering" it's previous value?

Considering the definition of a qubit state:

|ψ⧽ = α|0⧽ + β|1⧽

...we can postulate that, if the amplitudes were mereley real numbers, either amplitude could have their the sign flipped and there would be no observable difference to the probabilities of either |0⧽ or |1⧽ ocurring under measurement, but the two states would be mathematically distinct. This is because the probability of |0⧽ ocurring is |α|2, and the probability of |1⧽ ocurring is |β|2 - both operations would ignore the sign.

This is indeed what happens:

|0⧽ = 1|0⧽ + 0|1⧽

H|0⧽ = √½|0⧽ + √½|1⧽, which by convention is known as |+⧽

|1⧽ = 0|0⧽ + 1|1⧽

H|1⧽ = √½|0⧽ - √½|1⧽, which by convention is known as |-⧽

The two states, while appearing identical by measurement, actually have a different qubit "phase", which interacts with Hadamard gates to produce different outputs. We will return to phases later in this article.

Entanglement

Two (or more) qubits can be entangled by various gates.

Adding another bit (q1), we can use a controlled-NOT (CNOT) gate on q0 with a target of q1. This is similar to a NOT operation, but whereas a NOT operation will flip a bit, a CNOT operation will apply NOT on the target only if the source is 1.

A circuit graph showing qubit 0 being flipped via a NOT gate, then being used as the subject of a CNOT gate, with qubit 1 as the target.
Quibit 0 has a NOT gate to flip it from 0 to 1. Because q0 will now be "1", the target of the CNOT operation (q1) will be flipped.
A graph showing the state "1-1" has a 100% probability, with other states ("0-0", "0-1" and "1-0" having 0 probability)
This shows us that effectively we have set both bits to the same value (1).

It should be noted  that in the real world, we would run this experiment multiple times, because there is a small chance the quantum bits could flip on their own. This is about a 7% chance in the computer used at time of writing.

The interesting thing about the CNOT gate is that it enforces a relationship between two qubits even if one is in superposition. By this means, quantum entanglement is possible.

A circuit graph showing qubit 0 going through a Hadamard gate before being used as the subject of a CNOT gate, with qubit 1 as the target.
Example showing entangement of two qubits via CNOT gate, where qubit 0 was already in superposition.
A graph showing state "0-0" and "1-1" have a probabilty of 50% each, but states "0-1" and "1-0" have a probability of 0.
In this entangled state, the value of qubits 0 and 1 will always be the same, even though we don't know what the value will be.

Because one qubit is in a superposition, when we entangle the other with it, it is also put into a superposition. Measuring either qubit will end the superposition of both qubits.

A graph showing qubit 0 going through a Hadamard gate, then used as the subject of a CNOT gate with qubit 1 as the target, then a measurement is taken of qubit 0.
Measuring one qubit will give us a certain value.
A graph showing the probability of state "1-1" is 100%, but other states ("0-0", "0-1", and "1-0" have 0 probability)
In this example, both qubits became 1.

You can entangle two qubits using a CNOT gate and then throw one into superposition afterwards - but this does not entangle the two qubits.

A CNOT gate used before a qubit 0 is in superposition.
Qubit 0 is in superposition, but qubit 1 is a known value (0), independent of qubit 0.

Phase

As earlier stated in the article, the two amplitudes describing the state of a qubit are complex numbers. Complex numbers can be described as a Real and Imaginary number, or as a polar system, as an angle and a value. The angle is what is described when referring to "phase":

A graph of a unit circle on the complex plane, with a radial arm representing the value of the qubit, and the angle the arm makes as the phase.
Graph describing polar coordinate system of complex numbers.

We can manipulate phase using phase gates. One such gate is the "S" gate, which will rotate the phase on the |1⧽ amplitude by π/2.

Diagram showing the effect of S gates on the phases. It rotates the phase of the "1" amplitude but does not alter the "0" amplitude. By rotating phase, the end result of the circuit is the "0" amplitude, even though before the first Hadamard gate, the qubit was "1".
Phase can be manipulated between the two Hadamard gates from on our previous example to produce a different result.
The output of the above circuit shows the qubit output value is 0, even though before Hadamard Gates, it was set to 1.

Final Notes on Phase

Here are some tips on phases which I've not really found noted in most materials; presumably it's assumed knowledge.

The phases of amplitudes is distinct to the phase of the qubit as a whole. Qubit phase is the difference between the two amplitude phases. So, if amplitude "0" had a phase of π, and amplitude "1" had a phase of ½π, the qubit phase will be -½π (which is equivalent to ³⁄₂π). Qubit phase is useful to consider over amplitude phase sometimes because sometimes the difference in phases between the two amplitudes is the determining factor of behavior. For instance, a Hadamard gate will produce a "1" result if the qubit phase is π, regardless of whether the amplitude phases are 0 and π, π and 0, π/4 and 3π/4, and so on.

When dealing with multiple qubits of different phases, the phase of the whole output is the sum of the phases of the qubits.

References

IBM Quantum. https://quantum-computing.ibm.com, 2021