Ejemplo n.º 1
0
 def test_rand_product_state(self):
     a = rand_product_state(3)
     assert a.shape[0] == 2**3
     assert_almost_equal((a.H @ a)[0, 0].real, 1.0)
     assert_almost_equal(mutual_information(a, [2, 2, 2], 0, 1), 0.0)
     assert_almost_equal(mutual_information(a, [2, 2, 2], 1, 2), 0.0)
     assert_almost_equal(mutual_information(a, [2, 2, 2], 0, 2), 0.0)
Ejemplo n.º 2
0
 def test_mutual_information_pure_sub(self):
     a = qu.up() & qu.bell_state(1)
     ixy = qu.mutual_information(a, [2, 2, 2], 0, 1)
     assert_allclose(0.0, ixy, atol=1e-12)
     ixy = qu.mutual_information(a, [2, 2, 2], 0, 2)
     assert_allclose(0.0, ixy, atol=1e-12)
     ixy = qu.mutual_information(a, [2, 2, 2], 2, 1)
     assert_allclose(2.0, ixy, atol=1e-12)
Ejemplo n.º 3
0
 def test_quantum_discord_pure(self):
     for _ in range(10):
         p = qu.rand_ket(4)
         p = p @ p.H
         iab = qu.mutual_information(p)
         qd = qu.quantum_discord(p)
         assert_allclose(iab / 2, qd)
Ejemplo n.º 4
0
 def test_mutinf_subsys_pure(self):
     p = rand_ket(2**7)
     dims = (2**3, 2**4)
     # exact
     mi0 = mutual_information(p, dims, sysa=0)
     mi1 = mutinf_subsys(p, dims, sysa=0, sysb=1, approx_thresh=1e30)
     assert_allclose(mi1, mi0)
     # approx
     mi2 = mutinf_subsys(p, dims, sysa=0, sysb=1, approx_thresh=1)
     assert_allclose(mi1, mi2, rtol=5e-2)
Ejemplo n.º 5
0
 def test_mutinf_subsys(self):
     p = qu.rand_ket(2**9)
     dims = (2**3, 2**2, 2**4)
     # exact
     rho_ab = qu.ptr(p, dims, [0, 2])
     mi0 = qu.mutual_information(rho_ab, [8, 16])
     mi1 = qu.mutinf_subsys(p, dims, sysa=0, sysb=2, approx_thresh=1e30)
     assert_allclose(mi1, mi0)
     # approx
     mi2 = qu.mutinf_subsys(p, dims, sysa=0, sysb=2, approx_thresh=1)
     assert_allclose(mi1, mi2, rtol=0.1)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def test_mutinf_interleave_pure(self):
     p = qu.singlet() & qu.singlet()
     ixy = qu.mutual_information(p, [2] * 4, sysa=(0, 2))
     assert_allclose(ixy, 4)
Ejemplo n.º 8
0
 def test_mixed_sub(self, inds):
     a = qu.rand_rho(2**3)
     rho_ab = qu.ptr(a, [2, 2, 2], inds)
     ixy = qu.mutual_information(rho_ab, (2, 2))
     assert (0 <= ixy <= 2.0)
Ejemplo n.º 9
0
 def test_mutual_information_pure(self):
     a = qu.bell_state(0)
     assert_allclose(qu.mutual_information(a), 2.)
     a = qu.rand_product_state(2)
     assert_allclose(qu.mutual_information(a), 0., atol=1e-12)
Ejemplo n.º 10
0
 def test_mutinf_interleave(self):
     p = dop(singlet() & singlet())
     ixy = mutual_information(p, [2] * 4, sysa=(0, 2))
     assert_allclose(ixy, 4)