In the previous post, we introduced the notion of a quantum system as a probabilistic system. It is a convenient way if you’re a beginner. Yet, it is far from being comprehensive.
We got to know the RY gate to increase the probability of measuring a qubit as 1. For instance, the Hadamard gate lets us measure the qubit as 1 with a probability of 50%. Once we added an RY gate, we increased it to 85%.
This code implements this circuit.
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.ry(2, 0)
qc.measure(0,0)
results = execute(qc,Aer.get_backend('qasm_simulator')).result()
plot_histogram(results.get_counts(), figsize=(4,2), color=['white'])
It produces the following results.
Why don’t we increase the probability of measuring the qubit as 1 even further?
Here’s an updated circuit.
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.ry(2, 0)
qc.ry(2, 0)
qc.measure(0,0)
The following figure shows the result of this circuit.
Oops. The probability of measuring the qubit as 1 decreased!
I’m curious what Obi-Wan would say now.
Superposition is a complex linear combination of 1 and 0.
Let’s look at what a linear combination of two states looks like.
Look at the arbitrary qubit state vector |𝜓⟩ in this figure. It originates in the center and has a magnitude (length) of 1/2. Due to this equal magnitude, all state vectors end at the pointed circle. So does |𝜓⟩.
The angle between the state vector |0⟩ and |𝜓⟩, named 𝜃 (“theta”), controls the proximities of the vector head to the top and the bottom of the system (dashed lines).
These proximities represent the probabilities of
𝛼² of measuring |𝜓⟩ as
0
and 𝛽² of measuring it as
1
.
The proximities
𝛼 and
𝛽 are at the opposite sidesof the state's probability (
|𝜓⟩) they describe.
𝛼 is the proximity (or distance) to
|1⟩ because with increasing distance to
|0⟩ the probability of measuring 0 increases.
Thus, by controlling the proximities, the angle 𝜃 also controls the probabilities of measuring the qubit in either state 0
or 1
.
Now, let’s look at what happens if 𝜃 is greater than 𝜋 (𝜋 is around 3.14).
If 𝜃 becomes greater than 𝜋, its proximity to |1⟩ decreases again, therefore making it less likely to observe the qubit as 1.
In Qiskit, we can easily look at the state vectors. When we run our circuit with the statevector_simulator
, we can use the function plot_bloch_multivector
from qiskit.visualization
to show Bloch Spheres of the qubits.
The following figure depicts the two states we created earlier. This representation is known as the Bloch Sphere.
Don’t bother with the Y-axis. Today, we only care about the vertical Z-axis with |0⟩ and |1⟩ on it and the X-axis. Both vectors reside on the circle that surrounds the X-axis and the Z-axis.
On the left-hand side, we see the qubit with lower 𝜃 and a higher probability of being 1. On the right-hand side, we see the other qubit with a greater value of 𝜃 and a lower probability of 1.
Thus far, our qubits are independent of each other. But only the ability to entangle qubits enables us to create a system beyond a simple random number generator.
Entanglement is an extremely strong correlation between qubits. Entangled qubits remain perfectly correlated even if separated by great distances.
Usually, we use the controlled-NOT gate (also known as CNOT or CX) to demonstrate entanglement. So let’s start by looking classically at this gate.
The truth table shows that this gate applies an X-gate on the target qubit only if the control qubit is in state |1⟩. Otherwise, it does nothing.
When we only look at the basis states, there is still nothing special going on here. The result is the same as that of a classical circuit.
Let’s use this gate in a circuit.
# Redefine the quantum circuit
qc = QuantumCircuit(2)
# apply X-gate on the control qubit
qc.x(0)
# Apply the CNOT-gate
qc.cx(0,1)
The following figure depicts the circuit diagram.
And this is the result of this circuit.
The resulting state vectors are unsurprisingly boring, too. We first put the top qubit into state |1⟩. Then, the CNOT gate puts the bottom qubit into state |1⟩, too.
We see both states pointing to |1⟩.
But it becomes interesting when the control qubit is in a state of superposition. Before we apply the CNOT gate, the Hadamard gate puts the qubit 𝑄Q into the state |+⟩. And, the NOT gate puts the target qubit in state |1⟩.
When measured, a qubit in this state is either 0 or 1, with a probability of 50% each. The following figure depicts the quantum circuit diagram.
# Redefine the quantum circuit
qc = QuantumCircuit(2)
# apply Hadamard gate on the control qubit
qc.h(0)
# apply X-gate on the target qubit
qc.x(1)
# Apply the CNOT-gate
qc.cx(0,1)
We measure the control qubit 𝑃 as either 0 or 1 with a probability of 50% each. This is exactly what we expect for a qubit in the state |+⟩. And, we measure the target qubit 𝑄 as the exact opposite.
“Of course it does!” you may think. If the control qubit 𝑃 is 0
, we leave the target qubit 𝑄 untouched in its state |1⟩. We measure it as 1
. But if the control qubit is 1
, we apply the X-gate on the qubit 𝑄. We turn it from |1⟩ into |0⟩ and measure it as 0
.
Let’s have a look.
So, let’s look at what linear algebra tells us about our two qubits. This is what happens if we print the state vectors.
… Just kidding…
This is the real output.
The good thing is, it didn’t explode. But it doesn’t help us much either.
Conclusion
Linear algebra and its visualization are powerful tools to reason about the qubit state. It explains why we measure qubits in certain values.
But this point of view has its shortcomings, too. The Bloch Sphere — that is the most prominent visualization — works only for single qubits. It doesn’t work well on entangled qubits. Unfortunately, quantum computing becomes interesting when we work with entangled qubits.
Moreover, understanding entangled qubits is the most challenging part of quantum computing. Too bad that this representation doesn’t help us here of all things.
This representation is our last hope.