Hello,
I suggest to add to this stopper, on top of metric_threshold and mode (which stop per trial) also a global metric_threshold_exp and mode_exp (which will stop the whole experiment).
Sometimes it’s good to stop the whole tune process if a global minima (or close to that) was found.
Something similar with this:
class BestValueStopper(Stopper):
def __init__(self, target_value: int = 0, metric="", mode="", min_iterations=10):
self._target_value = target_value
self._metric = metric
self._mode = mode
self._min_iterations = min_iterations
self._results = []
self._should_stop = False
if mode == "min":
self._mode_op = np.less_equal
else:
self._mode_op = np.greater_equal
def __call__(self, trial_id, result):
self._results.append(trial_id)
if self._mode_op(result[self._metric], self._target_value) and len(self._results) >= self._min_iterations: #
self._should_stop = True
logger.info(
f"BestValueStopper should stop - iter {len(self._results)} - {result[self._metric]} / {self._target_value}"
)
return True
return self._should_stop
def stop_all(self):
return self._should_stop