Пример #1
0
def test_adjoint_of_complementary_channel_kraus_operators():
    r"""Test the adjoint channel of the complementary channel based on kraus operators."""
    # Test Adjoint complementary channel is unital
    rho = np.eye(4)
    krauss_ops = initialize_dephrasure_examples(0.1, 0.2)
    chan = DenseKraus(krauss_ops, [1, 1], 2, 3, orthogonal_kraus=[2])
    chan_s = SparseKraus(krauss_ops, [1, 1], 2, 3)

    desired = np.eye(2)
    # Test Dense Kraus
    actual = chan.entropy_exchange(rho, 1, adjoint=True)
    assert np.all(np.abs(actual - desired) < 1e-4)
    # Test Sparse Kraus
    actual = chan_s.entropy_exchange(rho, 1, adjoint=True).todense()
    assert np.all(np.abs(actual - desired) < 1e-4)

    # Test based on random density matrix.
    rho = rand_dm_ginibre(4, 4).data.toarray()
    desired = sum([
        rho[i, j] * krauss_ops[i].T.dot(krauss_ops[j]) for i in range(0, 4)
        for j in range(0, 4)
    ])
    actual = chan.entropy_exchange(rho, 1, adjoint=True)
    assert np.all(np.abs(actual - desired) < 1e-4)
    actual = chan_s.entropy_exchange(rho, 1, adjoint=True).todense()
    assert np.all(np.abs(actual - desired) < 1e-4)
Пример #2
0
def test_sparse_krauss_versus_dense_krauss():
    r"""Test the sparse krauss operators versus dense krauss operators."""
    p, q = 0.2, 0.4

    k_ops = initialize_dephrasure_examples(p, q)
    spkrauss = SparseKraus(k_ops, [1, 1], 2, 3)
    dKrauss = DenseKraus(k_ops, [1, 1], 2, 3)

    for n in range(1, 4):
        # Update channel to correpond to n.
        spkrauss.update_kraus_operators(n)
        dKrauss.update_kraus_operators(n)

        # Test nth krauss operators
        assert issubclass(type(spkrauss.nth_kraus_ops), SparseArray)
        spkrauss_nth_krauss = spkrauss.nth_kraus_ops.todense()
        dkrauss_nth_krauss = dKrauss.nth_kraus_ops
        assert_array_almost_equal(spkrauss_nth_krauss, dkrauss_nth_krauss)

        # Test exchange array
        assert issubclass(type(spkrauss.nth_kraus_exch), SparseArray)
        spkrauss_exchange = spkrauss.nth_kraus_exch.todense()
        dkrauss_exchange = dKrauss.nth_kraus_exch
        assert_array_almost_equal(dkrauss_exchange, spkrauss_exchange)

        # Test channel output
        rho = np.array(rand_dm_ginibre(2**n).data.todense())
        assert_array_almost_equal(spkrauss.channel(rho), dKrauss.channel(rho))

        # Test entropy exchange
        assert_array_almost_equal(
            spkrauss.entropy_exchange(rho, n)[0],
            dKrauss.entropy_exchange(rho, n)[0])
Пример #3
0
def test_adjoint_of_entropy_exchange():
    r"""Test the adjoint of the entropy exchange on pauli channel example."""
    p1, p2, p3 = 0.1, 0.01, 0.4
    krauss_ops = initialize_pauli_examples(p1, p2, p3)
    dense_krauss_obj = DenseKraus(krauss_ops, [1, 1], 2, 2)
    sparse_krauss_obj = SparseKraus(krauss_ops, [1, 1], 2, 2)

    # Test on random density matrices
    for n in [1, 2]:
        if n != 1:
            krauss_ops = np.kron(krauss_ops, krauss_ops)
        for _ in range(0, 50):
            dense_krauss_obj.update_kraus_operators(n)
            sparse_krauss_obj.update_kraus_operators(n)

            rho = np.array(rand_dm_ginibre(4**n).data.todense())

            desired = np.zeros((2**n, 2**n), dtype=np.complex128)
            for i, k1 in enumerate(krauss_ops):
                for j, k2 in enumerate(krauss_ops):
                    desired += np.conj(k2.T).dot(k1) * rho[j, i]

            dense_chan = dense_krauss_obj.entropy_exchange(rho, n, True)
            sparse_chan = sparse_krauss_obj.entropy_exchange(rho, n,
                                                             True).todense()

            assert_array_almost_equal(dense_chan, sparse_chan)
            assert_array_almost_equal(desired, dense_chan)
            assert_array_almost_equal(desired, sparse_chan)

    # Test that adjoint maps of compl. positive maps are always unital
    rho = np.eye(4**n)
    desired = np.eye(2**n)
    assert_array_almost_equal(
        desired,
        sparse_krauss_obj.entropy_exchange(rho, n, True).todense())
    assert_array_almost_equal(desired,
                              dense_krauss_obj.entropy_exchange(rho, n, True))