Example #1
0
def unitary_infid(U_dict: dict, gate: str, index, dims, proj: bool):
    """
    Unitary overlap between ideal and actually performed gate.

    Parameters
    ----------
    U_dict : dict
        Contains unitary representations of the gates, identified by a key.
    index : int
        Index of the qubit(s) in the Hilbert space to be evaluated
    gate : str
        One of the keys of U_dict, selects the gate to be evaluated
    dims : list
        List of dimensions of qubits
    proj : boolean
        Project to computational subspace

    Returns
    -------
    tf.float
        Unitary fidelity.
    """
    U = U_dict[gate]
    projection = "fulluni"
    fid_lvls = np.prod([dims[i] for i in index])
    if proj:
        projection = "wzeros"
        fid_lvls = 2**len(index)
    U_ideal = tf.constant(perfect_gate(gate, index, dims, projection),
                          dtype=tf.complex128)
    infid = 1 - tf_unitary_overlap(U, U_ideal, lvls=fid_lvls)
    return infid
Example #2
0
def unitary_infid(ideal: np.ndarray,
                  actual: tf.Tensor,
                  index: List[int] = None,
                  dims=None) -> tf.Tensor:
    """
    Unitary overlap between ideal and actually performed gate.

    Parameters
    ----------
    ideal : np.ndarray
        Ideal or goal unitary representation of the gate.
    actual : np.ndarray
        Actual, physical unitary representation of the gate.
    index : List[int]
        Index of the qubit(s) in the Hilbert space to be evaluated
    gate : str
        One of the keys of propagators, selects the gate to be evaluated
    dims : list
        List of dimensions of qubits

    Returns
    -------
    tf.float
        Unitary fidelity.
    """
    if index is None:
        index = list(range(len(dims)))
    actual_comp = tf_project_to_comp(actual, dims=dims, index=index)
    fid_lvls = 2**len(index)
    infid = 1 - tf_unitary_overlap(actual_comp, ideal, lvls=fid_lvls)
    return infid
Example #3
0
def test_unitary_overlap(args: Tuple[List[int], List[int], List[int]]) -> None:
    """test unitary overlap function from tf_utils

    Parameters
    ----------
    args : Tuple[List[int], List[int], List[int]]
        Matrix A, Matrix B and Expected Overlap
    """
    x, x_noisy, over = args
    pauli_x = tf.constant(x)
    pauli_x_noisy = tf.constant(x_noisy)

    overlap = tf_unitary_overlap(pauli_x, pauli_x_noisy)
    assert overlap.numpy() > over