Exemplo n.º 1
0
 def test_dnorm_force_solve(self, dim, matrix_generator):
     """
     Metrics: checks that special cases for dnorm agree with SDP solutions.
     """
     if matrix_generator == 'bcsz':
         A = rand_super_bcsz(dim)
         B = rand_super_bcsz(dim)
     elif matrix_generator == 'haar':
         A = rand_unitary_haar(dim)
         B = rand_unitary_haar(dim)
     assert (dnorm(A, B, force_solve=False) == pytest.approx(dnorm(
         A, B, force_solve=True),
                                                             abs=1e-5))
Exemplo n.º 2
0
def test_dnorm_force_solve():
    """
    Metrics: checks that special cases for dnorm agree with SDP solutions.
    """
    def case(A, B, significant=4):
        assert_approx_equal(dnorm(A, B, force_solve=False),
                            dnorm(A, B, force_solve=True))

    for dim in (2, 3):
        for _ in range(10):
            yield (case, rand_super_bcsz(dim), None)
        for _ in range(10):
            yield (case, rand_unitary_haar(dim), rand_unitary_haar(dim))
Exemplo n.º 3
0
def test_rand_unitary_haar_unitarity():
    """
    Random Qobjs: Tests that unitaries are actually unitary.
    """
    U = rand_unitary_haar(5)
    I = qeye(5)

    assert_(U * U.dag() == I)
Exemplo n.º 4
0
def test_average_gate_fidelity_target():
    """
    Metrics: Tests that for random unitaries U, AGF(U, U) = 1.
    """
    for _ in range(10):
        U = rand_unitary_haar(13)
        SU = to_super(U)
        assert_almost_equal(average_gate_fidelity(SU, target=U), 1)
Exemplo n.º 5
0
def test_average_gate_fidelity_target():
    """
    Metrics: Tests that for random unitaries U, AGF(U, U) = 1.
    """
    for _ in range(10):
        U = rand_unitary_haar(13)
        SU = to_super(U)
        assert_almost_equal(average_gate_fidelity(SU, target=U), 1)
Exemplo n.º 6
0
def test_dnorm_force_solve():
    """
    Metrics: checks that special cases for dnorm agree with SDP solutions.
    """
    def case(A, B, significant=4):
        assert_approx_equal(
            dnorm(A, B, force_solve=False), dnorm(A, B, force_solve=True)
        )

    for dim in (2, 3):
        for _ in range(10):
            yield (
                case,
                rand_super_bcsz(dim), None
            )
        for _ in range(10):
            yield (
                case,
                rand_unitary_haar(dim), rand_unitary_haar(dim)
            )
Exemplo n.º 7
0
def random_herm_oper(_dims, n):
    return make_hermitian(rand_unitary_haar(2**n, dims=_dims))