# Given a state $|\phi\rangle=\frac{1}{\sqrt{2}}(|0\rangle+e^{i\theta}|1\rangle)$, how do I know the angle $\theta$?

Question1. If there is a state $$|\phi\rangle=\frac{1}{\sqrt{2}}(|0\rangle+e^{i\theta}|1\rangle)$$, and I want to know the angle $$\theta$$. What kind of measurement should I do? Could somebody give me the quantum circuit?

Question2. How to perform a measurement with base $$M{{({{\theta }_{k}})}_{\pm }}=\left\{ 1/\sqrt{2}\left( |0\rangle \pm {{e}^{-i{{\theta }_{k}}}}|1\rangle \right) \right\}$$ on IBMQ?

• Do you have many copies of the state $|\phi\rangle$, or just one? Can you access them all at once, or do you have them just one at a time? Mar 31 '20 at 9:34
• @WilliamYang in my answer for $\phi$ I assumed that we have many copies of the state $\phi$ (we can prepare them as many as we want). I will add this to my answer. Mar 31 '20 at 9:55
• @DavitKhachatryan but you also assumed you just get them one at a time. If you have them all at the same time, you can get a square root improvement I believe. Mar 31 '20 at 11:11
• @DavitKhachatryan I’ll write it up as a (partial) answer when I get the time. Basically, it’s the Fourier transform. Mar 31 '20 at 11:34
• @DavitKhachatryan hmmm maybe it doesn't quite work being given just the state $|\phi\rangle$ as compared to having an oracle that applies the unknown phase. I thought I'd seen something like it before, but cannot instantly reconstruct anything that out-performs your answer. Mar 31 '20 at 14:35

As mentioned in the comments of the question I assume that we can prepare $$|\phi \rangle$$ as many as we want. Let's calculate the relative phase for this one qubit pure state:

$$|\psi \rangle = \frac{1}{\sqrt{2}} \left( |0\rangle + e^{i\theta}|1\rangle\right)$$

We are going to execute $$2$$ different experiments in order to estimate $$\theta$$. In the first experiment we apply this circuit:

circuit_experiment_1.h(q[0])
circuit_experiment_1.measure(q[0], c[0])


$$H \frac{1}{\sqrt{2}} \left( |0\rangle + e^{i\theta}|1\rangle\right) = \frac{1}{2}\left[(1 + e^{i\theta})| 0 \rangle + (1 - e^{i\theta})| 1 \rangle \right]$$

The probabilities of $$|0\rangle$$ and $$|1\rangle$$ states:

\begin{align*} P(0) = \frac{1}{4}\left| 1 + e^{i\theta} \right|^2 = \frac{1}{2}(1 + \cos(\theta)) \\ P(1) = \frac{1}{4}\left| 1 - e^{i\theta} \right|^2 = \frac{1}{2}(1 - \cos(\theta)) \end{align*}

From here we can see that:

$$\theta = \pm \arccos\big(P(0) - P(1)\big)$$

because the range of usual principal value arccosine function is equal to $$[0, \pi]$$. So we will need the second experiment in order to estimate the $$sign(\theta)$$. But, before that, how to find $$P(0)$$ and $$P(1)$$ with the described experiment? We will need to execute the circuit $$N$$ times (bigger $$N$$ gives better precision) and take into accout these relations between measurement outcomes and probabilities:

\begin{align*} P(0) = \lim_{N \rightarrow \infty} \frac{N_{0}}{N} \qquad P(1) = \lim_{N \rightarrow \infty} \frac{N_{1}}{N} \end{align*}

where $$N_{0}$$ is the number of $$|0\rangle$$ measurement outcomes and $$N_{1}$$ is the number of $$|1\rangle$$ measurement outcomes. Also, note that:

$$\langle X \rangle = \langle \psi | X | \psi \rangle = \langle \psi |H Z H| \psi \rangle = P(0) - P(1)$$

So, the formula can be written in this way:

$$\theta = \pm \arccos \big( \langle X \rangle \big)$$

The sign of the $$\theta$$

Now we should determine the $$sign(\theta)$$ with this circuit:

circuit_experiment_2.sdg(q[0])
circuit_experiment_2.h(q[0])
circuit_experiment_2.measure(q[0], c[0])


The state after applying $$S^{\dagger}$$ and $$H$$ gates:

$$H S^{\dagger} \frac{1}{\sqrt{2}} \left( |0\rangle + e^{i\theta}|1\rangle\right) = \frac{1}{2}\left[(1 - i e^{i\theta})| 0 \rangle + (1 + i e^{i\theta})| 1 \rangle \right]$$

with the same logic:

\begin{align*} P'(0) = \frac{1}{4}\left| 1 - ie^{i\theta} \right|^2 = \frac{1}{2}(1 + \sin(\theta)) \\ P'(1) = \frac{1}{4}\left| 1 + ie^{i\theta} \right|^2 = \frac{1}{2}(1 - \sin(\theta)) \end{align*}

So after determining the $$P'(0)$$ and $$P'(1)$$ from the second experiment we will find the sign of the $$\theta$$:

$$sign(\theta) = sign(\arcsin\left(P'(0) - P'(1)\right)) = sign(P'(0) - P'(1))$$

because the range of usual principal value of arcsine function is $$[-\frac{\pi}{2}, \frac{\pi}{2}]$$.

Also, note that for the expectation value of the $$Y$$ operator (as can be seen from this answer) we have this relation:

$$\langle Y \rangle = \langle \psi| Y | \psi\rangle = \langle \psi| S H Z H S^{\dagger} | \psi\rangle = P'(0) - P'(1)$$

By taking this into account and combining two results:

\begin{align*} \theta = sign \big(\langle Y \rangle \big) \arccos \big(\langle X \rangle \big) \end{align*}

An approach for finding the relative phase of an arbitrary pure state is described in this answer.

Here is the circuit for measuring in $$M{{({{\theta }_{k}})}_{\pm }}=\left\{ 1/\sqrt{2}\left( |0\rangle \pm {{e}^{-i{{\theta }_{k}}}}|1\rangle \right) \right\}$$ basis. I assume here that $$\theta_k$$ is given:

circuit.u1(theta_k, q[0])    # q[0] is one of the qubits
circuit.h(q[0])
circuit.measure(q[0], c[0])   #c[0] is a classical bit


If the state was $$M(\theta _k)_+= 1/\sqrt{2}\left( |0\rangle + e^{-i\theta _k}|1\rangle \right)$$, then the outcome of the circuit will be $$|0\rangle$$, and if it was $$M(\theta _k)_-= 1/\sqrt{2}\left( |0\rangle - e^{-i\theta _k}|1\rangle \right)$$, then the outcome of the circuit will be $$|1\rangle$$. So this way we will be able to measure in $$M{{({{\theta }_{k}})}_{\pm }}$$ basis.

• Thank you so much! You do help me a lot! Mar 31 '20 at 9:41
• Nice answer. Just one question, why not to calculate an angle as $\theta = \arccos(2P(|0\rangle)-1)$ or $\theta = \arccos(1-2P(|1\rangle))$? I supposed you subtracted probabilities $P(|0\rangle)$ and $P(|1\rangle)$ from each other, right? Mar 31 '20 at 9:52
• Thanks Martin. You are right. I will add also that expression to the equation in the answer. I think $P(0) - P(1)$ is a more easily understandable expression, so I will keep it :) Mar 31 '20 at 10:10
• @WilliamYang, I did a mistake, it is corrected now. In the previous version of the answer, I didn't calculate $\theta$, there was a sign ambiguity that comes from the arccosine function that I haven't taken into account. Jul 26 '20 at 18:59
• Sorry,but what if I have only one state $|\varphi\rangle$ at a time?What kind of measurement should I do to get $\theta$? Nov 26 '20 at 8:26

I would just like to share a code for testing a phase measurement on IBM Q:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[1];
creg c[1];

//measuring theta in
//(|0> + |1>*exp(i*theta))

h q[0]; //(|0> + |1>)
t q[0]; //(|0> + |1>*exp(i*pi/4))
//s q[0]; //(|0> + |1>*exp(i*pi/2))
//u1 (pi/8) q[0]; //(|0> + |1>*exp(i*pi/8))

h q[0]; //measurment in Hadamard basis

measure q[0] -> c[0];


Tested on IBM Q Armonk (1 qubit processor).

EDIT (based on Davit comment): To infer a sign of the phase, a measurement in circular basis (i.e. adding $$S^\dagger$$ gate before Hadamard gate) has to be done as well. Combining results from measurement in Hadamard basis and circular basis gives complete knowledge about the phase.

• Thank you Martin ：） Mar 31 '20 at 10:30
• @DavitKhachatryan: I think that the circuit work correcly but only for phases between $0$ and $\pi$ as these values are returned by arccos. Jul 27 '20 at 7:19
• yes they work correctly for that values, but not for the relative phases between $\pi$ and $2\pi$. Jul 27 '20 at 7:21
• @DavitKhachatryan: Hi, I edited my answer. Just one question. I think we can replace $S$ with $S^\dagger$, right? Only one difference will be a sign before $i$ and switching formulas for $P'(0)$ and $P'(1)$. Jul 29 '20 at 8:17
• Martin, yes we did QST. BTW I was trying to avoid that :). Nevertheless, if for each expectation value we need to run let say $1000$ experiments for the precision, then the overall number of experiments will be $N = 3000$, but I think with this technique for the same precision $2000 < N \le 3000$ experiments will be needed. When the phase is near to $0$ we can execute QST, otherwise, we will do fewer experiments in order to estimate only the sign of the phase. Jul 31 '20 at 7:19