Exemple #1
0
def average_gate_fidelity(oper, target=None):
    """
    Given a Qobj representing the supermatrix form of a map, returns the
    average gate fidelity (pseudo-metric) of that map.

    Parameters
    ----------
    A : Qobj
        Quantum object representing a superoperator.
    target : Qobj
        Quantum object representing the target unitary; the inverse
        is applied before evaluating the fidelity.

    Returns
    -------
    fid : float
        Fidelity pseudo-metric between A and the identity superoperator,
        or between A and the target superunitary.
    """
    kraus_form = to_kraus(oper)
    d = kraus_form[0].shape[0]

    if kraus_form[0].shape[1] != d:
        return TypeError("Average gate fidelity only implemented for square "
                         "superoperators.")

    if target is None:
        return (d + np.sum([np.abs(A_k.tr())**2
                        for A_k in kraus_form])) / (d**2 + d)
    else:
        return (d + np.sum([np.abs((A_k * target.dag()).tr())**2
                        for A_k in kraus_form])) / (d**2 + d)
Exemple #2
0
def average_gate_fidelity(oper, target=None):
    """
    Given a Qobj representing the supermatrix form of a map, returns the
    average gate fidelity (pseudo-metric) of that map.

    Parameters
    ----------
    A : Qobj
        Quantum object representing a superoperator.
    target : Qobj
        Quantum object representing the target unitary; the inverse
        is applied before evaluating the fidelity.

    Returns
    -------
    fid : float
        Fidelity pseudo-metric between A and the identity superoperator,
        or between A and the target superunitary.
    """
    kraus_form = to_kraus(oper)
    d = kraus_form[0].shape[0]

    if kraus_form[0].shape[1] != d:
        return TypeError("Average gate fidelity only implemented for square "
                         "superoperators.")

    if target is None:
        return (d + np.sum([np.abs(A_k.tr())**2
                        for A_k in kraus_form])) / (d**2 + d)
    else:
        return (d + np.sum([np.abs((A_k * target.dag()).tr())**2
                        for A_k in kraus_form])) / (d**2 + d)
Exemple #3
0
def average_gate_fidelity(oper):
    """
    Given a Qobj representing the supermatrix form of a map, returns the
    average gate fidelity (pseudo-metric) of that map.
    
    Parameters
    ----------
    A : Qobj
        Quantum object representing a superoperator.
        
    Returns
    -------
    fid : float
        Fidelity pseudo-metric between A and the identity superoperator.
    """
    kraus_form = to_kraus(oper)
    d = kraus_form[0].shape[0]
    
    if kraus_form[0].shape[1] != d:
        return TypeError("Average gate fielity only implemented for square "
            "superoperators.")
    
    return (
        d + np.sum([
            np.abs(A_k.tr())**2
            for A_k in kraus_form
        ])
    ) / (d**2 + d)
 def test_NeglectSmallKraus(self):
     """
     Superoperator: Convert Kraus to Choi matrix and back. Neglect tiny Kraus operators.
     """
     zero = asarray([[1], [0]], dtype=complex)
     one = asarray([[0], [1]], dtype=complex)
     zero_log = kron(kron(zero, zero), zero)
     one_log = kron(kron(one, one), one)
     # non-square Kraus operator (isometry)
     kraus = Qobj(zero_log @ zero.T + one_log @ one.T)
     super = sprepost(kraus, kraus.dag())
     # 1 non-zero Kraus operator the rest are zero
     sixteen_kraus_ops = to_kraus(super, tol=0.0)
     # default is tol=1e-9
     one_kraus_op = to_kraus(super)
     assert_(len(sixteen_kraus_ops) == 16 and len(one_kraus_op) == 1)
     assert_((one_kraus_op[0] - kraus).norm() < tol)
 def test_NonSquareKrausSuperChoi(self):
     """
     Superoperator: Convert non-square Kraus operator to Super + Choi matrix and back.
     """
     zero = asarray([[1], [0]], dtype=complex)
     one = asarray([[0], [1]], dtype=complex)
     zero_log = kron(kron(zero, zero), zero)
     one_log = kron(kron(one, one), one)
     # non-square Kraus operator (isometry)
     kraus = Qobj(zero_log @ zero.T + one_log @ one.T)
     super = sprepost(kraus, kraus.dag())
     choi = to_choi(super)
     op1 = to_kraus(super)
     op2 = to_kraus(choi)
     op3 = to_super(choi)
     assert_(choi.type == "super" and choi.superrep == "choi")
     assert_(super.type == "super" and super.superrep == "super")
     assert_((op1[0] - kraus).norm() < 1e-8)
     assert_((op2[0] - kraus).norm() < 1e-8)
     assert_((op3 - super).norm() < 1e-8)
    def test_ChoiKrausChoi(self, superoperator):
        """
        Superoperator: Convert superoperator to Choi matrix and back.
        """
        choi_matrix = to_choi(superoperator)
        kraus_ops = to_kraus(choi_matrix)
        test_choi = kraus_to_choi(kraus_ops)

        # Assert both that the result is close to expected, and has the right
        # type.
        assert (test_choi - choi_matrix).norm() < tol
        assert choi_matrix.type == "super" and choi_matrix.superrep == "choi"
        assert test_choi.type == "super" and test_choi.superrep == "choi"
    def test_ChoiKrausChoi(self):
        """
        Superoperator: Convert superoperator to Choi matrix and back.
        """
        superoperator = rand_super()
        choi_matrix = to_choi(superoperator)
        kraus_ops = to_kraus(choi_matrix)
        test_choi = kraus_to_choi(kraus_ops)

        # Assert both that the result is close to expected, and has the right
        # type.
        assert_((test_choi - choi_matrix).norm() < tol)
        assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
        assert_(test_choi.type == "super" and test_choi.superrep == "choi")
Exemple #8
0
 def test_ChoiKrausChoi(self):
     """
     Superoperator: Converting superoperator to Choi matrix and back.
     """
     superoperator = rand_super()
     choi_matrix = to_choi(superoperator)
     kraus_ops = to_kraus(choi_matrix)
     test_choi = kraus_to_choi(kraus_ops)
     
     # Assert both that the result is close to expected, and has the right
     # type.
     assert_((test_choi - choi_matrix).norm() < 1e-12)
     assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi")
     assert_(test_choi.type == "super" and test_choi.superrep == "choi")
Exemple #9
0
def average_gate_fidelity(oper):
    """
    Given a Qobj representing the supermatrix form of a map, returns the
    average gate fidelity (pseudo-metric) of that map.
    
    Parameters
    ----------
    A : Qobj
        Quantum object representing a superoperator.
        
    Returns
    -------
    fid : float
        Fidelity pseudo-metric between A and the identity superoperator.
    """
    kraus_form = to_kraus(oper)
    d = kraus_form[0].shape[0]

    if kraus_form[0].shape[1] != d:
        return TypeError("Average gate fielity only implemented for square "
                         "superoperators.")

    return (d + np.sum([np.abs(A_k.tr())**2
                        for A_k in kraus_form])) / (d**2 + d)