How To Think Of Quantum Computing As A Beginner
Start simple before you advance to complex notions
I’d like to start this week's letter with a little something of my own. For almost a year I write about quantum machine learning on a weekly basis. It started with the post on Quantum Machine Learning - Beyond The Hype and the highlight certainly is my book Hands-On Quantum Machine Learning With Python that you can get on Amazon (printed) or on Leanpub (ebook).
I am all the more pleased with the increasing recognition I receive. Yesterday, Quantum Zeitgeist published a review of my book and an interview with me. It tells me that I am not alone on my journey towards quantum machine learning mastery.
That being said, let’s continue with this journey.
Quantum computing is hard to understand. At least it seems that way if you’re new to the field. When you see all the mathematical formulae, you feel like Cletus.
Don’t worry! You’re not alone. I felt the same way. But, there’s a way out. As a beginner, it is paramount to start with a basic understanding of the quantum bit — that we call qubit.
Most of the explanations out there do not really help. Some explanations are so abstract that you cannot use them, such as
“the qubit is 0 and 1 simultaneously”
(it is not, but that’s another story). How do you work with that explanation?
Other explanations are purely mathematical, such as
The quantum superposition is a combination of two basis states |0⟩ and |1⟩
Fortunately, the truth depends on the point of view. And, there are different points of view.
Let’s first recap the basics of classical programming
In classical programming, we think about the boolean states: true and false. If 𝑃 is false it is not true. If 𝑄 is true, 𝑃∨𝑄 is true (𝑃 or 𝑄), but 𝑃∧𝑄 (𝑃 and 𝑄) is not.
There are only very few operators in boolean logic. Yet, we can combine them arbitrarily to construct complex algorithms. We use this kind of logic in conditional statements (if-then-else), in loops (for, while), and in assignments (P=Q).
And, we reason about boolean logic in truth tables.
When Obi-Wan tells us that something will be true, he applies boolean logic. He reasons about the reality in absolute terms.
In a classical system, a system that is sensitive dependent to initial conditions, the answer to a question is already determined before we ask it.
For instance, rather than watching the baseball match tonight, you spend the evening with your friends. When you return home, even though you don’t know the results, the match is over, and there is a definite result. There could be different results, but you don’t know the result until you look at it.
If we were able to measure all conditions precisely, we could tell the outcome. If you knew everything about the world, you would be able to calculate the result of the match without even watching it.
In classical systems, there is no randomness. Things appear random. But if we measured something with infinite precision, randomness would disappear.
Thinking in probabilities
What would Obi-Wan say if he thought in a quantum way?
Maybe, he would say: “What I’m about to tell you could be true or false. I know it once I look at it. But, I can tell you the probability. And, I can even change it.”
Obi-Wan applies a probabilistic perspective on quantum computing.
While a classical bit is true (==1) or false (==0), a quantum bit (qubit) can be in a state of superposition, as long as you don’t look at it. Superposition is a complex linear combination of 1 and 0. But once you look at the qubit, it is (and remains) either one value.
So, when we can’t observe this state of superposition, what’s the big deal?
The big thing is the consequences. In a quantum system, the answer to a question is not determined until you ask it. And since it is not determined yet, you can still change the outcome.
You return home, not knowing the results of the baseball match. You favor one of the teams. What do you do? Right, you alter the system to result in the state you would like to see.
Do you have doubts? Good! Not even Einstein liked this notion. It led him to his famous statement that God does not play dice.
Let’s turn to the quantum computer. And, let’s do some coding. Here’s a quantum bit in Qiskit (IBM’s quantum software development kit).
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0,0)
qc.draw()
The following figure depicts this quantum circuit graphically.
We define a quantum circuit with a single qubit (line 1). The Hadamard gate (line 2) puts it into a state of superposition.
When you measure it (line 3), you observe it as either 0 or 1, each with a probability of 50%.
results = execute(qc,Aer.get_backend('qasm_simulator')).result()
plot_histogram(results.get_counts())
The slight differences are due to the empirical nature of the simulator we use (`qasm_simulator`).
We're a fan of the value 1. So why don't we increase the probability of measuring it?
The 𝑅𝑌 gate (line 3) transforms a qubit's state of superposition. It affects the measurement probabilities.
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.ry(0.8, 0)
qc.measure(0,0)
qc.draw()
The circuit diagram shows the updated quantum circuit.
Let’s look at the results again.
results = execute(qc,Aer.get_backend('qasm_simulator')).result()
plot_histogram(results.get_counts())
Not too bad, is it?
I have to confess, this short introduction of the quantum circuit lacks a lot of details. It is far from being complete. But, it provides a reasonable way of how to think about a qubit.
The notion that the qubit is a probabilistic system comes in handy if you’re a beginner. It is not too abstract to understand. Yet, it is sufficient to start experimenting with qubits in a quantum circuit.
Once you understand the implications of a qubit as a probabilistic system, you’re ready to proceed with advanced ways of looking at a qubit.