def METHOD_NAME(self, x: np.ndarray, grad: np.ndarray) -> float:
    """Execute the objective function in the form required by NLOpt."""
    # Cache f(x) so we do not need to recalculate it if we're using
    # an approximate gradient
    self.f0 = self.f(x)
    if grad.size > 0:
        grad[:] = self.df(x)
    return self.f0