Пример #1
0
    def test_expand(self):
        """Test expand method."""
        rho0, rho1 = np.diag([1, 0]), np.diag([0, 1])
        rho_init = DensityMatrix(np.kron(rho0, rho0))
        chan1 = Kraus(self.UI)
        chan2 = Kraus(self.UX)

        # X \otimes I
        chan = chan1.expand(chan2)
        rho_targ = DensityMatrix(np.kron(rho1, rho0))
        self.assertEqual(chan.dim, (4, 4))
        self.assertEqual(rho_init @ chan, rho_targ)

        # I \otimes X
        chan = chan2.expand(chan1)
        rho_targ = DensityMatrix(np.kron(rho0, rho1))
        self.assertEqual(chan.dim, (4, 4))
        self.assertEqual(rho_init @ chan, rho_targ)

        # Completely depolarizing
        chan_dep = Kraus(self.depol_kraus(1))
        chan = chan_dep.expand(chan_dep)
        rho_targ = DensityMatrix(np.diag([1, 1, 1, 1]) / 4)
        self.assertEqual(chan.dim, (4, 4))
        self.assertEqual(rho_init @ chan, rho_targ)
syndrome_op = Kraus(job.result().get_unitary())

# Initialize fidelity simulation parameters
p_error = [0.05 * i for i in range(11)]
f1 = []
f2 = []

# Evolve initial state
for p in p_error:

    # Build noise channel
    bit_flip_channel = Kraus([[[0, np.sqrt(p)], [np.sqrt(p), 0]],
                              [[np.sqrt(1 - p), 0], [0, np.sqrt(1 - p)]]])
    bit_flip_channel = bit_flip_channel.tensor(bit_flip_channel).tensor(
        bit_flip_channel)
    bit_flip_channel = bit_flip_channel.expand(Kraus(np.eye(2))).expand(
        Kraus(np.eye(2)))

    # Apply channels
    corrupted_state = DensityMatrix(init_state.evolve(bit_flip_channel))
    corrected_state = DensityMatrix(corrupted_state.evolve(syndrome_op))
    corrected_state = DensityMatrix(corrected_state.evolve(
        qecc.correction_ckt))

    # Trace out syndrome
    ini = DensityMatrix(partial_trace(init_state, [3, 4]))
    corrupted_state = DensityMatrix(partial_trace(corrupted_state, [3, 4]))
    corrected_state = DensityMatrix(partial_trace(corrected_state, [3, 4]))

    # Record results
    f1.append(state_fidelity(ini, corrupted_state))
    f2.append(state_fidelity(ini, corrected_state))