Example #1
0
def test_kraus_to_super():
    """Tests the function on random channels acting on random states.
    Channels and states are non-physical, but this is irrelevant for the test.
    """
    for num_qubits in (1, 2, 3, 4, 5):
        d = 2**num_qubits
        fake_kraus_ops = [
            np.random.rand(d, d) + 1.0j * np.random.rand(d, d)
            for _ in range(7)
        ]
        super_op = kraus_to_super(fake_kraus_ops)
        fake_state = np.random.rand(d, d) + 1.0j * np.random.rand(d, d)
        result_with_kraus = sum(
            [k @ fake_state @ k.conj().T for k in fake_kraus_ops])
        result_with_super = vector_to_matrix(
            super_op @ matrix_to_vector(fake_state))
        assert np.allclose(result_with_kraus, result_with_super)
Example #2
0
def test_vector_to_matrix():
    for d in [1, 2, 3, 4]:
        vec = np.random.rand(d**2)
        assert vector_to_matrix(vec).shape == (d, d)
        assert (matrix_to_vector(vector_to_matrix(vec)) == vec).all
Example #3
0
def test_non_squared_dimension():
    with raises(ValueError, match="must be a square number"):
        vector_to_matrix(np.random.rand(7))
    with raises(ValueError, match="must be a square number"):
        choi_to_super(np.random.rand(7, 7))
Example #4
0
def test_matrix_to_vector():
    for d in [1, 2, 3, 4]:
        mat = np.random.rand(d, d)
        assert matrix_to_vector(mat).shape == (d**2, )
        assert (vector_to_matrix(matrix_to_vector(mat)) == mat).all