Quantum mechanics basics
Introduction
In the following video, Olivia Lanes steps you through the content in this lesson. Alternatively, you can open the YouTube video for this lesson in a separate window.
In the previous lesson, we learned how to produce an entangled state of two qubits, known as a "Bell state." When we measured the state, we saw that the measurements of the two qubits were correlated: when one was measured to be 0 then the other was also measured 0 and when one was 1 the other was measured 1, too. We saw that this is a hallmark of quantum entanglement. Today we'll dig deeper into this state and what it reveals about the quantum physics fundamental to quantum computing.
The Bell state
Many of the quantum phenomena that make quantum computers behave differently from classical computers are already present in the deceptively simple Bell state we produced in the previous lesson. Let's bring back that Bell state circuit:
# Added by doQumentation — required packages for this notebook
!pip install -q qiskit
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
qc.draw("mpl")
The image above represents the quantum circuit for making the Bell state . The two black horizontal lines represent our two qubits, and the boxes and other symbols on those lines represent gates or operations performed on the corresponding qubits. The gray double line is a classical information bus that allows us to store the classical information that we obtain by measuring the two qubits. We're going to dig into the details of this circuit and the resulting Bell state in order to understand the basics of quantum computing.
The math of quantum computing
Quantum state representation
First, we need a common language in which to discuss quantum states and circuits. There are a couple different ways to represent quantum states. The first is with Dirac notation. In Dirac notation, the state looks like this:
Here, the state is written inside angle brackets and vertical bars. The two terms each represent the two possible measurement outcomes of the state. So when we measure this state, we will either find that both of the qubits are in the state 0 or that both are in the state 1. The is called a "normalization constant." It is there to ensure that the sum of the squares each of the coefficients in the state all add up to . We'll discuss why this is the case later, in the section about measurements.
The second way to represent a state is in the standard language of linear algebra: as a vector, where each entry of the vector represents a different possible measurement outcome. In this notation, our Bell state would be written like this:
By convention, the entries of the vector are ordered as follows:
- The first entry corresponds to the two-qubit state
- The second to
- The third to
- The fourth to
As expected, in the Bell state vector , the first and fourth entries are nonzero, while the second and third entries are zero. The normalization constant ensures that the length of the vector is .
A note on the ordering of qubits
Qiskit uses little endian ordering. This means that the rightmost qubit is considered the first (or least significant) qubit, and the leftmost qubit is the most significant qubit. So, when we write a state like :
- the rightmost bit corresponds to qubit , and is in the state .
- the leftmost bit corresponds to qubit , and is in the state .
Gate representation
Just as states can be represented as vectors, gates can be represented as matrices. A gate acts on a state by transforming its vector into a new vector.
Each gate corresponds to a specific matrix that dictates how the state will be transformed. We apply this transformation by multiplying the gate matrix and the original state vector, with the gate matrix to the left of the state vector, like this:
where represents the gate matrix and represents the state vector.
Let's look at the Hadamard gate as an example. The Hadamard gate is a single-qubit gate (the red box labelled "H" in the circuit diagram above) that transforms the state to and the state to . In matrix notation, the Hadamard looks like:
Check your understanding
Use matrix multiplication to show that the Hadamard matrix transforms the states as expected. (If needed, you can learn how to do matrix multiplication.)
Answer
There are a few things to keep in mind about gate matrices:
- They are always square, matrices, where is also the dimension of the state vector it is applied to. For example, when you only have a single qubit, the state vector is two-dimensional, representing the two possible states 0 and 1 of the qubit. In this case, the dimensions of gate matrix applied to this system would be .
- Quantum gates are reversible. In other words, you can find another matrix that is the gate's inverse, which undoes the action of the gate and transforms the qubits back to their original state.
- Quantum gates also preserve the length of the vectors they transform. Quantum state vectors will always have length (guaranteed by the normalization constants we discussed earlier). The gates do not lengthen or shorten them, but simply rotate them.
These are all properties of unitary matrices. If you're curious about more of the mathematical properties of unitary matrices, you can read more about them in John Watrous's lesson on multiple systems in the Basics of Quantum Information course.
How measurements work
When we measure a quantum state, the result is always one of the possible outcomes (for a single qubit, either 0 or 1). Which outcome we get is random, but the quantum state tells us the probabilities of each outcome.
The entries in the state vector determine these probabilities. To get the probability of a particular outcome, we take the square of the entry corresponding to that outcome. For example, if a qubit is in the state:
the first entry (corresponding to 0) is , and the second entry (corresponding to 1) is also . Squaring these numbers gives
which means there is a 50% chance of measuring 0 and a 50% chance of measuring 1.
Recall that the sum of all the squared entries always adds up to 1. This makes sense because when we measure, we are guaranteed to get some outcome, so the probabilities of all possible outcomes must total 100%.
After measurement, the qubit collapses to the observed outcome, and any previous superposition is lost. The qubit now behaves like a classical bit. Measurements are fundamentally different from quantum gates. While gates change quantum states in a deterministic and reversible manner, measurement is inherently random and irreversible.
Measurement in different bases
By default, when you measure a qubit in a quantum circuit, you are measuring the qubit's state only along one axis. This is called the computational basis, or basis, which is defined by the states and . You can think of the state as a vector pointing straight up, and the state as a vector pointing straight down. So, a measurement in the basis answers the question, “Is the qubit's state pointing up or down?”
But this is not the only kind of question we can ask of a qubit. A qubit's state vector does not only point either up or down. A superposition of and will result in a state vector that points in any direction in three-dimensional space — what direction precisely depends on the relative amplitudes and phases of the two parts of the superposition. So, while a standard, -basis measurement asks "up or down?" you can also ask "left or right?" or "forward or backward?"
These questions correspond to measuring in different bases. Each basis has its own set of two basis vectors, which define the two possible measurement outcomes in that basis (like or for the -basis).
- Z basis measurement outcomes collapse to or
- X basis measurement outcomes collapse to or
- Y basis measurement outcomes collapse to