def test_sqrt_channel_fidelity_different_channel():
    """Calculate the root channel fidelity of different channels."""
    choi_1 = dephasing(4)
    choi_2 = depolarizing(4)
    np.testing.assert_equal(
        np.isclose(sqrt_channel_fidelity(choi_1, choi_2), 1 / 2, atol=1e-3), True
    )
Beispiel #2
0
def test_depolarizing_complete_depolarizing():
    """Maps every density matrix to the maximally-mixed state."""
    test_input_mat = np.array([[1 / 2, 0, 0, 1 / 2], [0, 0, 0, 0],
                               [0, 0, 0, 0], [1 / 2, 0, 0, 1 / 2]])

    expected_res = (1 / 4 * np.array([[1 / 2, 0, 0, 1 / 2], [0, 0, 0, 0],
                                      [0, 0, 0, 0], [1 / 2, 0, 0, 1 / 2]]))

    res = apply_map(test_input_mat, depolarizing(4))

    bool_mat = np.isclose(expected_res, res)
    np.testing.assert_equal(np.all(bool_mat), True)
Beispiel #3
0
def test_depolarizing_partially_depolarizing():
    """The partially depolarizing channel for `p = 0.5`."""
    test_input_mat = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                               [13, 14, 15, 16]])

    expected_res = np.array([
        [17.125, 0.25, 0.375, 0.5],
        [0.625, 17.75, 0.875, 1],
        [1.125, 1.25, 18.375, 1.5],
        [1.625, 1.75, 1.875, 19],
    ])

    res = apply_map(test_input_mat, depolarizing(4, 0.5))

    bool_mat = np.isclose(expected_res, res)
    np.testing.assert_equal(np.all(bool_mat), True)
Beispiel #4
0
def test_partial_channel_dim_list():
    """
    Perform the partial map using the depolarizing channel as the Choi
    matrix on first system when the dimension is specified as list.
    """
    rho = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                    [13, 14, 15, 16]])
    res = partial_channel(rho, depolarizing(2), 2, [2, 2])

    expected_res = np.array([
        [3.5, 0.0, 5.5, 0.0],
        [0.0, 3.5, 0.0, 5.5],
        [11.5, 0.0, 13.5, 0.0],
        [0.0, 11.5, 0.0, 13.5],
    ])

    bool_mat = np.isclose(expected_res, res)
    np.testing.assert_equal(np.all(bool_mat), True)
Beispiel #5
0
def test_partial_channel_depolarizing_first_system():
    """
    Perform the partial map using the depolarizing channel as the Choi
    matrix on first system.
    """
    rho = np.array([
        [
            0.3500,
            -0.1220 - 0.0219 * 1j,
            -0.1671 - 0.0030 * 1j,
            -0.1170 - 0.0694 * 1j,
        ],
        [
            -0.0233 + 0.0219 * 1j,
            0.1228,
            -0.2775 + 0.0492 * 1j,
            -0.2613 + 0.0529 * 1j,
        ],
        [
            -0.2671 + 0.0030 * 1j,
            -0.2775 - 0.0492 * 1j,
            0.1361,
            0.0202 + 0.0062 * 1j,
        ],
        [
            -0.2170 + 0.0694 * 1j,
            -0.2613 - 0.0529 * 1j,
            0.2602 - 0.0062 * 1j,
            0.2530,
        ],
    ])
    res = partial_channel(rho, depolarizing(2))

    expected_res = np.array([
        [0.2364 + 0.0j, 0.0 + 0.0j, -0.2142 + 0.02495j, 0.0 + 0.0j],
        [0.0 + 0.0j, 0.2364 + 0.0j, 0.0 + 0.0j, -0.2142 + 0.02495j],
        [-0.2642 - 0.02495j, 0.0 + 0.0j, 0.19455 + 0.0j, 0.0 + 0.0j],
        [0.0 + 0.0j, -0.2642 - 0.02495j, 0.0 + 0.0j, 0.19455 + 0.0j],
    ])

    bool_mat = np.isclose(expected_res, res)
    np.testing.assert_equal(np.all(bool_mat), True)
Beispiel #6
0
def test_partial_channel_depolarizing_second_system():
    """
    Perform the partial map using the depolarizing channel as the Choi
    matrix on second system.
    """
    rho = np.array([
        [
            0.3101,
            -0.0220 - 0.0219 * 1j,
            -0.0671 - 0.0030 * 1j,
            -0.0170 - 0.0694 * 1j,
        ],
        [
            -0.0220 + 0.0219 * 1j,
            0.1008,
            -0.0775 + 0.0492 * 1j,
            -0.0613 + 0.0529 * 1j,
        ],
        [
            -0.0671 + 0.0030 * 1j,
            -0.0775 - 0.0492 * 1j,
            0.1361,
            0.0602 + 0.0062 * 1j,
        ],
        [
            -0.0170 + 0.0694 * 1j,
            -0.0613 - 0.0529 * 1j,
            0.0602 - 0.0062 * 1j,
            0.4530,
        ],
    ])
    res = partial_channel(rho, depolarizing(2), 1)

    expected_res = np.array([
        [0.2231 + 0.0j, 0.0191 - 0.00785j, 0.0 + 0.0j, 0.0 + 0.0j],
        [0.0191 + 0.00785j, 0.2769 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],
        [0.0 + 0.0j, 0.0 + 0.0j, 0.2231 + 0.0j, 0.0191 - 0.00785j],
        [0.0 + 0.0j, 0.0 + 0.0j, 0.0191 + 0.00785j, 0.2769 + 0.0j],
    ])

    bool_mat = np.isclose(expected_res, res)
    np.testing.assert_equal(np.all(bool_mat), True)
Beispiel #7
0
def test_kraus_to_choi_depolarizing_channel():
    """Kraus operators for depolarizing channel should yield the proper Choi matrix."""
    kraus_1 = np.array([[1 / np.sqrt(2), 0], [0, 0]])
    kraus_2 = np.array([[1 / np.sqrt(2), 0], [0, 0]])
    kraus_3 = np.array([[0, 0], [1 / np.sqrt(2), 0]])
    kraus_4 = np.array([[0, 0], [1 / np.sqrt(2), 0]])
    kraus_5 = np.array([[0, 1 / np.sqrt(2)], [0, 0]])
    kraus_6 = np.array([[0, 1 / np.sqrt(2)], [0, 0]])
    kraus_7 = np.array([[0, 0], [0, 1 / np.sqrt(2)]])
    kraus_8 = np.array([[0, 0], [0, 1 / np.sqrt(2)]])

    kraus_ops = [
        [kraus_1, kraus_2],
        [kraus_3, kraus_4],
        [kraus_5, kraus_6],
        [kraus_7, kraus_8],
    ]

    choi_res = kraus_to_choi(kraus_ops)
    expected_choi_res = depolarizing(2)

    bool_mat = np.isclose(choi_res, expected_choi_res)
    np.testing.assert_equal(np.all(bool_mat), True)
Beispiel #8
0
def test_partial_channel_invalid_dim():
    """Invalid dimension for partial map."""
    with np.testing.assert_raises(ValueError):
        rho = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [12, 11, 10, 9]])
        partial_channel(rho, depolarizing(3), 1, [2, 2])
Beispiel #9
0
def test_partial_channel_non_square_matrix_2():
    """Matrix must be square with sys arg."""
    with np.testing.assert_raises(ValueError):
        rho = np.array([[1, 2, 3, 4], [2, 2, 2, 2], [12, 11, 10, 9]])
        partial_channel(rho, depolarizing(3), 2)
Beispiel #10
0
def test_is_unital_depolarizing_choi_false():
    """Verify Choi matrix of the depolarizing map is not unital."""
    np.testing.assert_equal(is_unital(depolarizing(4)), False)
Beispiel #11
0
def test_is_completely_positive_choi_true():
    """Verify Choi matrix of the depolarizing map is completely positive."""
    np.testing.assert_equal(is_completely_positive(depolarizing(2)), True)
Beispiel #12
0
def test_is_positive_choi_true():
    """Verify that the Choi matrix of the depolarizing map is positive."""
    np.testing.assert_equal(is_positive(depolarizing(4)), True)
Beispiel #13
0
def test_is_trace_preserving_choi_true():
    """Verify Choi matrix of the depolarizing map is trace preserving."""
    np.testing.assert_equal(is_trace_preserving(depolarizing(2)), True)
def test_sqrt_channel_fidelity_inconsistent_dims():
    """Inconsistent dimensions between Choi matrices."""
    with np.testing.assert_raises(ValueError):
        choi_1 = depolarizing(4)
        choi_2 = dephasing(2)
        sqrt_channel_fidelity(choi_1, choi_2)
Beispiel #15
0
def test_partial_channel_non_square_matrix():
    """Matrix must be square."""
    with np.testing.assert_raises(ValueError):
        rho = np.array([[1, 1, 1, 1], [5, 6, 7, 8], [3, 3, 3, 3]])
        partial_channel(rho, depolarizing(3))
Beispiel #16
0
def test_is_completely_positive_choi_true():
    """Verify Choi matrix of the depolarizing map as a quantum channel."""
    np.testing.assert_equal(is_quantum_channel(depolarizing(2)), True)
Beispiel #17
0
def test_is_completely_positive_choi_true():
    """Verify that the Choi matrix of the depolarizing map is not a unitary channel."""
    np.testing.assert_equal(is_unitary(depolarizing(2)), False)