Quantum Phase Estimation (QPE) is a quantum algorithm that forms the building block of many more complex quantum algorithms. At its core, QPE solves a fairly straightforward problem: given an operator $U$ and a quantum state $\vert\psi\rangle$ that is an eigenvalue of $U$ with $U\vert\psi\rangle = \exp\left(2 \pi i \theta\right)\vert\psi\rangle$, can we obtain an estimate of $\theta$?

The answer is yes. The QPE algorithm gives us $2^n\theta$, where $n$ is the number of qubits we use to estimate the phase $\theta$.

2. Estimating $\pi$

In this demo, we choose $$U = u_1(\theta), \vert\psi\rangle = \vert1\rangle$$ where $$ u_1(\theta) = \begin{bmatrix} 1 & 0\\ 0 & \exp(i\theta) \end{bmatrix} $$ is one of the quantum gates available in Qiskit, and $$u_1(\theta)\vert1\rangle = \exp(i\theta)\vert1\rangle.$$

By choosing the phase for our gate to be $\theta = 1$, we can solve for $\pi$ using the following two relations:

From the output of the QPE algorithm, we measure an estimate for $2^n\theta$. Then, $\theta = \text{measured} / 2^n$ From the definition of the $u_1(\theta)$ gate above, we know that $2\pi\theta = 1 \Rightarrow \pi = 1 / 2\theta$

Combining these two relations, $\pi = 1 / \left(2 \times (\text{(measured)}/2^n)\right)$.

For detailed understanding of the QPE algorithm, please refer to the chapter dedicated to it in the Qiskit Textbook located at qiskit.org/textbook.