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 or
where
where is the imaginary unit. Here we're seeing for the first time superpositions with a phase difference between the two parts. Phase is typically written as , where is the angle of a quantum state's amplitude in the complex plane β a two-dimensional plane where the horizontal axis represents real numbers and the vertical axis represents imaginary ones. You can think of it more intuitively as how shifted one wave is relative to another: are their peaks aligned, or is one wave shifted so its peak meets the other's trough?
Pauli matrices and observablesβ
There are three matrices, the so-called Pauli matrices, that relate to these three different basis choices , , and :
How exactly do these relate to the measurement bases? At first glance, these look like ordinary gate matrices β and they are. Each Pauli matrix can act on a qubit and change its state:
- Pauli-X flips and , like a classical NOT gate.
- Pauli-Z leaves unchanged but multiplies by , changing the relative phase.
- Pauli-Y flips the qubit and introduces a phase.
But Pauli matrices have a second, equally important interpretation. In quantum mechanics, any measurable quantity is called an observable, and observables are represented by matrices. The Pauli matrices correspond to measurements along three different axes, and their eigenstates correspond to the two possible measurement outcomes along each axis. (If you aren't familiar with the term eigenstate, that's okay β they are just special vectors associated with a given matrix.)
- β measurement in the Z basis (, )
- β measurement in the X basis (, )
- β measurement in the Y basis (, )
This explains why Pauli matrices seem to do double duty. They both act on states (as gates) and define measurement directions (as observables). Both roles come from the same underlying mathematics.
So how, in practice, do you measure in the X or Y basis? By default, our quantum computers are only set up to measure in the Z basis. So, you need to change bases by rotating the qubit's state vector in such a way that the information you're interested in, either X or Y, is now pointing in the Z direction. Then, you just perform a Z measurement as usual.
For example, measuring in the X basis can be done by applying a Hadamard gate, and then measuring in the Z basis. The Hadamard rotates the state so that βX-informationβ becomes βZ-information.β After that, a normal measurement does the job.
You will see more of the Pauli matrices in the next lesson, when we apply our new quantum-circuit-writing skills to a real problem in quantum physics.
The Bell state circuitβ
Now that we have a starting point β we know that states can be represented by vectors, gates can be represented by matrices, and measurements cause a state to "collapse" β let's walk through the circuit that creates and measures the Bell state above.
We start with the initial state of two qubits in :
Create the superpositionβ
The circuit begins by applying a Hadamard gate to qubit 0. As we saw in the previous section, the Hadamard takes the qubit from a definite state, either or , into a combination of both of those states. Recall that the Hadamard gate is:
To apply it to the first qubit in a two-qubit system, we use an expanded 4x4 matrix that applies to qubit 0 while leaving qubit 1 unchanged. Think of it as βapply to the first qubit and donβt touch the second qubitβ:
Then we multiply this by the initial state vector: