Phase estimation procedure
Next, we'll discuss the phase-estimation procedure, which is a quantum algorithm for solving the phase estimation problem.
We'll begin with a low-precision warm-up, which explains some of the basic intuition behind the method. We'll then talk about the quantum Fourier transform, which is an important quantum operation used in the phase-estimation procedure, as well as its quantum circuit implementation. Once we have the quantum Fourier transform in hand, we'll describe the phase-estimation procedure in full generality and analyze its performance.
Warm-up: approximating phases with low precision
We'll begin with a couple of simple versions of the phase-estimation procedure that provide low-precision solutions to the phase-estimation problem. This is helpful for explaining the intuition behind the general procedure that we'll see a bit later in the lesson.
Using the phase kickback
A simple approach to the phase-estimation problem, which allows us to learn something about the value we seek, is based on the phase kick-back phenomenon. As we'll see, this is essentially a single-qubit version of the general phase-estimation procedure to be discussed later in the lesson.
As part of the input to the phase estimation problem, we have a unitary quantum circuit for the operation We can use the description of this circuit to create a circuit for a controlled- operation, which can be depicted as this figure suggests (with the operation viewed as a quantum gate, on the left and a controlled- operation on the right).
We can create a quantum circuit for a controlled- operation by first adding a control qubit to the circuit for and then replacing every gate in the circuit for with a controlled version of that gate — so our one new control qubit effectively controls every single gate in the circuit for This requires that we have a controlled version of every gate in our circuit, but we can always build circuits for these controlled operations in case they're not included in our gate set.
Now consider the following circuit, where the input state of all of the qubits except the top one is the quantum state eigenvector of
The measurement outcome probabilities for this circuit depend on the eigenvalue of corresponding to the eigenvector Let's analyze the circuit in detail to determine exactly how.
The initial state of the circuit is
and the first Hadamard gate transforms this state to
Next, the controlled- operation is performed, which results in the state
Using the assumption that is an eigenvector of having eigenvalue we can alternatively express this state as follows.
Here we observe the phase kickback phenomenon. It is slightly different this time than it was for Deutsch's algorithm and the Deutsch-Jozsa algorithm because we're not working with a query gate — but the idea is similar.
Finally, the second Hadamard gate is performed. After just a bit of simplification, we obtain this expression for this state.
The measurement therefore yields the outcomes and with these probabilities:
Here's a plot of the probabilities for the two possible outcomes, and as functions of
Naturally, the two probabilities always sum to Notice that when the measurement outcome is always and when the measurement outcome is always So, although the measurement result doesn't reveal exactly what is, it does provide us with some information about it — and if we were promised that either or we could learn from the circuit which one is correct without error.
Intuitively speaking, we can think of the circuit's measurement outcome as being a guess for to "one bit of accuracy." In other words, if we were to write in binary notation and round it off to one bit, we'd have a number like this:
The measurement outcome can be viewed as a guess for the bit When is neither nor there's a nonzero probability that the guess will be wrong — but the probability of making an error becomes smaller and smaller as we get closer to or
It's natural to ask what role the two Hadamard gates play in this procedure:
-
The first Hadamard gate sets the control qubit to a uniform superposition of and so that when the phase kickback occurs, it happens for the state and not the state, creating a relative phase difference that affects the measurement outcomes. If we didn't do this and the phase kickback produced a global phase, it would have no effect on the probabilities of obtaining different measurement outcomes.
-
The second Hadamard gate allows us to learn something about the number through the phenomenon of interference. Prior to the second Hadamard gate, the state of the top qubit is
and if we were to measure this state, we would obtain and each with probability telling us nothing about By performing the second Hadamard gate, however, we cause the number to affect the output probabilities.
Doubling the phase
The circuit above uses the phase kickback phenomenon to approximate to a single bit of accuracy. One bit of accuracy may be all we need in some situations — but for factoring we're going to need a lot more accuracy than that. A natural question is, how can we learn more about
One very simple thing we can do is to replace the controlled- operation in our circuit with two copies of this operation, like in this circuit:
Two copies of a controlled- operation is equivalent to a controlled- operation. If is an eigenvector of having eigenvalue then this state is also an eigenvector of this time having eigenvalue
So, if we run this version of the circuit, we're effectively performing the same computation as before, except that the number is replaced by Here's a plot illustrating the output probabilities as ranges from to
Doing this can indeed provide us with some additional information about If the binary representation of is
then doubling effectively shifts the binary point one position to the right:
And because we're equating with as we move around the unit circle, we see that the bit has no influence on our probabilities, and we're effectively obtaining a guess for the second bit after the binary point if we round to two bits. For instance, if we knew in advance that was either or then we could fully trust the measurement outcome to tell us which.
It's not immediately clear, though, how this estimation should be reconciled with what we learned from the original (non-doubled) phase kickback circuit to give us the most accurate information possible about So let's take a step back and consider how to proceed.
Two-qubit phase estimation
Rather than considering the two options described above separately, let's combine them into a single circuit like so.
The Hadamard gates after the controlled operations have been removed and there are no measurements here yet. We'll add more to the circuit as we consider our options for learning as much as we can about
If we run this circuit when is an eigenvector of the state of the bottom qubits will remain throughout the entire circuit, and phases will be "kicked" into the state of the top two qubits. Let's analyze the circuit carefully, by means of the following figure.
We can write the state like this:
When the first controlled- operation is performed, the eigenvalue gets kicked into the phase when (the top qubit) is equal to but not when it's So, we can express the resulting state like this:
The second and third controlled- gates do something similar, except for rather than and with replaced by We can express the resulting state like this:
If we think about the binary string as representing an integer in binary notation, which is we can alternatively express this state as follows.
Our goal is to extract as much information about as we can from this state.
At this point we'll consider a special case, where we're promised that for some integer In other words, we have so we can express this number exactly using binary notation with two bits, as . . . or . In general, might not be one of these four values, but thinking about this special case will help us to figure out how to most effectively extract information about in general.
First we'll define a two-qubit state vector for each possible value
After simplifying the exponentials, we can write these vectors as follows.
These vectors are orthogonal: if we choose any pair of them and compute their inner product, we get Each one is also a unit vector, so is an orthonormal basis. We therefore know right away that there is a measurement that can discriminate them perfectly — meaning that, if we're given one of them but we don't know which, then we can figure out which one it is without error.
To perform such a discrimination with a quantum circuit, we can first define a unitary operation that transforms standard basis states into the four states listed above.
To write down as a matrix, it's just a matter of taking the columns of to be the states
This is a special matrix, and it's likely that some readers will have encountered it before: it's the matrix associated with the -dimensional discrete Fourier transform. In light of this fact, let us call it by the name rather than The name is short for quantum Fourier transform — which is essentially just the discrete Fourier transform, viewed as a unitary operation. We'll discuss the quantum Fourier transform in greater detail and generality shortly.
We can perform the inverse of this operation to go the other way, to transform the states into the standard basis states If we do this, then we can measure to learn which value describes as Here's a diagram of a quantum circuit that does this.
To summarize, if we run this circuit when for the state immediately before the measurements take place will be (for encoded as a two-bit binary string), so the measurements will reveal the value without error.
This circuit is motivated by the special case that — but we can run it for any choice of and and hence any value of that we wish. Here's a plot of the output probabilities the circuit produces for arbitrary choices of
This is a clear improvement over the single-qubit variant described earlier in the lesson. It's not perfect — it can give us the wrong answer — but the answer is heavily skewed toward values of for which is close to In particular, the most likely outcome always corresponds to the closest value of to (equating and as before), and from the plot it looks like this closest value for always appears with probability just above When is exactly halfway between two such values, like for instance, the two equally close values of are equally likely.
Preparing to generalize to many qubits
Given the improvement we've just obtained by using two control qubits rather than one, in conjunction with the inverse of the -dimensional quantum Fourier transform, it's natural to consider generalizing it further — by adding more control qubits. When we do this, we obtain the general phase estimation procedure. We'll see how this works shortly, but in order to describe it precisely we're going to need to discuss the quantum Fourier transform in greater generality, to see how it's defined for other dimensions and to see how we can implement it (or its inverse) with a quantum circuit.
Quantum Fourier transform
The quantum Fourier transform is a unitary operation that can be defined for any positive integer dimension In this section, we'll see how this operation is defined and how it can be implemented with a quantum circuit on qubits with cost when
The matrices that describe the quantum Fourier transform are derived from an analogous operation on -dimensional vectors known as the discrete Fourier transform. This operation can be thought about in different ways. For instance, we can think about the discrete Fourier transform in purely abstract, mathematical terms as a linear mapping. Or we can think about it in computational terms, where we're given an -dimensional vector of complex numbers (using binary notation to encode the real and imaginary parts of the entries, let us suppose) and the goal is to calculate the -dimensional vector obtained by applying the discrete Fourier transform. Our focus will be on third way, which is viewing this transformation as a unitary operation that can be performed on a quantum system.
There's an efficient algorithm for computing the discrete Fourier transform on a given input vector known as the fast Fourier transform. It has applications in signal processing and many other areas, and is considered by many to be one of the most important algorithms ever discovered. As it turns out, the implementation of the quantum Fourier transform when is a power of 2 that we'll study is based on precisely the same underlying structure that make the fast Fourier transform possible.
Definition of the quantum Fourier transform
To define the quantum Fourier transform, we'll first define a complex number for each positive integer like this:
This is the number on the complex unit circle we obtain if we start at and move counter-clockwise by an angle of radians, or a fraction of of the circumference of the circle. Here are a few examples:
Now we can define the -dimensional quantum Fourier transform, which is described by an matrix whose rows and columns are associated with the standard basis states We're only going to need this operation for when is a power of for phase estimation, but the operation can be defined for any positive integer
As was already stated, this is the matrix associated with the -dimensional discrete Fourier transform. Often the leading factor of is not included in the definition of this matrix, but we need to include it to obtain a unitary matrix.
Here's the quantum Fourier transform, written as a matrix, for some small values of
Notice, in particular, that is another name for a Hadamard operation.
Unitarity
Let's check that is unitary, for any selection of One way to do this is to show that its columns form an orthonormal basis. We can define a vector corresponding to column number starting from and going up to like this:
Taking the inner product between any two of these vectors gives us this expression:
We can evaluate sums like this using the following formula for the sum of the first terms of a geometric series.
Specifically, we can use this formula when When we have so using the formula and dividing by gives
When we have so the formula reveals this:
This happens because so making numerator zero, while the denominator is nonzero because Intuitively speaking, what we're doing is summing a bunch of points that are distributed around the unit circle, and they cancel out and leave when summed.
We have therefore established that is an orthonormal set,
which reveals that is unitary.
Controlled-phase gates
To implement the quantum Fourier transform with a quantum circuit, we'll need to make use of controlled-phase gates. Recall that a phase operation is a single-qubit unitary operation of the form
for any real number A controlled version of this gate has the following matrix:
For this controlled gate, it doesn't actually matter which qubit is the control and which is the target because the two possibilities are equivalent. We can use any of the following symbols to represent this gate in quantum circuit diagrams.
For the third form, the label is also sometimes placed on the side of the control line or under the lower control when that's convenient.
To perform the quantum Fourier transform when and we're going to need to perform an operation on qubits whose action on standard basis states can be described as
where is a bit and is a number encoded in binary notation as a string of bits. This can be done using controlled-phase gates by generalizing the following example, for which
In general, for an arbitrary choice of the top qubit corresponding to the bit can be viewed as the control, with the phase gates ranging from on the qubit corresponding to the least significant bit of to on the qubit corresponding to the most significant bit of These controlled-phase gates all commute with one another and could be performed in any order.
Circuit implementation of the QFT
Now we'll see how we can implement the quantum Fourier transform with a circuit when the dimension is a power of There are, in fact, multiple ways to implement the quantum Fourier transform, but this is arguably the simplest method known. Once we know how to implement the quantum Fourier transform with a quantum circuit, it's straightforward to implement its inverse: we can replace each gate with its inverse (or, equivalently, conjugate transpose) and apply the gates in the reverse order. Every quantum circuit composed of unitary gates alone can be inverted in this way.
The implementation is recursive in nature, so that's how it's most naturally described. The base case is in which case the quantum Fourier transform is a Hadamard operation.
To perform the quantum Fourier transform on qubits when we can perform the following steps, whose actions we'll describe for standard basis states of the form where is an integer encoded as bits using binary notation and is a single bit.
-
First apply the -dimensional quantum Fourier transform to the bottom/leftmost qubits to obtain this state:
This is done by recursively applying the method being described for one fewer qubit, using the Hadamard operation on a single qubit as the base case.
-
Use the top/rightmost qubit as a control to inject the phase for each standard basis state of the remaining qubits (as is described above) to obtain this state:
-
Perform a Hadamard gate on the top/rightmost qubit to obtain this state:
-
Permute the order of the qubits so that the least significant bit becomes the most significant bit, with all others shifted up/right:
For example, here's the circuit we obtain for In this diagram, the qubits are given names that correspond to the standard basis vectors (for the input) and (for the output) for clarity.
Analysis
The key formula we need to verify that the circuit just described implements the -dimensional quantum Fourier transform is this one:
This formula works for any choice of integers and but we'll only need it for and It can be checked by expanding the product in the exponent on the right-hand side,
where the second equality makes use of the observation that
The -dimensional quantum Fourier transform is defined as follows for every
If we write and as
for and we obtain
Finally, by thinking about the standard basis states and as binary encodings of integers in the range
we see that the circuit above implements the required operation. If this method for performing the quantum Fourier transform seems remarkable, it's because it is: it's essentially the fast Fourier transform in the form of a quantum circuit.
Finally, let's count how many gates are used in the circuit just described. The controlled-phase gates aren't in the standard gate set that we discussed in the previous lesson, but to begin we'll ignore this and count each of them as a single gate.
Let's let denote the number of gates we need for each possible choice of If the quantum Fourier transform is just a Hadamard operation, so
If then in the circuit above we need gates for the quantum Fourier transform on qubits, plus controlled-phase gates, plus a Hadamard gate, plus swap gates, so
We can obtain a closed-form expression by summing:
We don't actually need as many swap gates as the method describes. If we rearrange the gates just a bit, we can push all of the swap gates out to the right and reduce the number of swap gates required to Asymptotically speaking this isn't a major improvement: we still obtain circuits with size for performing
If we wish to implement the quantum Fourier transform using only gates from our standard gate set, we need to either build or approximate each of the controlled-phase gates with gates from our set. The number required depends on how much accuracy we require, but as a function of the total cost remains quadratic.
It is, in fact, possible to approximate the quantum Fourier transform quite closely with a sub-quadratic number of gates by using the fact that is very close to the identity operation when is very small — which means that we can simply leave out most of the controlled-phase gates without suffering too much of a loss in terms of accuracy.
General procedure and analysis
Now we'll examine the phase-estimation procedure in general. The idea is to extend the two-qubit version of phase estimation that we considered above in the natural way suggested by the following diagram.
Notice that, for each new control qubit added on the top, we double the number of times the unitary operation is performed. This is indicated in the diagram by the powers on for each of the controlled-unitary operations.
The most straightforward way to implement a controlled- operation for some choice of is simply to repeat a controlled- operation times. If this is indeed the methodology that is used, it must be recognized that the addition of control qubits contributes significantly to the size of the circuit: if we have control qubits, like the diagram depicts, a total of copies of the controlled- operation are required. This means that a significant computational cost is incurred as is increased — but as we will see, it also leads to a significantly more accurate approximation of
It is important to note, however, that for some choices of it may be possible to create a circuit that implements the operation for large values of in a more efficient way than simply repeating times the circuit for We'll see a specific example of this in the context of integer factorization later in the lesson, where the efficient algorithm for modular exponentiation discussed in the previous lesson comes to the rescue.
Now let us analyze the circuit just described. The state immediately prior to the inverse quantum Fourier transform looks like this:
A special case
Along similar lines to what we did in the case, we'll first consider the special case that for In this case the state prior to the inverse quantum Fourier transform can alternatively be written like this:
So, when the inverse quantum Fourier transform is applied, the state becomes
and the measurements reveal (encoded in binary).
Bounding the probabilities
For other values of meaning ones that don't take the form for an integer the measurement outcomes won't be certain, but we can prove bounds on the probabilities for different outcomes. Going forward, let's consider an arbitrary choice of satisfying
After the inverse quantum Fourier transform is performed, the state of the circuit is this:
So, when the measurements on the top qubits are performed, we see each outcome with probability
To get a better handle on these probabilities, we'll make use of the same formula that we saw before, for the sum of the initial portion of a geometric series.
We can simplify the sum appearing in the formula for by taking Here's what we obtain.
So, in the case that we find that (as we already knew from considering this special case), and in the case that we find that
We can learn more about these probabilities by thinking about how arc lengths and chord lengths on the unit circle are related. Here's a figure that illustrates the relationships we need for any real number
First, the chord length (drawn in blue) can't possibly be larger than the arc length (drawn in purple):
Relating these lengths in the other direction, we see that the ratio of the arc length to the chord length is greatest when and in this case the ratio is half the circumference of the circle divided by the diameter, which is Thus, we have
and so
An analysis based on these relations reveals the following two facts.
-
Suppose that is a real number and satisfies
This means that is either the best -bit approximation to or it's exactly halfway between and either or so it's one of the two best approximations to
We'll prove that has to be pretty large in this case. By the assumption we're considering, it follows that so we can use the second observation above relating arc and chord lengths to conclude that
We can also use the first observation about arc and chord lengths to conclude that
Putting these two inequalities to use on reveals
This explains our observation that the best outcome occurs with probability greater than in the version of phase estimation discussed earlier. It's not really 40%, it's and in fact this bound holds for every choice of
-
Now suppose that satisfies
This means that there's a better approximation to in between and
This time we'll prove that can't be too big. We can start with the simple observation that
which follows from the fact that any two points on the unit circle can differ in absolute value by at most
We can also use the second observation about arc and chord lengths from above, this time working with the denominator of rather than the numerator, to conclude
Putting the two inequalities together reveals
Note that, while this bound is good enough for our purposes, it is fairly crude — the probability is usually much lower than
The important take-away from this analysis is that very close approximations to are likely to occur — we'll get a best -bit approximation with probability greater than — whereas approximations off by more than are less likely to occur, with probability upper bounded by
Given these guarantees, it is possible to boost our confidence by repeating the phase estimation procedure several times, to gather statistical evidence about It is important to note that the state of the bottom collection of qubits is unchanged by the phase estimation procedure, so it can be used to run the procedure as many times as we like. In particular, each time we run the circuit, we get a best -bit approximation to with probability greater than while the probability of being off by more than is bounded by If we run the circuit several times and take the most commonly appearing outcome of the runs, it's therefore exceedingly likely that the outcome that appears most commonly will not be one that occurs at most of the time. As a result, we'll be very likely to obtain an approximation that's within of the value Indeed, the unlikely chance that we're off by more than decreases exponentially in the number of times the procedure is run.
Here are two plots showing the probabilities for three consecutive values for when and as functions of (Only three outcomes are shown for clarity. Probabilities for other outcomes are obtained by cyclically shifting the same underlying function.)