Esempio n. 1
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 ** num_qubits )
        self.sigmav = pauli.get_pauli_n_qubit_projection( num_qubits, location )
        self.sigmav = self.Hcoef * self.sigmav
Esempio n. 2
0
    def test_get_pauli_2_qubit_proj_3_1_2(self):
        num_qubits = 3
        qubit_pro1 = 1
        qubit_pro2 = 2
        paulis = get_pauli_n_qubit_projection(num_qubits,
                                              [qubit_pro1, qubit_pro2])
        self.assertTrue(len(paulis) == 16)

        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(np.kron(I, X), I), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Y), I), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Z), I), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, I), I), paulis))

        self.assertTrue(self.in_array(np.kron(np.kron(I, X), X), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Y), X), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Z), X), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, I), X), paulis))

        self.assertTrue(self.in_array(np.kron(np.kron(I, X), Y), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Y), Y), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Z), Y), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, I), Y), paulis))

        self.assertTrue(self.in_array(np.kron(np.kron(I, X), Z), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Y), Z), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, Z), Z), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, I), Z), paulis))
Esempio n. 3
0
    def test_get_pauli_1_qubit_proj_3_0(self):
        num_qubits = 3
        qubit_proj = 0
        paulis = get_pauli_n_qubit_projection(num_qubits, [qubit_proj])
        self.assertTrue(len(paulis) == 4)

        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(np.kron(X, I), I), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(Y, I), I), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(Z, I), I), paulis))
        self.assertTrue(self.in_array(np.kron(np.kron(I, I), I), paulis))
Esempio n. 4
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)

        self.Hcoef = -1j / (2**num_qubits)
        self.locations = locations
        self.paulis = [
            pauli.get_pauli_n_qubit_projection(num_qubits, location)
            for location in locations
        ]
        self.sigmav = self.Hcoef * np.array(self.paulis)

        self.working_locations = deepcopy(locations)
        self.working_sigmav = np.copy(self.sigmav)