class_docstr: Fail when at least num_trials exist and num_finished have finished.
class_docstr_tok: ["Fail","when","at","least","num_trials","exist","and","num_finished","have","finished","."]
code: def on_step_begin(self, iteration: int, trials: list, **info):
      if self.fail_at and iteration >= self.fail_at:
          print(
              "Actually failing after delay:",
              [(t.status, t.last_result.get("it")) for t in trials],
          )
          raise RuntimeError("Failing")
  
      if len(trials) < self.num_trials:
          return
  
      if (
          len(
              [
                  t
                  for t in trials
                  if t.status in [Trial.TERMINATED, Trial.ERROR]
              ]
          )
          >= self.num_finished
      ):
          self.fail_at = iteration + self.delay
          print(
              f"Triggering fail in {self.delay} iterations:",
              [(t.status, t.last_result.get("it")) for t in trials],
          )
      else:
          print(
              "Not failing:",
              [(t.status, t.last_result.get("it")) for t in trials],
          )
  
imports: import json
  import logging
  import os
  import shutil
  import time
  import unittest
  import pytest
  import ray
  from ray import train, tune
  import ray.cloudpickle
  from ray.train import Checkpoint, CheckpointConfig, FailureConfig, RunConfig, ScalingConfig
  from ray.air._internal.uri_utils import URI
  from ray.train.data_parallel_trainer import DataParallelTrainer
  from ray.train._internal.storage import get_fs_and_path, _download_from_fs_path, _upload_to_fs_path
  from ray.tune import Callback, Trainable
  from ray.tune.analysis import ExperimentAnalysis
  from ray.tune.execution.experiment_state import _find_newest_experiment_checkpoint
  from ray.tune.experiment import Trial
  from ray.tune.result_grid import ResultGrid
  from ray.tune.schedulers.async_hyperband import ASHAScheduler
  from ray.tune.search.optuna import OptunaSearch
  from ray.tune.tune_config import TuneConfig
  from ray.tune.tuner import Tuner
  from ray.train.tests.util import create_dict_checkpoint, load_dict_checkpoint
label_desc: Use image node_id 2 for calling the _FailOnStats obj's underlying member method code with example usage: obj.on_step_begin(iteration, trials) without return types