Exemplo n.º 1
0
    def test_apply_SWAP_full_swap(self):
        qc = QC(3, 0, noise=True, pg=0.1)
        qc.CNOT(0, 1)
        qc.CNOT(1, 0)
        qc.CNOT(0, 1)

        qc2 = QC(3, 0, noise=True, pg=0.1)
        qc2.SWAP(0, 1, efficient=False)

        np.testing.assert_array_almost_equal(
            qc.total_density_matrix()[0].toarray(),
            qc2.total_density_matrix()[0].toarray())
Exemplo n.º 2
0
    def test_measure_first_qubit_bell_state_one(self):
        qc = QC(2, 1)
        qc.CNOT(0, 1)
        qc.measure(0, outcome=1, basis="Z")

        correct_result = np.array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
                                   [0, 0, 0, 1]])
        np.testing.assert_equal(qc.total_density_matrix()[0].toarray().real,
                                correct_result)
Exemplo n.º 3
0
    def test_measure_first_N_qubit(self):
        # Initialise system in |+0> state, CNOT on 2nd qubit and measure |+> on first qubit
        qc = QC(2, 1)
        qc.CNOT(0, 1)
        qc.measure_first_N_qubits(1, measure=0)

        correct_result = np.array([[0.5, 0.5], [0.5, 0.5]])
        np.testing.assert_array_equal(qc.total_density_matrix()[0].toarray(),
                                      correct_result)

        # Initialise second system also in |+0>, CNOT on 2nd qubit and measure |-> on first qubit
        qc2 = QC(2, 1)
        qc2.CNOT(0, 1)
        qc2.measure_first_N_qubits(1, measure=1)

        correct_result_2 = np.array([[0.5, -0.5], [-0.5, 0.5]])
        np.testing.assert_array_equal(qc2.total_density_matrix()[0].toarray(),
                                      correct_result_2)
Exemplo n.º 4
0
    def test_measure_first_qubit_bell_state_minus(self):
        # Initialise second system also in |+0>, CNOT on 2nd qubit and measure |-> on first qubit
        qc = QC(2, 1)
        qc.CNOT(0, 1)
        qc.measure(0, outcome=1)

        correct_result = 1 / 4 * np.array([[1, -1, -1, 1], [-1, 1, 1, -1],
                                           [-1, 1, 1, -1], [1, -1, -1, 1]])
        np.testing.assert_array_almost_equal(
            qc.total_density_matrix()[0].toarray().real, correct_result)
Exemplo n.º 5
0
    def test_two_qubit_gate_error(self):
        qc = QC(2, 0, noise=True, pg=0.01)
        qc.CNOT(0, 1)

        expected_density_matrix = np.array([[(1 - (0.01 * 12 / 15)), 0, 0, 0],
                                            [0, 0.04 / 15, 0, 0],
                                            [0, 0, 0.04 / 15, 0],
                                            [0, 0, 0, 0.04 / 15]])
        np.testing.assert_array_almost_equal(
            qc.total_density_matrix()[0].toarray().real,
            expected_density_matrix)
Exemplo n.º 6
0
    def test_apply_SWAP_efficient_swap(self):
        qc = QC(3, 0, noise=True, pg=0.1, pn=0.1)
        qc.create_bell_pair(1, 2)
        qc._uninitialised_qubits.append(0)
        # SWAP is equal to three CNOT operations
        qc.CNOT(1, 0)
        qc.CNOT(0, 1)
        qc.CNOT(1, 0)
        # Qubit 1 is now uninitialised due to swapping. Measure it such that it disappears from the density matrix
        qc.measure(1)

        qc2 = QC(3, 0, noise=True, pg=0.1, pn=0.1)
        qc2.create_bell_pair(1, 2)
        qc2._uninitialised_qubits.append(0)
        qc2.SWAP(1, 0, efficient=True)
        # Measurement of qubit 1 is not necessary, since the density matrices are not fused with the efficient SWAP

        np.testing.assert_array_almost_equal(
            qc.get_combined_density_matrix([0])[0].toarray(),
            qc2.get_combined_density_matrix([0])[0].toarray())