Пример #1
0
        def case(qobj):
            qobj = to_chi(qobj)
            rt_qobj = to_chi(to_choi(qobj))

            assert_almost_equal(rt_qobj.data.toarray(), qobj.data.toarray())
            assert_equal(rt_qobj.type, qobj.type)
            assert_equal(rt_qobj.dims, qobj.dims)
Пример #2
0
        def case(qobj):
            qobj = to_chi(qobj)
            rt_qobj = to_chi(to_choi(qobj))

            assert_almost_equal(rt_qobj.data.toarray(), qobj.data.toarray())
            assert_equal(rt_qobj.type, qobj.type)
            assert_equal(rt_qobj.dims, qobj.dims)
Пример #3
0
    def test_chi_choi_roundtrip(self, dimension):

        superop = rand_super_bcsz(dimension)
        superop = to_chi(superop)
        rt_superop = to_chi(to_choi(superop))
        dif = norm(rt_superop - superop)

        assert dif == pytest.approx(0, abs=1e-7)
        assert rt_superop.type == superop.type
        assert rt_superop.dims == superop.dims
Пример #4
0
def test_dag_preserves_superrep():
    """
    Checks that dag() preserves superrep.
    """
    def case(qobj):
        orig_superrep = qobj.superrep
        assert_equal(qobj.dag().superrep, orig_superrep)

    for dim in (2, 4, 8):
        qobj = rand_super_bcsz(dim)
        yield case, to_super(qobj)
        # These two shouldn't even do anything, since qobj
        # is Hermicity-preserving.
        yield case, to_choi(qobj)
        yield case, to_chi(qobj)
Пример #5
0
 def case(S, chi_expected, silent=True):
     chi_actual = to_chi(S)
     chiq = Qobj(chi_expected, dims=[[[2], [2]], [[2], [2]]], superrep='chi')
     if not silent:
         print(chi_actual)
         print(chi_expected)
     assert_almost_equal((chi_actual - chiq).norm('tr'), 0)
Пример #6
0
 def case(S, chi_expected, silent=True):
     chi_actual = to_chi(S)
     chiq = Qobj(chi_expected, dims=[[[2], [2]], [[2], [2]]], superrep='chi')
     if not silent:
         print(chi_actual)
         print(chi_expected)
     assert_almost_equal((chi_actual - chiq).norm('tr'), 0)
Пример #7
0
 def test_chi_known(self, superop, chi_expected):
     """
     Superoperator: Chi-matrix for known cases is correct.
     """
     chi_actual = to_chi(superop)
     chiq = Qobj(
         chi_expected,
         dims=[[[2], [2]], [[2], [2]]],
         superrep='chi',
     )
     assert (chi_actual - chiq).norm() < tol
Пример #8
0
def test_dag_preserves_superrep():
    """
    Checks that dag() preserves superrep.
    """

    def case(qobj):
        orig_superrep = qobj.superrep
        assert_equal(qobj.dag().superrep, orig_superrep)

    for dim in (2, 4, 8):
        qobj = rand_super_bcsz(dim)
        yield case, to_super(qobj)
        # These two shouldn't even do anything, since qobj
        # is Hermicity-preserving.
        yield case, to_choi(qobj)
        yield case, to_chi(qobj)
Пример #9
0
    def test_SuperChoiChiSuper(self):
        """
        Superoperator: Converting two-qubit superoperator through
        Choi and chi representations goes back to right superoperator.
        """
        superoperator = super_tensor(rand_super(2), rand_super(2))

        choi_matrix = to_choi(superoperator)
        chi_matrix = to_chi(choi_matrix)
        test_supe = to_super(chi_matrix)

        # Assert both that the result is close to expected, and has the right
        # type.
        assert_((test_supe - superoperator).norm() < tol)
        assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
        assert_(chi_matrix.type == "super" and chi_matrix.superrep == "chi")
        assert_(test_supe.type == "super" and test_supe.superrep == "super")
Пример #10
0
    def test_SuperChoiChiSuper(self):
        """
        Superoperator: Converting two-qubit superoperator through
        Choi and chi representations goes back to right superoperator.
        """
        superoperator = super_tensor(rand_super(2), rand_super(2))

        choi_matrix = to_choi(superoperator)
        chi_matrix = to_chi(choi_matrix)
        test_supe = to_super(chi_matrix)

        # Assert both that the result is close to expected, and has the right
        # type.
        assert_((test_supe - superoperator).norm() < tol)
        assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
        assert_(chi_matrix.type == "super" and chi_matrix.superrep == "chi")
        assert_(test_supe.type == "super" and test_supe.superrep == "super")