예제 #1
0
    def u2(rads0, rads1, rads2, rads3, lib='np'):
        """
        Returns arbitrary 2-dim unitary matrix (U(2) group) parametrized as
        follows:

        exp(1j*(rads0 + rads1*sig_x + rads2*sig_y + rads3*sig_z))

        where rads1 is an angle in radians and sig_x is the x Pauli
        matrix, etc.


        Parameters
        ----------
        rads0 : float
        rads1 : float
        rads2 : float
        rads3 : float
        lib : str

        Returns
        -------
        np.ndarray

        """
        if 'autograd.numpy' in sys.modules:
            tlist = [rads0, rads1, rads2, rads3]
            return pu2(*tlist)
        return OneBitGates.get_fun(lib, 'exp')(1j * rads0) * \
               OneBitGates.rot(rads1, rads2, rads3, lib=lib)
예제 #2
0
    def phase_fac(ang_rads, lib='np'):
        """
        Returns

        exp(1j*ang_rads*I_2) = [[x, 0],[0, x]] with x = exp(1j*ang_rads)


        Parameters
        ----------
        ang_rads : float
        lib : str

        Returns
        -------
        np.ndarray

        """
        if 'autograd.numpy' in sys.modules:
            tlist = [0.] * 4
            tlist[0] = ang_rads
            return pu2(*tlist)
        mat_dict = OneBitGates.const_dict(0)
        x = OneBitGates.get_fun(lib, 'exp')(1j * ang_rads)
        mat_dict['11'] = x
        mat_dict['00'] = x
        return OneBitGates.get_mat(lib, mat_dict)
예제 #3
0
    def P_1_phase_fac(ang_rads, lib='np'):
        """
        Returns

        exp(1j*ang_rads*P_1) = [[1, 0],[0, x]] with x = exp(1j*ang_rads)

        Parameters
        ----------
        ang_rads : float
        lib : str

        Returns
        -------
        np.ndarray

        """
        if 'autograd.numpy' in sys.modules:
            tlist = [0.] * 4
            tlist[0] = -ang_rads / 2
            tlist[3] = -ang_rads / 2
            return np.exp(1j * ang_rads / 2) * pu2(*tlist)
        mat_dict = OneQubitGate.const_dict(0)
        x = OneQubitGate.get_fun(lib, 'exp')(1j * ang_rads)
        mat_dict['11'] = x
        mat_dict['00'] = 1
        return OneQubitGate.get_mat(lib, mat_dict)
예제 #4
0
    def rot_ax(rad_ang, axis, lib='np'):
        """
        Returns

        exp(1j*rad_ang*sig_n)

        where n = x if axis = 1, n = y if axis = 2 and n = z if axis = 3

        Parameters
        ----------
        rad_ang : float
        axis : int
        lib : str

        Returns
        -------
        np.ndarray

        """
        if 'autograd.numpy' in sys.modules:
            assert axis in [1, 2, 3]
            tlist = [0.] * 4
            tlist[axis] = rad_ang
            # print('mmbbvv', axis, pu2(*tlist))
            return pu2(*tlist)

        mat_dict = OneBitGates.const_dict(0)
        c = OneBitGates.get_fun(lib, 'cos')(rad_ang)
        s = OneBitGates.get_fun(lib, 'sin')(rad_ang)

        if axis == 1:
            mat_dict['00'] = c
            mat_dict['01'] = 1j * s
            mat_dict['10'] = 1j * s
            mat_dict['11'] = c
        elif axis == 2:
            mat_dict['00'] = c
            mat_dict['01'] = s
            mat_dict['10'] = -s
            mat_dict['11'] = c
        elif axis == 3:
            mat_dict['00'] = c + 1j * s
            mat_dict['11'] = c - 1j * s
        else:
            assert False, "axis not in [1,2,3]"

        return OneBitGates.get_mat(lib, mat_dict)
예제 #5
0
    def rot(rad_ang_x, rad_ang_y, rad_ang_z, lib='np'):
        """
        Returns

        exp(1j*(rad_ang_x*sig_x + rad_ang_y*sig_y + rad_ang_z*sig_z))

        where rad_ang_x is an angle in radians and sig_x is the x Pauli
        matrix, etc.

        Parameters
        ----------
        rad_ang_x : float
        rad_ang_y : float
        rad_ang_z : float
        lib : str

        Returns
        -------
        np.ndarray

        """
        if 'autograd.numpy' in sys.modules:
            tlist = [0., rad_ang_x, rad_ang_y, rad_ang_z]
            return pu2(*tlist)

        mat_dict = OneQubitGate.const_dict(0)
        vec = [rad_ang_x, rad_ang_y, rad_ang_z]
        n = OneQubitGate.get_fun(lib,
                                 'sqrt')(vec[0]**2 + vec[1]**2 + vec[2]**2)
        if abs(n) < 1e-8:
            mat_dict['00'] = 1
            mat_dict['11'] = 1
        else:
            nx = rad_ang_x / n
            ny = rad_ang_y / n
            nz = rad_ang_z / n
            c = OneQubitGate.get_fun(lib, 'cos')(n)
            s = OneQubitGate.get_fun(lib, 'sin')(n)
            mat_dict['00'] = c + 1j * s * nz
            mat_dict['01'] = s * ny + 1j * s * nx
            mat_dict['10'] = -s * ny + 1j * s * nx
            mat_dict['11'] = c - 1j * s * nz
        return OneQubitGate.get_mat(lib, mat_dict)