qiskit/extensions/initializer.py
def _bloch_angles(pair_of_complex):
        """
        Static internal method to work out rotation to create the passed in
        qubit from the zero vector.
        """
        [a_complex, b_complex] = pair_of_complex
        # Force a and b to be complex, as otherwise numpy.angle might fail.
        a_complex = complex(a_complex)
        b_complex = complex(b_complex)
        mag_a = np.absolute(a_complex)
        final_r = float(np.sqrt(mag_a ** 2 + np.absolute(b_complex) ** 2))
        if final_r < _EPS:
            theta = 0
            phi = 0
            final_r = 0
            final_t = 0
        else:
            theta = float(2 * np.arccos(mag_a / final_r))
            a_arg = np.angle(a_complex)
            b_arg = np.angle(b_complex)
            final_t = a_arg + b_arg
            phi = b_arg - a_arg

        return final_r * np.exp(1.J * final_t / 2), theta, phi
def _bloch_angles(pair_of_complex):
        """
        Static internal method to work out rotation to create the passed in
        qubit from the zero vector.
        """
        [a_complex, b_complex] = pair_of_complex
        # Force a and b to be complex, as otherwise numpy.angle might fail.
        a_complex = complex(a_complex)
        b_complex = complex(b_complex)
        mag_a = np.absolute(a_complex)
        final_r = float(np.sqrt(mag_a ** 2 + np.absolute(b_complex) ** 2))
        if final_r < _EPS:
            theta = 0
            phi = 0
            final_r = 0
            final_t = 0
        else:
            theta = float(2 * np.arccos(mag_a / final_r))
            a_arg = np.angle(a_complex)
            b_arg = np.angle(b_complex)
            final_t = a_arg + b_arg
            phi = b_arg - a_arg

        return final_r * np.exp(1.J * final_t / 2), theta, phi
def _bloch_angles ( pair_of_complex ) : [ a_complex , b_complex ] = pair_of_complex # Force a and b to be complex, as otherwise numpy.angle might fail. a_complex = complex ( a_complex ) b_complex = complex ( b_complex ) mag_a = np . absolute ( a_complex ) final_r = float ( np . sqrt ( mag_a ** 2 + np . absolute ( b_complex ) ** 2 ) ) if final_r < _EPS : theta = 0 phi = 0 final_r = 0 final_t = 0 else : theta = float ( 2 * np . arccos ( mag_a / final_r ) ) a_arg = np . angle ( a_complex ) b_arg = np . angle ( b_complex ) final_t = a_arg + b_arg phi = b_arg - a_arg return final_r * np . exp ( 1.J * final_t / 2 ) , theta , phi
Static internal method to work out rotation to create the passed in
        qubit from the zero vector.
Static internal method to work out rotation to create the passed in qubit from the zero vector .