The Software Crisis
Software projects run over-budget, over-time, are inefficient, unmaintainable or ineffective. This is The Software "crisis".
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.
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:
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.
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.
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.
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:
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 + |β|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.
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.
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.
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.
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.
You can entangle two qubits using a CNOT gate and then throw one into superposition afterwards - but this does not entangle the two qubits.
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":
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.
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.
IBM Quantum. https://quantum-computing.ibm.com, 2021