Optimise ML distance between two partials. min and max set brackets

def brent_optimise(node1, node2, min_brlen=0.001, max_brlen=10, verbose=False):
    """
    Optimise ML distance between two partials. min and max set brackets
    """
    from scipy.optimize import minimize_scalar
    wrapper = BranchLengthOptimiser(node1, node2, (min_brlen + max_brlen) / 2.)
    n = minimize_scalar(lambda x: -wrapper(x)[0], method='brent', bracket=(min_brlen, max_brlen))['x']
    if verbose:
        logger.info(wrapper)
    if n < min_brlen:
        n = min_brlen
        wrapper(n)
    return n, -1 / wrapper.get_d2lnl(n)