Quanlse/Utils/Functions.py
def wigner(rho: ndarray, xRange: ndarray, yRange: ndarray):
    """
    Calculate the wigner function of density matrix using laguerre polynomial.

    :param rho: Input density matrix.
    :param xRange: The range of the X quadrature in the phase space.
    :param yRange: The range of the y quadrature in the phase space.
    """
    X, P = meshgrid(xRange, yRange)
    T = X ** 2 + P ** 2

    def _wignerLaguerre(_m, _n):
        """
        Return wigner function for state |n><m|
        """
        if _m == _n:
            poly = laguerre(_n)
            _w = ((-1) ** _n / pi) * exp(-T) * poly(2 * T)
        else:
            factor1 = sqrt(factorial(m) / factorial(n))
            factor2 = ((-1) ** m / pi) * (sqrt(2) * (X + 1j * P)) ** (n - m) * exp(-T)
            _w = factor1 * factor2 * genlaguerre(m, n - m)(2 * T)
        return _w
    W = zeros([len(xRange), len(yRange)], dtype=complex)
    # Add all the contribution
    dim = prod(rho.shape[0])
    for m in range(dim):
        wmn = real(rho[m, m] * _wignerLaguerre(m, m))
        W += wmn
        for n in range(m + 1, dim):
            wmn = real(rho[m, n] * _wignerLaguerre(m, n))
            W += 2 * wmn
    return W

    Calculate the wigner function of density matrix using laguerre polynomial.

    :param rho: Input density matrix.
    :param xRange: The range of the X quadrature in the phase space.
    :param yRange: The range of the y quadrature in the phase space.
    
Calculate the wigner function of density matrix using laguerre polynomial.
Calculate the wigner function of density matrix using laguerre polynomial .
def wigner(rho: ndarray, xRange: ndarray, yRange: ndarray):
    X, P = meshgrid(xRange, yRange)
    T = X ** 2 + P ** 2
    def _wignerLaguerre(_m, _n):
        if _m == _n:
            poly = laguerre(_n)
            _w = ((-1) ** _n / pi) * exp(-T) * poly(2 * T)
        else:
            factor1 = sqrt(factorial(m) / factorial(n))
            factor2 = ((-1) ** m / pi) * (sqrt(2) * (X + 1j * P)) ** (n - m) * exp(-T)
            _w = factor1 * factor2 * genlaguerre(m, n - m)(2 * T)
        return _w
    W = zeros([len(xRange), len(yRange)], dtype=complex)
    dim = prod(rho.shape[0])
    for m in range(dim):
        wmn = real(rho[m, m] * _wignerLaguerre(m, m))
        W += wmn
        for n in range(m + 1, dim):
            wmn = real(rho[m, n] * _wignerLaguerre(m, n))
            W += 2 * wmn
    return W
def wigner ( rho : ndarray , xRange : ndarray , yRange : ndarray ) : X , P = meshgrid ( xRange , yRange ) T = X ** 2 + P ** 2 def _wignerLaguerre ( _m , _n ) : """
        Return wigner function for state |n><m|
        """ if _m == _n : poly = laguerre ( _n ) _w = ( ( - 1 ) ** _n / pi ) * exp ( - T ) * poly ( 2 * T ) else : factor1 = sqrt ( factorial ( m ) / factorial ( n ) ) factor2 = ( ( - 1 ) ** m / pi ) * ( sqrt ( 2 ) * ( X + 1j * P ) ) ** ( n - m ) * exp ( - T ) _w = factor1 * factor2 * genlaguerre ( m , n - m ) ( 2 * T ) return _w W = zeros ( [ len ( xRange ) , len ( yRange ) ] , dtype = complex ) dim = prod ( rho . shape [ 0 ] ) for m in range ( dim ) : wmn = real ( rho [ m , m ] * _wignerLaguerre ( m , m ) ) W += wmn for n in range ( m + 1 , dim ) : wmn = real ( rho [ m , n ] * _wignerLaguerre ( m , n ) ) W += 2 * wmn return W
Calculate the wigner function of density matrix using laguerre polynomial.
Calculate the wigner function of density matrix using laguerre polynomial .
"""
    Calculate the wigner function of density matrix using laguerre polynomial.

    :param rho: Input density matrix.
    :param xRange: The range of the X quadrature in the phase space.
    :param yRange: The range of the y quadrature in the phase space.
    """ """
        Return wigner function for state |n><m|
        """ # Add all the contribution
rho
ndarray
Input density matrix.
Input density matrix .
xRange
ndarray
The range of the X quadrature in the phase space.
The range of the X quadrature in the phase space .
yRange
ndarray
The range of the y quadrature in the phase space.
The range of the y quadrature in the phase space .