class_docstr: Implements the strategy of stopping a trial if its performance
  doesn't reach a pre-specified threshold by a certain progression.
class_docstr_tok: ["Implements","the","strategy","of","stopping","a","trial","if","its","performance","does","n't","reach","a","pre-specified","threshold","by","a","certain","progression","."]
docstr: Stop a trial if its performance doesn't reach a pre-specified threshold
  by `min_progression`.
  
  Args:
      trial_index: Indices of candidate trial to stop early.
      experiment: Experiment that contains the trials and other contextual data.
      df: Dataframe of partial results for the objective metric.
      map_key: Name of the column of the dataset that indicates progression.
      minimize: Whether objective value is being minimized.
  
  Returns:
      A tuple `(should_stop, reason)`, where `should_stop` is `True` iff the
      trial should be stopped, and `reason` is an (optional) string providing
      information on why the trial should or should not be stopped.
docstr_tok: ["Stop","a","trial","if","its","performance","does","n't","reach","a","pre-specified","threshold","by","`","min_progression","`",".","Args",":","trial_index",":","Indices","of","candidate","trial","to","stop","early",".","experiment",":","Experiment","that","contains","the","trials","and","other","contextual","data",".","df",":","Dataframe","of","partial","results","for","the","objective","metric",".","map_key",":","Name","of","the","column","of","the","dataset","that","indicates","progression",".","minimize",":","Whether","objective","value","is","being","minimized",".","Returns",":","A","tuple","`","(","should_stop",",","reason",")","`",",","where","`","should_stop","`","is","`","True","`","iff","the","trial","should","be","stopped",",","and","`","reason","`","is","an","(","optional",")","string","providing","information","on","why","the","trial","should","or","should","not","be","stopped","."]
code: def should_stop_trial_early(
      self,
      trial_index: int,
      experiment: Experiment,
      df: pd.DataFrame,
      map_key: str,
      minimize: bool,
  ) -> Tuple[bool, Optional[str]]:
      """Stop a trial if its performance doesn't reach a pre-specified threshold
      by `min_progression`.
  
      Args:
          trial_index: Indices of candidate trial to stop early.
          experiment: Experiment that contains the trials and other contextual data.
          df: Dataframe of partial results for the objective metric.
          map_key: Name of the column of the dataset that indicates progression.
          minimize: Whether objective value is being minimized.
  
      Returns:
          A tuple `(should_stop, reason)`, where `should_stop` is `True` iff the
          trial should be stopped, and `reason` is an (optional) string providing
          information on why the trial should or should not be stopped.
      """
      logger.info(
          f"Considering trial {trial_index} for early stopping."
      )
  
      stopping_eligible, reason = self.is_eligible(
          trial_index=trial_index,
          experiment=experiment,
          df=df,
          map_key=map_key,
      )
      if not stopping_eligible:
          return False, reason
  
      # threshold early stopping logic
      df_trial = df[df["trial_index"] == trial_index].dropna(
          subset=["mean"]
      )
      trial_last_prog = df_trial[map_key].max()
      data_last_prog = df_trial[df_trial[map_key] == trial_last_prog][
          "mean"
      ].iloc[0]
      logger.info(
          "Early stopping objective at last progression is:\n"
          f"{data_last_prog}."
      )
      should_early_stop = (
          data_last_prog > self.metric_threshold
          if minimize
          else data_last_prog < self.metric_threshold
      )
      comp = "worse" if should_early_stop else "better"
      reason = (
          f"Trial objective value {data_last_prog} is {comp} than "
          f"the metric threshold {self.metric_threshold:}."
      )
      logger.info(
          f"Early stopping decision for {trial_index}: {should_early_stop}. "
          f"Reason: {reason}"
      )
      return should_early_stop, reason
  
file_path: Ax/ax/early_stopping/strategies/threshold.py
imports: from logging import Logger
  from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
  import pandas
  from ax.core.experiment import Experiment
  from ax.early_stopping.strategies.base import BaseEarlyStoppingStrategy
  from ax.exceptions.core import UnsupportedError
  from ax.utils.common.logger import get_logger
label_desc: Use image node_id 3 for calling the ThresholdEarlyStoppingStrategy obj's underlying member method code with example usage: obj.should_stop_trial_early(trial_index, experiment, df, map_key, minimize) and returns: should_early_stop,  reason, False,  reason