Quanlse/Utils/Functions.py
def globalPhase(U: ndarray) -> float:
    r"""
    Compute the global phase of a 2*2 unitary matrix.
    Each 2*2 unitary matrix can be equivalently characterized as:

    :math:`U = e^{i\alpha} R_z(\phi) R_y(\theta) R_z(\lambda)`

    We aim to compute the global phase `\alpha`.
    See also Theorem 4.1 in `Nielsen & Chuang`'s book.

    :param U: the matrix representation of the 2*2 unitary
    :return: the global phase of the unitary matrix
    """
    # Notice that the determinant of the unitary is given by e^{2i\alpha}
    coe = linalg.det(U) ** (-0.5)
    alpha = - angle(coe)
    return alpha
r"""
    Compute the global phase of a 2*2 unitary matrix.
    Each 2*2 unitary matrix can be equivalently characterized as:

    :math:`U = e^{i\alpha} R_z(\phi) R_y(\theta) R_z(\lambda)`

    We aim to compute the global phase `\alpha`.
    See also Theorem 4.1 in `Nielsen & Chuang`'s book.

    :param U: the matrix representation of the 2*2 unitary
    :return: the global phase of the unitary matrix
    
r"""
Compute the global phase of a 2*2 unitary matrix.
Each 2*2 unitary matrix can be equivalently characterized as.
r " " " Compute the global phase of a 2 * 2 unitary matrix . Each 2 * 2 unitary matrix can be equivalently characterized as .
def globalPhase(U: ndarray) -> float:
    coe = linalg.det(U) ** (-0.5)
    alpha = - angle(coe)
    return alpha
def globalPhase ( U : ndarray ) -> float : coe = linalg . det ( U ) ** ( - 0.5 ) alpha = - angle ( coe ) return alpha
r"""
Compute the global phase of a 2*2 unitary matrix.
r " " " Compute the global phase of a 2 * 2 unitary matrix .
r"""
    Compute the global phase of a 2*2 unitary matrix.
    Each 2*2 unitary matrix can be equivalently characterized as:

    :math:`U = e^{i\alpha} R_z(\phi) R_y(\theta) R_z(\lambda)`

    We aim to compute the global phase `\alpha`.
    See also Theorem 4.1 in `Nielsen & Chuang`'s book.

    :param U: the matrix representation of the 2*2 unitary
    :return: the global phase of the unitary matrix
    """ # Notice that the determinant of the unitary is given by e^{2i\alpha}
the global phase of the unitary matrix
the global phase of the unitary matrix
U
ndarray
the matrix representation of the 2*2 unitary
the matrix representation of the 2 * 2 unitary
math
`U = e^{i\alpha} R_z(\phi) R_y(\theta) R_z(\lambda)`
We aim to compute the global phase `\alpha`.
See also Theorem 4.1 in `Nielsen & Chuang`'s book.
` U = e^ { i \ alpha } R_z ( \ phi ) R_y ( \ theta ) R_z ( \ lambda ) ` We aim to compute the global phase ` \ alpha ` . See also Theorem 4 . 1 in ` Nielsen & Chuang ` ' s book .