def process_fidelity(channel1, channel2, require_cptp=True):
<EOL>is_cptp1 = None<EOL>is_cptp2 = None<EOL>if isinstance(channel1, (list, np.ndarray)):<EOL><INDENT>channel1 = Operator(channel1)<EOL>if require_cptp:<EOL><INDENT>is_cptp1 = channel1.is_unitary()<EOL><DEDENT><DEDENT>if isinstance(channel2, (list, np.ndarray)):<EOL><INDENT>channel2 = Operator(channel2)<EOL>if require_cptp:<EOL><INDENT>is_cptp2 = channel2.is_unitary()<EOL><DEDENT><DEDENT>s1 = SuperOp(channel1)<EOL>s2 = SuperOp(channel2)<EOL>if require_cptp:<EOL><INDENT>if is_cptp1 is None:<EOL><INDENT>is_cptp1 = s1.is_cptp()<EOL><DEDENT>if not is_cptp1:<EOL><INDENT>raise QiskitError('<STR_LIT>')<EOL><DEDENT>if is_cptp2 is None:<EOL><INDENT>is_cptp2 = s2.is_cptp()<EOL><DEDENT>if not is_cptp2:<EOL><INDENT>raise QiskitError('<STR_LIT>')<EOL><DEDENT><DEDENT>input_dim1, output_dim1 = s1.dim<EOL>input_dim2, output_dim2 = s2.dim<EOL>if input_dim1 != output_dim1 or input_dim2 != output_dim2:<EOL><INDENT>raise QiskitError('<STR_LIT>')<EOL><DEDENT>if input_dim1 != input_dim2:<EOL><INDENT>raise QiskitError('<STR_LIT>')<EOL><DEDENT>fidelity = np.trace(s1.compose(s2.adjoint()).data) / (input_dim1 ** <NUM_LIT:2>)<EOL>return fidelity<EOL>
Return the process fidelity between two quantum channels.

    This is given by

        F_p(E1, E2) = Tr[S2^dagger.S1])/dim^2

    where S1 and S2 are the SuperOp matrices for channels E1 and E2,
    and dim is the dimension of the input output statespace.

    Args:
        channel1 (QuantumChannel or matrix): a quantum channel or unitary matrix.
        channel2 (QuantumChannel or matrix): a quantum channel or unitary matrix.
        require_cptp (bool): require input channels to be CPTP [Default: True].

    Returns:
        array_like: The state fidelity F(state1, state2).

    Raises:
        QiskitError: if inputs channels do not have the same dimensions,
        have different input and output dimensions, or are not CPTP with
        `require_cptp=True`.