quantum-computingqubit

Convert from qubit density matrix to Bloch vector


Given the 2x2 density matrix of a qubit, how do I compute the point on the Bloch sphere that represents the qubit?

For example, the state |0⟩-|1⟩ has a density matrix of [[0.5,-0.5],[-0.5,0.5]] and should end up along the X axis. But the density matrix [[0.5, 0], [0, 0.5]] isn't biased in any direction and should end up at the origin.


Solution

  • The conversion depends on a couple arbitrary choices:

    Assuming you answer those with "at the bottom" and "right-handed", then this method will do it:

    def toBloch(matrix):
        [[a, b], [c, d]] = matrix
        x = complex(c + b).real
        y = complex(c - b).imag
        z = complex(d - a).real
        return x, y, z
    

    You switch to other choices by picking and choosing which outputs to negate.

    Testing it out:

    print(toBloch([[1, 0],
                   [0, 0]])) #Off, Z=-1
    # (0.0, 0.0, -1.0)
    
    print(toBloch([[0, 0],
                   [0, 1]])) #On, Z=+1
    # (0.0, 0.0, 1.0)
    
    print(toBloch([[0.5, 0.5],
                   [0.5, 0.5]])) #On+Off, X=-1
    # (-1.0, 0.0, 0.0)
    
    print(toBloch([[0.5, 0.5j],
                   [-0.5j, 0.5]])) #On+iOff, Y=-1
    # (0.0, -1.0, 0.0)
    
    print(toBloch([[0.5, 0.0],
                   [0.0, 0.5]])) #maximally mixed state, X=Y=Z=0
    # (0.0, 0.0, 0.0)