def METHOD_NAME(fock, nphys, nelec, occupancy=2):
    ''' Finds a chemical potential which best agrees with the number
        of physical electrons and abides by the Aufbau principal via
        a binary search.
    Args:
        fock : 2D array or tuple of arrays
            Fock matrix to diagonalise, may be the physical Fock matrix
            or extended Fock matrix. Can also be the output of
            :func:`np.linalg.eigh` for this matrix, i.e. a tuple of the
            eigenvalues and eigenvectors.
        nphys : int
            Number of physical degrees of freedom
        nelec : int
            Number of physical electrons
    Kwargs:
        occupancy : int
            Occupancy of the states, i.e. 2 for RHF and 1 for UHF.
            Default 2.
    Returns:
        chemical potential, and the error in the number of electrons
    '''
    if isinstance(fock, tuple):
        w, v = fock
    else:
        w, v = np.linalg.eigh(fock)
    nmo = v.shape[-1]
    sum0 = sum1 = 0.0
    for i in range(nmo):
        n = occupancy * np.dot(v[:nphys,i].conj().T, v[:nphys,i]).real
        sum0, sum1 = sum1, sum1 + n
        if i > 0:
            if sum0 <= nelec and nelec <= sum1:
                break
    if abs(sum0 - nelec) < abs(sum1 - nelec):
        homo = i-1
        error = nelec - sum0
    else:
        homo = i
        error = nelec - sum1
    lumo = homo+1
    chempot = 0.5 * (w[homo] + w[lumo])
    return chempot, error