class_docstr: A Global Stopping Strategy which recommends stopping optimization if there
  is no significant improvement over recent iterations.
  
  This stopping strategy recommends stopping if there is no significant improvement
  over the past `window_size` trials, among those that are feasible
  (satisfying constraints). The meaning of a "significant"
  improvement differs between single-objective and multi-objective optimizations.
  For single-objective optimizations, improvement is as a fraction of the
  interquartile range (IQR) of the objective values seen so far. For
  multi-objective optimizations (MOO), improvement is as a fraction of the hypervolume
  obtained `window_size` iterations ago.
docstr: Check if the objective has improved significantly in the past
  "window_size" iterations.
  
  For single-objective optimization experiments, it will call
  _should_stop_single_objective() and for MOO experiments, it will call
  _should_stop_moo(). Before making either of these calls, this function carries
  out some sanity checks to handle obvious/invalid cases. For more detail
  on what it means to "significantly" improve, see the class docstring.
  
  Args:
      experiment: The experiment to apply the strategy on.
      trial_to_check: The trial in the experiment at which we want to check
          for stopping. If None, we check at the latest trial.
      objective_thresholds: Custom objective thresholds to use as reference pooint
          when computing hv of the pareto front against. This is used only in the
          MOO setting. If not specified, the objective thresholds on the
          experiment's optimization config will be used for the purpose.
  
  Returns:
      A Tuple with a boolean determining whether the optimization should stop,
      and a str declaring the reason for stopping.
docstr_tok: ["Check","if","the","objective","has","improved","significantly","in","the","past","''","window_size","''","iterations",".","For","single-objective","optimization","experiments",",","it","will","call","_should_stop_single_objective","(",")","and","for","MOO","experiments",",","it","will","call","_should_stop_moo","(",")",".","Before","making","either","of","these","calls",",","this","function","carries","out","some","sanity","checks","to","handle","obvious\/invalid","cases",".","For","more","detail","on","what","it","means","to","``","significantly","''","improve",",","see","the","class","docstring",".","Args",":","experiment",":","The","experiment","to","apply","the","strategy","on",".","trial_to_check",":","The","trial","in","the","experiment","at","which","we","want","to","check","for","stopping",".","If","None",",","we","check","at","the","latest","trial",".","objective_thresholds",":","Custom","objective","thresholds","to","use","as","reference","pooint","when","computing","hv","of","the","pareto","front","against",".","This","is","used","only","in","the","MOO","setting",".","If","not","specified",",","the","objective","thresholds","on","the","experiment","'s","optimization","config","will","be","used","for","the","purpose",".","Returns",":","A","Tuple","with","a","boolean","determining","whether","the","optimization","should","stop",",","and","a","str","declaring","the","reason","for","stopping","."]
code: def _should_stop_optimization(
      self,
      experiment: Experiment,
      trial_to_check: Optional[int] = None,
      objective_thresholds: Optional[List[ObjectiveThreshold]] = None,
      **kwargs: Dict[str, Any],
  ) -> Tuple[bool, str]:
      """
      Check if the objective has improved significantly in the past
      "window_size" iterations.
  
      For single-objective optimization experiments, it will call
      _should_stop_single_objective() and for MOO experiments, it will call
      _should_stop_moo(). Before making either of these calls, this function carries
      out some sanity checks to handle obvious/invalid cases. For more detail
      on what it means to "significantly" improve, see the class docstring.
  
      Args:
          experiment: The experiment to apply the strategy on.
          trial_to_check: The trial in the experiment at which we want to check
              for stopping. If None, we check at the latest trial.
          objective_thresholds: Custom objective thresholds to use as reference pooint
              when computing hv of the pareto front against. This is used only in the
              MOO setting. If not specified, the objective thresholds on the
              experiment's optimization config will be used for the purpose.
  
      Returns:
          A Tuple with a boolean determining whether the optimization should stop,
          and a str declaring the reason for stopping.
      """
  
      max_completed_trial = max(
          experiment.trial_indices_by_status[TrialStatus.COMPLETED]
      )
  
      if trial_to_check is None:
          trial_to_check = max_completed_trial
      elif trial_to_check > max_completed_trial:
          raise ValueError(
              "trial_to_check is larger than the total number of "
              f"trials (={max_completed_trial})."
          )
  
      # Only counting the trials up to trial_to_check.
      num_completed_trials = sum(
          index <= trial_to_check
          for index in experiment.trial_indices_by_status[
              TrialStatus.COMPLETED
          ]
      )
      min_required_trials = max(self.min_trials, self.window_size)
      if num_completed_trials < min_required_trials:
          stop = False
          message = (
              "There are not enough completed trials to make a stopping decision "
              f"(completed: {num_completed_trials}, required: {min_required_trials})."
          )
          return stop, message
  
      if isinstance(
          experiment.optimization_config,
          MultiObjectiveOptimizationConfig,
      ):
          return self._should_stop_moo(
              experiment=experiment,
              trial_to_check=trial_to_check,
              objective_thresholds=objective_thresholds,
          )
      else:
          return self._should_stop_single_objective(
              experiment=experiment, trial_to_check=trial_to_check
          )
  
imports: from logging import Logger
  from typing import Any, Dict, List, Optional, Tuple
  import numpy
  from ax.core.base_trial import BaseTrial, TrialStatus
  from ax.core.data import Data
  from ax.core.experiment import Experiment
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig, OptimizationConfig
  from ax.core.outcome_constraint import ObjectiveThreshold
  from ax.core.trial import Trial
  from ax.core.types import ComparisonOp
  from ax.global_stopping.strategies.base import BaseGlobalStoppingStrategy
  from ax.modelbridge.modelbridge_utils import observed_hypervolume
  from ax.plot.pareto_utils import get_tensor_converter_model
  from ax.service.utils.best_point import fill_missing_thresholds_from_nadir
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast, not_none
label_desc: Use image node_id 2 for calling the ImprovementGlobalStoppingStrategy obj's underlying member method code with example usage: obj._should_stop_optimization(experiment, trial_to_check, objective_thresholds) and returns: stop,  message, self, self