def __wizard(rho, epsilon=None):
    '\n    Returns the nearest positive semidefinite operator to an operator.\n\n    This method is based on reference [1]. It constrains positivity\n    by setting negative eigenvalues to zero and rescaling the positive\n    eigenvalues.\n\n    Args:\n        rho (array_like): the input operator.\n        epsilon(float or None): threshold (>=0) for truncating small\n            eigenvalues values to zero.\n\n    Returns:\n        numpy.array: A positive semidefinite numpy array.\n    '
    if (epsilon is None):
        epsilon = 0.0
    dim = len(rho)
    rho_wizard = np.zeros([dim, dim])
    (v, w) = np.linalg.eigh(rho)
    for j in range(dim):
        if (v[j] < epsilon):
            tmp = v[j]
            v[j] = 0.0
            x = 0.0
            for k in range((j + 1), dim):
                x += (tmp / (dim - (j + 1)))
                v[k] = (v[k] + (tmp / (dim - (j + 1))))
    for j in range(dim):
        rho_wizard = (rho_wizard + (v[j] * outer(w[:, j])))
    return rho_wizard
Returns the nearest positive semidefinite operator to an operator.

This method is based on reference [1]. It constrains positivity
by setting negative eigenvalues to zero and rescaling the positive
eigenvalues.

Args:
    rho (array_like): the input operator.
    epsilon(float or None): threshold (>=0) for truncating small
        eigenvalues values to zero.

Returns:
    numpy.array: A positive semidefinite numpy array.
def __wizard(rho, epsilon=None):
    '\n    Returns the nearest positive semidefinite operator to an operator.\n\n    This method is based on reference [1]. It constrains positivity\n    by setting negative eigenvalues to zero and rescaling the positive\n    eigenvalues.\n\n    Args:\n        rho (array_like): the input operator.\n        epsilon(float or None): threshold (>=0) for truncating small\n            eigenvalues values to zero.\n\n    Returns:\n        numpy.array: A positive semidefinite numpy array.\n    '
    if (epsilon is None):
        epsilon = 0.0
    dim = len(rho)
    rho_wizard = np.zeros([dim, dim])
    (v, w) = np.linalg.eigh(rho)
    for j in range(dim):
        if (v[j] < epsilon):
            tmp = v[j]
            v[j] = 0.0
            x = 0.0
            for k in range((j + 1), dim):
                x += (tmp / (dim - (j + 1)))
                v[k] = (v[k] + (tmp / (dim - (j + 1))))
    for j in range(dim):
        rho_wizard = (rho_wizard + (v[j] * outer(w[:, j])))
    return rho_wizard