Esempio n. 1
0
    def test_subsystem(self):
        rho = qu.rand_rho(6)
        dims = [3, 2]
        I, X, Y, Z = (qu.pauli(s) for s in 'IXYZ')
        mi_i = qu.mutual_information(rho, dims)
        p = 0.1
        Ek = [(1 - p)**0.5 * I, (p / 3)**0.5 * X, (p / 3)**0.5 * Y,
              (p / 3)**0.5 * Z]

        with pytest.raises(ValueError):
            qu.kraus_op(rho,
                        qu.randn((3, 2, 2)),
                        check=True,
                        dims=dims,
                        where=1)

        sigma = qu.kraus_op(rho, Ek, check=True, dims=dims, where=1)
        mi_f = qu.mutual_information(sigma, dims)
        assert mi_f < mi_i
        assert qu.tr(sigma) == pytest.approx(1.0)
        sig_exp = sum(
            (qu.eye(3) & E) @ rho @ qu.dag(qu.eye(3) & E) for E in Ek)
        assert_allclose(sig_exp, sigma)
Esempio n. 2
0
 def test_depolarize(self, stack):
     rho = qu.rand_rho(2)
     I, X, Y, Z = (qu.pauli(s) for s in 'IXYZ')
     es = [qu.expec(rho, A) for A in (X, Y, Z)]
     p = 0.1
     Ek = [(1 - p)**0.5 * I, (p / 3)**0.5 * X, (p / 3)**0.5 * Y,
           (p / 3)**0.5 * Z]
     if stack:
         Ek = np.stack(Ek, axis=0)
     sigma = qu.kraus_op(rho, Ek, check=True)
     es2 = [qu.expec(sigma, A) for A in (X, Y, Z)]
     assert qu.tr(sigma) == pytest.approx(1.0)
     assert all(abs(e2) < abs(e) for e, e2 in zip(es, es2))
     sig_exp = sum(E @ rho @ qu.dag(E) for E in Ek)
     assert_allclose(sig_exp, sigma)
Esempio n. 3
0
 def test_multisubsystem(self):
     qu.seed_rand(42)
     dims = [2, 2, 2]
     IIX = qu.ikron(qu.rand_herm(2), dims, 2)
     dcmp = qu.pauli_decomp(IIX, mode='c')
     for p, x in dcmp.items():
         if x == 0j:
             assert (p[0] != 'I') or (p[1] != 'I')
         else:
             assert p[0] == p[1] == 'I'
     K = qu.rand_iso(3 * 4, 4).reshape(3, 4, 4)
     KIIXK = qu.kraus_op(IIX, K, dims=dims, where=[0, 2])
     dcmp = qu.pauli_decomp(KIIXK, mode='c')
     for p, x in dcmp.items():
         if x == 0j:
             assert p[1] != 'I'
         else:
             assert p[1] == 'I'