I've trying to measure the phase angle from X axis of a qubit, but unable to find any function in Q# documentation, can anyone help me with this?


If this is part of a debugging effort then you can use the DumpRegister function. If you have a qubit q which is in the general state $\alpha|0\rangle + \beta|1\rangle$ where $\alpha$ and $\beta$ are complex numbers such that $|\alpha|^2+|\beta|^2=1$.


will give an output like this (Having Different Numbers)

# wave function for qubits with ids (least to most significant): 1
∣0❭:     0.707107 +  0.000000 i  ==     ***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣1❭:    -0.500000 + -0.500000 i  ==     ***********          [ 0.500000 ]  /      [ -2.35619 rad ]

However if the qubit is entangled with some other qubit the result would be

Qubits provided (0;) are entangled with some other qubit.

Each row of the output tells the Amplitude of the Qubit along the Particular Computational Basis. The left hand values are in the Regular Complex Notation (Real and Imaginary Parts) and right hand values are in [Probability] [Phase].
The phase angle with $X$ axis is simply the $\arctan$ of the ratio of the absolute values of the amplitudes.


Let us say the results give the amplitudes of basis states $|0\rangle$ and $|1\rangle$ as $\alpha = \alpha_R + i\alpha_I = |\alpha|e^{i\theta_1}$ and $ \beta = \beta_R + i\beta_I =|\beta|e^{i\theta_2} $ respectively.
Then q is in the state $\alpha|0\rangle + \beta|1\rangle = |\alpha|e^{i\theta_1}|0\rangle + |\beta|e^{i\theta_2}|1\rangle$.
We can remove the global phase and thus the relative phase will be $e^{i\theta_1-i\theta_2} = e^{i\theta}$ and let $\phi = 2\arctan\frac{|\beta|}{|\alpha|}$.
Thus q is in the state $\cos\frac{\theta}{2}|0\rangle + e^{i\theta}\sin\frac{\theta}{2}|1\rangle$. This state can be represented on the Bloch Sphere by the coordinates $(\sin\theta\cos\phi, \sin\theta\sin\phi, \cos\theta)$. Consequently the phase angle with X axis is given by $\arctan$ of the $x$ and $y$ coordinates. Thus the phase angle is $\phi=2\arctan\frac{|\beta|}{|\alpha|}$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.