1
$\begingroup$

I need to get a state vector for one qubit from bloch coordinates no matter if there could be many states that describes the same bloch coordinates, and it does not have to be normalized, because the bloch coordinates will not always be in the sphere surface.
If this could be done easy with Cirq or Qiskit better, if not please pseudo code or python will be nice.

$\endgroup$

2 Answers 2

3
$\begingroup$

if you have Bloch vector co-ordinates as $ \left(\begin{array}{cc} x\\ y\\ z \end{array}\right) $, then just compute the following system

$$x = \sin\theta \cos\phi\,,$$

$$y = \sin\theta \sin\phi\,,$$

$$z = \cos\theta\,.$$

and obtain $\theta$ and $\phi$.

And your state will be

$$\left|{\psi}\right\rangle = \cos\frac{\theta}{2}\left|0\right\rangle+ e^{i\phi}\sin\frac{\theta}{2}\left|1\right\rangle\,.$$

So, your state vector in computational basis will be $$ \left|{\psi}\right\rangle = \left(\begin{array}{cc} \cos\frac{\theta}{2}\\ e^{i\phi}\sin\frac{\theta}{2} \end{array}\right)\,. $$

$\endgroup$
0
2
$\begingroup$

Thanks to FDGod, I code it in python like this:

def statefromBloch(b):

    all_zeros = not np.any(b)
    if all_zeros:
        b=np.array([1e-30,1e-30,1e-30])
    radius = sqrt(b[0]**2+b[1]**2+b[2]**2)    
    bn= b / np.linalg.norm(b)

    θ=acos(bn[2])
    
    seno = sin(θ)
    if (seno == 0): seno=  1e-30    

    ac = bn[0] / seno
    
    if ac > 1: ac = 1
    if ac < -1: ac = -1
    ϕ= acos(ac)
    if (b[1]<0.): ϕ=-ϕ
    
    svqubit = np.zeros(2,dtype = np.complex128)
    svqubit[0] = cos(θ/2)
    svqubit[1] = sin(θ/2) *( cos(ϕ)+1j*sin(ϕ))

    svqubit*=sqrt(radius)

    return svqubit
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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