code: def test_tuner_resume_errored_only(
      ray_start_2_cpus, tmpdir, monkeypatch
  ):
      """Not resuming unfinished trials (but only errored and pending) should work"""
      monkeypatch.setenv("TUNE_GLOBAL_CHECKPOINT_S", "0")
  
      # TODO(justinvyu): Same as above.
      monkeypatch.setenv("RAY_AIR_LOCAL_CACHE_DIR", str(tmpdir))
  
      fail_marker = tmpdir / "fail_marker"
      fail_marker.write_text("", encoding="utf-8")
  
      hang_marker = tmpdir / "hang_marker"
      hang_marker.write_text("", encoding="utf-8")
  
      tuner = Tuner(
          _train_fn_sometimes_failing,
          tune_config=TuneConfig(num_samples=1),
          run_config=RunConfig(
              name="test_tuner_resume_errored_only",
              failure_config=FailureConfig(fail_fast=False),
              callbacks=[
                  _FailOnStats(num_trials=4, num_finished=2, delay=1)
              ],
          ),
          param_space={
              # First trial succeeds, second hangs, third fails, fourth hangs.
              "failing_hanging": tune.grid_search(
                  [
                      (None, None),
                      (None, hang_marker),
                      (fail_marker, None),
                      (None, hang_marker),
                  ]
              ),
          },
      )
      # Catch the FailOnStats error
      with pytest.raises(RuntimeError):
          tuner.fit()
  
      # After this run we have the following trial states (status, metric):
      # [('TERMINATED', 2), ('RUNNING', 1), ('ERROR', 1), ('PENDING', None)]
  
      # Restarting without continuing existing trials should lead to the results
      # [2, 1, 3, 0], because
      # the TERMINATED trial is finished (state = 2),
      # the RUNNING trial is not continued (marked as terminated),
      # the ERROR trial is not continued (remains at 1 and errored)
      # and the PENDING trial is not continued (marked as terminated).
  
      del tuner
      fail_marker.remove(ignore_errors=True)
      hang_marker.remove(ignore_errors=True)
  
      tuner = Tuner.restore(
          str(tmpdir / "test_tuner_resume_errored_only"),
          trainable=_train_fn_sometimes_failing,
          resume_unfinished=False,
          resume_errored=True,
      )
      tuner._local_tuner._run_config.callbacks = None
  
      results = tuner.fit()
      assert len(results) == 4
      assert len(results.errors) == 0
      assert sorted(
          [r.metrics.get("it", 0) for r in results]
      ) == sorted([2, 1, 3, 0])
  
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 13 for calling a global function with example usage: test_tuner_resume_errored_only(ray_start_2_cpus, tmpdir, monkeypatch) without return types