Example #1
0
def check_two_sets_of_krauss_are_same(krauss1, krauss2, numb=1000):
    is_same = True
    chann1 = AnalyticQChan(krauss1, [1, 1], 2, 2)
    chann2 = AnalyticQChan(krauss2, [1, 1], 2, 2)
    for _ in range(0, numb):
        # Get random Rho
        rho = np.array(rand_dm_ginibre(2).data.todense())
        rho1 = chann1.channel(rho, 1)
        rho2 = chann2.channel(rho, 1)
        # Compare them
        if np.any(np.abs(rho1 - rho2) > 1e-3):
            is_same = False
            break
    return is_same
Example #2
0
def test_channel_method_using_dephrasure():
    r"""Test the method 'channel' from 'QCorr.channel.AnalyticQChan' using dephrasure kraus ops."""
    p, q = 0.2, 0.4

    single_krauss_ops = set_up_dephrasure_conditions(p, q)
    orthogonal_krauss_indices = [2]
    for sparse in [False, True]:
        krauss_ops = single_krauss_ops.copy()
        channel = AnalyticQChan(single_krauss_ops, [1, 1], 2, 3,
                                orthogonal_krauss_indices, sparse)
        for n in range(1, 4):
            if n != 1:
                krauss_ops = np.kron(single_krauss_ops, krauss_ops)

            # Get random density state.
            rho = np.array(rand_dm_ginibre(2**n).data.todense())

            # Test channel method using kraus perators matches 'channel.channel'
            desired = np.zeros((3**n, 3**n), dtype=np.complex128)
            for krauss in krauss_ops:
                temp = krauss.dot(rho).dot(krauss.T)
                desired += temp
            actual = channel.channel(rho, n)
            assert_array_almost_equal(actual, desired)

    # Test constructor accepts the right input.
    assert_raises(TypeError, AnalyticQChan, "asdsa", [1, 1], 2, 2)