Ejemplo n.º 1
0
    def test_get_norder_paulis_2(self):
        num_qubits = 2
        paulis = get_norder_paulis(num_qubits)
        self.assertTrue(len(paulis) == 4**num_qubits)

        X = np.array([[0, 1], [1, 0]], dtype=np.complex128)
        Y = np.array([[0, -1j], [1j, 0]], dtype=np.complex128)
        Z = np.array([[1, 0], [0, -1]], dtype=np.complex128)
        I = np.array([[1, 0], [0, 1]], dtype=np.complex128)

        self.assertTrue(self.in_array(np.kron(X, X), paulis))
        self.assertTrue(self.in_array(np.kron(X, Y), paulis))
        self.assertTrue(self.in_array(np.kron(X, Z), paulis))
        self.assertTrue(self.in_array(np.kron(X, I), paulis))
        self.assertTrue(self.in_array(np.kron(Y, X), paulis))
        self.assertTrue(self.in_array(np.kron(Y, Y), paulis))
        self.assertTrue(self.in_array(np.kron(Y, Z), paulis))
        self.assertTrue(self.in_array(np.kron(Y, I), paulis))
        self.assertTrue(self.in_array(np.kron(Z, X), paulis))
        self.assertTrue(self.in_array(np.kron(Z, Y), paulis))
        self.assertTrue(self.in_array(np.kron(Z, Z), paulis))
        self.assertTrue(self.in_array(np.kron(Z, I), paulis))
        self.assertTrue(self.in_array(np.kron(I, X), paulis))
        self.assertTrue(self.in_array(np.kron(I, Y), paulis))
        self.assertTrue(self.in_array(np.kron(I, Z), paulis))
        self.assertTrue(self.in_array(np.kron(I, I), paulis))
Ejemplo n.º 2
0
    def test_is_unitary1(self):
        paulis = get_norder_paulis(3)

        for i in range(10):
            alpha = np.random.random(4**3)
            U = sp.linalg.expm(1j * dot_product(alpha, paulis))
            self.assertTrue(is_unitary(U, tol=1e-14))
Ejemplo n.º 3
0
 def get_gate_matrix(self, x):
     """Produces the matrix for this gate on its own."""
     sigma = pauli.get_norder_paulis(self.gate_size)
     sigma = self.Hcoef * sigma
     alpha = self.get_function_values(x, True)
     H = utils.dot_product(alpha, sigma)
     return sp.linalg.expm(H)
Ejemplo n.º 4
0
    def __init__ ( self, num_qubits, gate_size, location ):
        """
        FixedGate Constructor

        Args:
            num_qubits (int): The number of qubits in the entire circuit

            gate_size (int): The number of qubits this gate acts on

            location (tuple[int]): The qubits this gate acts on
        """

        super().__init__( num_qubits, gate_size )

        if not utils.is_valid_location( location, num_qubits ):
            raise TypeError( "Specified location is invalid." )

        if len( location ) != gate_size:
            raise ValueError( "Location does not match gate size." )

        self.location = location

        self.Hcoef = -1j / ( 2 ** self.num_qubits )
        self.paulis = pauli.get_norder_paulis( self.gate_size )
        self.sigmav = self.Hcoef * np.array( self.paulis )
        self.I = np.identity( 2 ** ( num_qubits - gate_size ) )
        self.perm_matrix = perm.calc_permutation_matrix( num_qubits, location )
Ejemplo n.º 5
0
    def __init__ ( self, num_qubits, gate_size, locations ):
        """
        GenericGate Constructor

        Args:
            num_qubits (int): The number of qubits in the entire circuit

            gate_size (int): The number of qubits this gate acts on

            locations (list[tuple[int]]): The potential locations of this gate
        """

        super().__init__( num_qubits, gate_size )

        if not utils.is_valid_locations( locations, num_qubits, gate_size ):
            raise TypeError( "Specified locations is invalid." )

        self.locations = locations

        self.Hcoef = -1j / ( 2 ** self.num_qubits )
        self.paulis = pauli.get_norder_paulis( self.gate_size )
        self.sigmav = self.Hcoef * np.array( self.paulis )
        self.I = np.identity( 2 ** ( num_qubits - gate_size ) )
        self.perms = np.array( [ perm.calc_permutation_matrix( num_qubits, l )
                                 for l in self.locations ] )

        self.working_locations = deepcopy( locations )
        self.working_perms = np.copy( self.perms )
Ejemplo n.º 6
0
    def test_get_norder_paulis_0(self):
        num_qubits = 0
        paulis = get_norder_paulis(num_qubits)
        self.assertTrue(len(paulis) == 4**num_qubits)

        I = np.array([[1, 0], [0, 1]], dtype=np.complex128)

        self.assertTrue(self.in_array(I, paulis))
Ejemplo n.º 7
0
    def test_dexpmv_single(self):
        n = 2
        paulis = get_norder_paulis(n)
        H = dot_product(np.random.random(4**n), paulis)

        for p in paulis:
            F0, dF0 = dexpm_exact(H, p)
            F1, dF1 = dexpmv(H, p)

            self.assertTrue(np.allclose(F0, F1))
            self.assertTrue(np.allclose(dF0, dF1))
Ejemplo n.º 8
0
    def test_get_norder_paulis_1(self):
        num_qubits = 1
        paulis = get_norder_paulis(num_qubits)
        self.assertTrue(len(paulis) == 4**num_qubits)

        X = np.array([[0, 1], [1, 0]], dtype=np.complex128)
        Y = np.array([[0, -1j], [1j, 0]], dtype=np.complex128)
        Z = np.array([[1, 0], [0, -1]], dtype=np.complex128)
        I = np.array([[1, 0], [0, 1]], dtype=np.complex128)

        self.assertTrue(self.in_array(X, paulis))
        self.assertTrue(self.in_array(Y, paulis))
        self.assertTrue(self.in_array(Z, paulis))
        self.assertTrue(self.in_array(I, paulis))
Ejemplo n.º 9
0
    def test_dexpmv_vector(self):
        n = 2
        paulis = get_norder_paulis(n)
        H = dot_product(np.random.random(4**n), paulis)

        dFs0 = []
        for p in paulis:
            _, dF = dexpm_exact(H, p)
            dFs0.append(dF)

        dFs0 = np.array(dFs0)

        _, dFs1 = dexpmv(H, paulis)

        self.assertTrue(np.allclose(dFs0, dFs1))
Ejemplo n.º 10
0
    def test_is_square_matrix1(self):
        paulis = get_norder_paulis(3)

        for i in range(10):
            alpha = np.random.random(4**3)
            self.assertTrue(is_square_matrix(dot_product(alpha, paulis)))
Ejemplo n.º 11
0
    def test_is_hermitian ( self ):
        paulis = get_norder_paulis( 3 )

        for i in range( 10 ):
            alpha = np.random.random( 4 ** 3 )
            self.assertTrue( is_hermitian( dot_product( alpha, paulis ) ) )
Ejemplo n.º 12
0
 def get_gate_matrix ( self, x ):
     """Produces the matrix for this gate on its own."""
     sigma = pauli.get_norder_paulis( self.gate_size )
     sigma = self.Hcoef * sigma
     H = utils.dot_product( x, sigma )
     return sp.linalg.expm( H )