Esempio n. 1
0
    def case(S, n_trials=50):        
        S = to_super(S)
        left_dims, right_dims = S.dims
        
        # Assume for the purposes of the test that S maps square operators to square operators.
        in_dim = np.prod(right_dims[0])
        out_dim = np.prod(left_dims[0])
        
        S_dual = to_super(S.dual_chan())
        
        primals = []
        duals = []
    
        for idx_trial in range(n_trials):
            X = rand_dm_ginibre(out_dim)
            X.dims = left_dims
            X = operator_to_vector(X)
            Y = rand_dm_ginibre(in_dim)
            Y.dims = right_dims
            Y = operator_to_vector(Y)

            primals.append((X.dag() * S * Y)[0, 0])
            duals.append((X.dag() * S_dual.dag() * Y)[0, 0])
    
        np.testing.assert_array_almost_equal(primals, duals)
Esempio n. 2
0
    def case(S, n_trials=50):
        S = to_super(S)
        left_dims, right_dims = S.dims

        # Assume for the purposes of the test that S maps square operators to square operators.
        in_dim = np.prod(right_dims[0])
        out_dim = np.prod(left_dims[0])

        S_dual = to_super(S.dual_chan())

        primals = []
        duals = []

        for idx_trial in range(n_trials):
            X = rand_dm_ginibre(out_dim)
            X.dims = left_dims
            X = operator_to_vector(X)
            Y = rand_dm_ginibre(in_dim)
            Y.dims = right_dims
            Y = operator_to_vector(Y)

            primals.append((X.dag() * S * Y)[0, 0])
            duals.append((X.dag() * S_dual.dag() * Y)[0, 0])

        np.testing.assert_array_almost_equal(primals, duals)
Esempio n. 3
0
def test_dual_channel(sub_dimensions, n_trials=50):
    """
    Qobj: dual_chan() preserves inner products with arbitrary density ops.
    """
    S = rand_super_bcsz(np.prod(sub_dimensions))
    S.dims = [[sub_dimensions, sub_dimensions],
              [sub_dimensions, sub_dimensions]]
    S = to_super(S)
    left_dims, right_dims = S.dims

    # Assume for the purposes of the test that S maps square operators to
    # square operators.
    in_dim = np.prod(right_dims[0])
    out_dim = np.prod(left_dims[0])

    S_dual = to_super(S.dual_chan())

    primals = []
    duals = []

    for _ in [None] * n_trials:
        X = rand_dm_ginibre(out_dim)
        X.dims = left_dims
        X = operator_to_vector(X)
        Y = rand_dm_ginibre(in_dim)
        Y.dims = right_dims
        Y = operator_to_vector(Y)

        primals.append((X.dag() * S * Y)[0, 0])
        duals.append((X.dag() * S_dual.dag() * Y)[0, 0])

    np.testing.assert_array_almost_equal(primals, duals)
Esempio n. 4
0
def test_fidelity_bounded_mixedmixed(tol=1e-7):
    """
    Metrics: Fidelity of mixed states within [0, 1].
    """
    for _ in range(10):
        rho = rand_dm_ginibre(11)
        sigma = rand_dm_ginibre(11)
        F = fidelity(rho, sigma)
        assert_(-tol <= F <= 1 + tol)
Esempio n. 5
0
def test_fidelity_bounded_mixedmixed(tol=1e-7):
    """
    Metrics: Fidelity of mixed states within [0, 1].
    """
    for _ in range(10):
        rho = rand_dm_ginibre(11)
        sigma = rand_dm_ginibre(11)
        F = fidelity(rho, sigma)
        assert_(-tol <= F <= 1 + tol)
Esempio n. 6
0
def test_call():
    """
    Test Qobj: Call
    """
    # Make test objects.
    psi = rand_ket(3)
    rho = rand_dm_ginibre(3)
    U = rand_unitary(3)
    S = rand_super_bcsz(3)

    # Case 0: oper(ket).
    assert U(psi) == U * psi

    # Case 1: oper(oper). Should raise TypeError.
    with expect_exception(TypeError):
        U(rho)

    # Case 2: super(ket).
    assert S(psi) == vector_to_operator(S * operator_to_vector(ket2dm(psi)))

    # Case 3: super(oper).
    assert S(rho) == vector_to_operator(S * operator_to_vector(rho))

    # Case 4: super(super). Should raise TypeError.
    with expect_exception(TypeError):
        S(S)
Esempio n. 7
0
def test_call():
    """
    Test Qobj: Call
    """
    # Make test objects.
    psi = rand_ket(3)
    rho = rand_dm_ginibre(3)
    U = rand_unitary(3)
    S = rand_super_bcsz(3)

    # Case 0: oper(ket).
    assert U(psi) == U * psi

    # Case 1: oper(oper). Should raise TypeError.
    with expect_exception(TypeError):
        U(rho)

    # Case 2: super(ket).
    assert S(psi) == vector_to_operator(S * operator_to_vector(ket2dm(psi)))

    # Case 3: super(oper).
    assert S(rho) == vector_to_operator(S * operator_to_vector(rho))

    # Case 4: super(super). Should raise TypeError.
    with expect_exception(TypeError):
        S(S)
Esempio n. 8
0
def test_rand_dm_ginibre_rank():
    """
    Random Qobjs: Ginibre-random density ops have correct rank.
    """
    rho = rand_dm_ginibre(5, rank=3)

    rank = sum([abs(E) >= 1e-10 for E in rho.eigenenergies()])
    assert_(rank == 3)
Esempio n. 9
0
def test_fidelity_bounded_puremixed(tol=1e-7):
    """
    Metrics: Fidelity of pure states against mixed states within [0, 1].
    """
    for _ in range(10):
        psi = rand_ket_haar(11)
        sigma = rand_dm_ginibre(11)
        F = fidelity(psi, sigma)
        assert_(-tol <= F <= 1 + tol)
Esempio n. 10
0
def test_fidelity_bounded_puremixed(tol=1e-7):
    """
    Metrics: Fidelity of pure states against mixed states within [0, 1].
    """
    for _ in range(10):
        psi = rand_ket_haar(11)
        sigma = rand_dm_ginibre(11)
        F = fidelity(psi, sigma)
        assert_(-tol <= F <= 1 + tol)
Esempio n. 11
0
    def test_stinespring_agrees(self, thresh=1e-10):
        """
        Stinespring: Partial Tr over pair agrees w/ supermatrix.
        """
        def case(map, state):
            S = to_super(map)
            A, B = to_stinespring(map)

            q1 = vector_to_operator(S * operator_to_vector(state))
            # FIXME: problem if Kraus index is implicitly
            #        ptraced!
            q2 = (A * state * B.dag()).ptrace((0, ))

            assert_((q1 - q2).norm('tr') <= thresh)

        for idx in range(4):
            case(rand_super_bcsz(2), rand_dm_ginibre(2))
Esempio n. 12
0
    def test_stinespring_agrees(self, dimension):
        """
        Stinespring: Partial Tr over pair agrees w/ supermatrix.
        """

        map = rand_super_bcsz(dimension)
        state = rand_dm_ginibre(dimension)

        S = to_super(map)
        A, B = to_stinespring(map)

        q1 = vector_to_operator(S * operator_to_vector(state))
        # FIXME: problem if Kraus index is implicitly
        #        ptraced!
        q2 = (A * state * B.dag()).ptrace((0, ))

        assert (q1 - q2).norm('tr') <= tol
Esempio n. 13
0
    def test_stinespring_agrees(self, thresh=1e-10):
        """
        Stinespring: Partial Tr over pair agrees w/ supermatrix.
        """
        def case(map, state):
            S = to_super(map)
            A, B = to_stinespring(map)

            q1 = vector_to_operator(
                S * operator_to_vector(state)
            )
            # FIXME: problem if Kraus index is implicitly
            #        ptraced!
            q2 = (A * state * B.dag()).ptrace((0,))

            assert_((q1 - q2).norm('tr') <= thresh)

        for idx in range(4):
            yield case, rand_super_bcsz(2), rand_dm_ginibre(2)