Phase estimation
Contents
Phase estimation#
The quantum piece of Shor’s algorithm is period finding.
The key to doing period finding is doing phase estimation.
In phase estimation we have a unitary matrix
Unitary matrices have eigenvalues and eigenvectors.
The eigenvalues are always of the form
.
Our goal in phase estimation will be to take an eigenvector
The way that we will do this is to split up our wires into two parts: the top (blue below) and bottom (red).
At the top we are going to put it
At the end of the circuit we want the top to be
Let’s just consider the case where the unitary circuit
The number of bottom wires then is going to be 1 (since our unitary
If we only have one wire on the top then all we can say is that the phase
If we have two wires on the top then we could get the binary numbers:
Let’s start with one wire where we can largely work things out by hand. Implement the following circuit into your simulator and check that you get the right result.
To initialize your simulator in the configuration shown in the picture you want to start your initial basis as
Grading
Run your simulator for 100 evenly chosen values of
As a separate graph, let
Let’s try to improve upon our accuracy:
The reverse gate, as you might expect, reverses the order of its input wires. For two wires this is the same as a swap gate.
Grading
Implement this circuit and produce the same graphs as above. Post them in your document.
Again, this seems to be doing the best we can do with only two wires on top. Let’s see how to do this in general.
Now we want to understand how to do this in general. What is the general pattern?
(*Notice: * If you look through the math there was nothing special about the phase gate. In the picture below we will use
(Notice that
To get the second arrow correct, we can think of the number
This can be done by having a control wire from each of the wires for
Accomplishing the last arrow is done by the inverse of the quantum fourier transform. Pause this page and go here to build it.
Now that you’ve figured out how to build a general quantum fourier transform, you need to figure out how to invert it. The easiest way to do this is to write a python script invert.py
which takes a circuit description and inverts it.
Now that we have a working inverse quantum fourier transform, we can produce a general circuit that gets us whatever accuracy we want for our phase gate
Q: How should we build a circuit for
Grading
Run your code to generate a circuit description with 6 wires on top and then run your simulator making the same two graphs as above.
Congrats! You are successfully doing phase estimation.
Eigenstates in the bottom wires#
So far, we’ve only been putting in the eigenstate
Q: What happens if you put in a linear superposition of eigenstates?
Grading
Using
Notice that if you put in a linear superposition of eigenstates
Speed#
How fast is your algorithm?
The QFT takes a number of gates which is quadratic in the number of wires. Outside of the QFT, the number of phase gates you have to use, though, is exponential in the number of wires. This is bad! Generically you can’t do better then that (this is called the no fast forwarding theorem!) but, in special cases, there are tricks to speed things up.
For a phase gate (and Shor’s algorithm) there are tricks. Figure out what the trick is here to replace many phase gates with a single gate.
Run
Grading
Paste that circuit description (up through the controlled-phase gates).
A different unitary circuit.#
The next step is to try a different circuit on the bottom wire. Generalize your code to take an arbitrary circuit description of NOT and P gates at the bottom (it would be nice to do a general circuit on the bottom but you’d have to learn how to do control-H and control-control-NOT) and does phase estimation on that circuit.
For example, we could replace the bottom wire (which was a single phase gate) with the following two wires
2
NOT 0
P 0 0.3
NOT 1
Determine how to compute the phase of the unitary which represents this circuit of two wires, just as we did with the phase gate.
Grading
Generate a histogram of the probability of a given set of wires on the top.