Last week I asked whether you preferred emails with images or without. 64% favored emails that contain images. So, here they are again.
You can read this post on Medium.
Quantum computing is a tough nut to crack. Especially if you are used to programming a classical computer. But quantum computing is not as forgiving as classical programming.
Let me briefly depict how I develop software classically. I start with a simple case. And once that works, I cope with edge cases. Additionally, I start with a concrete case. And once that works, I abstract the concreteness away to find a general solution.
That doesn’t work in quantum computing. Quantum computing is a b… let’s say it is a bit counter-intuitive. Whenever you think you understood how it works and proceed to the next step, it gives you a leg up. There, you’ll find yourself crying.
Let’s talk about quantum entanglement. Quantum entanglement is one of the astonishing characteristics of quantum mechanics. Two entangled particles share a state of superposition — no matter how far apart they are. Practically, we entangle qubits to construct meaningful quantum systems beyond a single qubit. All you need to understand is the CNOT-gate — the “controlled not transformation.”
Let’s say you have two qubits, P and Q. And, you apply the CNOT-gate on these two qubits with P is the control qubit, and Q is the target qubit. Then, P remains unchanged, and Q flips its state only if P is 1 but remains unchanged if P is 0. In other words, the CNOT-gate acts like a simple X (or NOT) gate applied on the target qubit only if the control qubit is 1.
The following truth table depicts the effect.
“That’s it?” you think. As mysterious as entanglement sounds from a physical perspective, it appears simple and intuitive from a programming perspective. Soon, you use it to add controls to other qubit transformations. Even further, you add controls to the controls. The CNOT becomes your favorite tool to create probabilistic quantum systems, such as Quantum Bayesian Networks. “Life is good,” you think.
Then, out of a sudden, it kicks back! Literally!
You stumble across quantum phase kickback. It disproves the apparent one-sidedness of the CNOT-gate. The control qubit doesn’t remain unchanged. For every action in physics, there is an opposite reaction. So, there is an effect on the control qubit. The control takes on the phase of the target qubit.
While the qubit phase doesn’t matter for a qubit that is 0, it does matter for a qubit in superposition. For example, the phase tells the difference between a qubit in state |+⟩ and |−⟩.
After you recovered from the shock, you fall in love with the qubit phase and phase kickback. It turns out that it is not only a part of famous quantum circuits, such as Deutsch’s algorithm. But it is, in fact, the building block of quantum advantage.
“Life is good, again,” you think.
So, what do you do? You start experimenting. By now, you have learned how to add even multiple controls to your quantum transformation gates. And, you have learned how to use the phase kickback effect to your advantage.
Wouldn’t it be great if we combined these two things? Wouldn’t it be great if we had a multi-controlled phase kickback?
First, let’s look at the phase kickback of the CNOT gate. Our quantum circuit has two qubits. We put the first into state |+⟩ and the second into state |−⟩.
from qiskit import QuantumCircuit, Aer, execute from qiskit.visualization import plot_bloch_multivector, plot_state_qsphere from math import pi # Create a quantum circuit with one qubit qc = QuantumCircuit(2) # put qubit 0 into |+> qc.h(0) # put qubit 1 into |-> qc.x(1) qc.h(1) out = execute(qc,Aer.get_backend('statevector_simulator')).result().get_statevector() plot_bloch_multivector(out)
The Bloch Spheres show that the qubits are in different phases.
Next, we apply the CNOT-gate on this state with the qubit at position is the control qubit and the qubit at position 1 is the target.
# Create a quantum circuit with one qubit qc = QuantumCircuit(2) # put qubit 0 into |+> qc.h(0) # put qubit 1 into |-> qc.x(1) qc.h(1) # apply CNOT gate with qubit 0 as control qubit qc.cx(0,1) out = execute(qc,Aer.get_backend('statevector_simulator')).result().get_statevector() plot_bloch_multivector(out)
We see the control qubit has changed its phase. When we apply further Hadamard gates on the qubits, we measure both as 1.
The following figure depicts the quantum circuit of this kickback case.
So, the control qubit of the CNOT gate takes over the phase of the target qubit. What would you think happens if we have two control qubits? Let’s take the following circuit for example. We also know the CCNOT gate as the Toffoli gate. It has two control qubits and applies a NOT gate on the target qubits only if both control qubits are in state |1⟩.
As a classical programmer, I would expect that we apply the phase of the target qubit to both control qubits. Consequently, the circuit should produce the measurement 111 — all three qubits measured as 1. Let’s have a look.
Oh, not again! Once you think you understood quantum gates, something completely unexpected happens. We see the target qubit is always 1 (the bottom left number). But the control qubits can be in any combination of 0 and 1.
Let’s look at the Bloch Spheres!
Oh, they seemed to be broken. We see the target qubit in state |1⟩. But we don’t see anything for the control qubits.
The problem is that the Toffoli gate results in an entangled quantum system. While Bloch Spheres look at individual qubits, we can’t represent an entangled quantum system individually anymore!
Conclusion
Apparently, in quantum computing, we can’t start with a simple and concrete case and then, add more complexity and abstraction, as we would do it in classical programming. The behavior of entanglement varies significantly in each case looked at in this post.
When we apply the CNOT gate on two qubits in the basis states |0⟩ and |1⟩, we can reason about their result in a truth table.
When we do the same on qubits in other states (such as |+⟩ and |−⟩), entangling the qubits is resolved and we see the phase kickback.
Finally, when we use multiple controls, as we do in the Toffoli gate, we end up with a completely different result. The system remains entangled!
You're interested in quantum computing and machine learning...
...But you don't know how to get started?