# Accuracy of Quantum Phase estimation; Finding the max difference integer, e

Working through Lab 5 in the Qiskit text, I have been attempting to complete Part 1, Step B. I implemented the following code as it seemed, at the time, to be what the question was asking for:

eList=[]

mList=list(count_qc4.values())
m=mList.index(max(mList))     #Giving the index of the highest value in the list as our desired output

#Calculate all possible e values
for i in range(16):
eList.append(round(np.absolute(phi_est[m]-phi_est[i])*(2**t)))

#Chose our e as the highest one
e=max(eList)
print('e = ',e)

This gives me $$e = 10$$. At the time I wrote this I was quite satisfied, but later on you rebuild the circuits with more counting qubits and are supposed to be able to graph the e-values you calculate to get $$e=2^{t-2}-1$$ which in the t=4 counting qubit scenario, gives me 3, not 10.

Any help with understanding how I was supposed to get that $$e = 3$$ using $$|m-b|\leq e/2^t$$ would be appreciated!

P.S. I have access to and have been referencing Sect 4.2.1 in QIQC by Nielson and Chaung as well as Sect 7.1.1 in the text by Kaye, Laflamme and Mosca.

I would like to suggest you my approach to QPE analysis which may be a bit different I think, but with a decent reasoning in my opinion. For the sake of that, first consider the following scheme of a QPE circuit with a counting register consisted of $$t$$ qubits, and an auxillary register in an eigenstate $$\lvert \psi \rangle$$ of the unitary operator $$U$$ (Using little-endian convention, as Qiskit does):

Now without explaining the entire mechanism of the QPE algorithm (for that we would need a seperate post), let's clarify some important issues:

1. Applying the operator $$U$$ upon the auxillary register which is in eigenstate $$\lvert \psi \rangle$$, yields: $$U \lvert \psi \rangle = e^{i2\pi\theta} \lvert \psi \rangle$$. The eigenvalue $$e^{i2\pi\theta}$$ is the phase $$\phi$$ of $$U$$ that we are seeking to discover. $$\theta$$ can be thought of as a coefficient of the full period phase $$2\pi$$. For example, if $$\theta = \frac{1}{4}$$ then $$\phi = 2\pi\theta = 2\pi\frac{1}{4} = \frac{\pi}{2}$$.
2. The value of any measurement in that circuit is essentially a binary string of length $$t$$, let it be $$x$$. The QPE algorithm is built such that $$x = 2^t\theta$$.
3. So by measuring we get $$x = 2^t\theta$$. From this equation we can easily extract $$\theta = \frac{x}{2^t}$$. Now computing the phase is simply $$\phi = 2\pi\theta$$.

I like to think in terms of $$\phi$$ (actual phase) rather than in terms of $$\theta$$ (an implicit coefficient of $$2\pi$$), finding it more convenient and intuitive. However, since the two terms are interchangeable, in the rest of this post I will mark "$$\color{green}\phi$$ terms" in green and "$$\color{red}\theta$$ terms" in red, in hope for preventing confusion.

The amount of qubits in the counting register $$t$$ is what sets the "resolution" of our phase estimation algorithm. The more qubits we add to the counting register, the more precise phase estimation we will be able to achieve (theoretically, ignoring noise and errors).

Let's think of a $$2\pi$$ phase as a unit circle over the complex plane. Then by setting the counting register with $$t$$ qubits we divide that circle with $$2^t$$ discrete lines, each line represents a discrete phase of $$(\frac{k}{2^t})2\pi, 0 < k < t$$. Then by running the QPE algorithm we can estimate the phase $$\color{green}\phi$$ to one of those $$2^t$$ discrete values. For emphasizing, here's a unit circle for $$t = 4$$ with $$2^4 = 16$$ lines:

If the phase $$\color{green}\phi$$ we are trying to estimate happens to be one of those $$2^t$$ discrete values - Then (ideally speaking, igonoring noise and errors) we should get an exact answer. If $$\color{green}\phi$$ isn't one of those $$2^t$$ discrete values, i.e it falls somewhere in between - Then we get some undesired results. We are supposed to measure the closest values to $$\color{green}\phi$$ in most shots, but we'll get other reuslts as well.

Now - by demanding "accuracy of up to $$\color{red}{2^{-2} = \frac{1}{4} = 0.25}$$" as in the lab you have linked to - That means we should keep just the results that are accurate up to a phase shift of $$\color{red}{0.25}\cdot 2 \pi = \color{green}{\frac{\pi}{2}}$$ from the most measured result, i.e from our "best estimation" - How would we do that?

Let's think again about our circle from before. Let's say, for example, that the most measured result is $$\color{green}{\frac{\pi}{4}}$$:

Keeping only the results that are accurate up to a phase shift of $$\color{red}{0.25}\cdot 2 \pi = \color{green}{\frac{\pi}{2}}$$ (excluded) from our line - That's keeping all lines that are inside the half circle (up to $$\color{green}{\frac{\pi}{2}}$$ to each direction) of our line.

$$2^t$$ lines are all the lines. $$2^{t - 1}$$ lines are $$\frac{1}{2}$$ of the lines. $$2^{t - 2}$$ lines are $$\frac{1}{4}$$ of the lines. $$2^{t - 2} - 1$$ is the closest we can get to $$\frac{1}{4}$$ because we are dealing with discrete values only. So if we let $$e = 2^{t - 2} - 1$$, and we allow results that are within $$e$$ difference away to each direction - Then it's the closest we can get to our "half circle" and it surely satisfy the $$\color{red}{2^{-2}}$$ accuracy condition:

Blue line - our "best estimation", i.e the most measured result. Green lines - $$e$$ results to each direction from our "best estimation".

Regarding the code you have tried yourself:

This equation: $$|m - b| \leq \frac{e}{2^{t}}$$ simply describes the functionality of $$e$$ - Set $$e$$ to some value, then that's the maximum difference you allow from $$b$$ ($$b$$ is the "best estimation"), and every other measurement $$m$$ of phases within the $$e$$ range determined - would satisfy this equation. So no need to "use" that equation.

The value $$e = 10$$ is clearly doesn't make any sense in the case of $$t = 4$$, becasue it allows deviation of $$10$$ phases to each direction (i.e $$20$$ total), and the overall discrete phases we have available are $$2^4 = 16$$.

• Very interesting. However, you might want to review 0.25=π/2 and everything that pertains to that equation. I didn't quite understand that part. Aug 23, 2022 at 4:17
• @MonteNero I have modified my answer with an explanation for that. Demanding accuracy of up to $2^{-2} = \frac{1}{4} = 0.25$ in implicit coeffcient terms of $2\pi$ is translated to an accuracy of $0.25\cdot 2 \pi = \frac{\pi}{2}$ when we think about the actual phase being estimated.