Ejemplo n.º 1
0
    def test_apply_SWAP_gate_efficient(self):
        qc = QC(2, 0)
        qc.X(0)
        qc.SWAP(0, 1, efficient=True)

        np.testing.assert_array_equal(
            qc.total_density_matrix()[0].toarray(),
            np.array([[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]))
Ejemplo n.º 2
0
    def test_measurement_arbitrary_qubit_1(self):
        qc = QC(4, 0)
        qc.X(2)
        outcome = qc.measure(2, basis='Z', probabilistic=True)
        resulting_matrix = np.array([[0, 0], [0, 1]])

        self.assertEqual(outcome[0], 1)
        np.testing.assert_array_equal(
            qc.get_combined_density_matrix([2])[0].toarray(), resulting_matrix)
Ejemplo n.º 3
0
    def test_single_gate_error(self):
        qc = QC(1, 0, noise=True, pg=0.01)
        qc.X(0)

        expected_density_matrix = np.array([[2 / 3 * 0.01, 0],
                                            [0, (1 - 0.01) + 0.01 / 3]])
        np.testing.assert_array_almost_equal(
            qc.total_density_matrix()[0].toarray().real,
            expected_density_matrix)
Ejemplo n.º 4
0
    def test_SWAP(self):
        qc = QC(5, 0)
        qc.X(0)
        qc.SWAP(0, 1)

        density_matrix_0, qubits_0 = qc._qubit_density_matrix_lookup[0]
        density_matrix_1, qubits_1 = qc._qubit_density_matrix_lookup[1]
        np.testing.assert_array_equal(density_matrix_0.toarray(),
                                      np.array([[1, 0], [0, 0]]))
        np.testing.assert_array_equal(density_matrix_1.toarray(),
                                      np.array([[0, 0], [0, 1]]))
        self.assertEqual(qubits_0, [0])
        self.assertEqual(qubits_1, [1])
Ejemplo n.º 5
0
 def test_apply_X_gate(self):
     qc = QC(1, 0)
     qc.X(0)
     np.testing.assert_array_equal(qc.total_density_matrix()[0].toarray(),
                                   np.array([[0, 0], [0, 1]]))