class_docstr: Callback for stopping the :code:`minimize` method before the budget is
  fully used.
  
  Parameters
  ----------
  stopping_criterion: func(optimizer) -> bool
      function that takes the current optimizer as input and returns True
      if the minimization must be stopped
  
  Note
  ----
  This callback must be register on the "ask" method only.
  
  Example
  -------
  In the following code, the :code:`minimize` method will be stopped at the 4th "ask"
  
  >>> early_stopping = ng.callbacks.EarlyStopping(lambda opt: opt.num_ask > 3)
  >>> optimizer.register_callback("ask", early_stopping)
  >>> optimizer.minimize(_func, verbosity=2)
  
  A couple other options (equivalent in case of non-noisy optimization) for stopping
  if the loss is below 12:
  
  >>> early_stopping = ng.callbacks.EarlyStopping(lambda opt: opt.recommend().loss < 12)
  >>> early_stopping = ng.callbacks.EarlyStopping(lambda opt: opt.current_bests["minimum"].mean < 12)
code: def __call__(
      self, optimizer: base.Optimizer, *args: tp.Any, **kwargs: tp.Any
  ) -> None:
      if args or kwargs:
          raise errors.NevergradRuntimeError(
              "EarlyStopping must be registered on ask method"
          )
      if self.stopping_criterion(optimizer):
          raise errors.NevergradEarlyStopping(
              "Early stopping criterion is reached"
          )
  
imports: import json
  import time
  import warnings
  import inspect
  import datetime
  import logging
  from pathlib import Path
  import numpy
  import nevergrad.common.typing
  from nevergrad.common import errors
  from nevergrad.parametrization import parameter
  from nevergrad.parametrization import helpers
  from .None import base
label_desc: Use image node_id 2 for calling the EarlyStopping obj's underlying member method code with example usage: obj.__call__(optimizer) without return types