code: def test_restore_with_parameters(
      ray_start_2_cpus, tmp_path, use_function_trainable
  ):
      """Tests Tuner restoration for a `tune.with_parameters` wrapped trainable."""
  
      def train_func(config, data_str=None, data_obj=None):
          assert data_str is not None and data_obj is not None
          fail_marker = config.pop("fail_marker", None)
          config["failing_hanging"] = (fail_marker, None)
          _train_fn_sometimes_failing(config)
  
      class FailingTrainable(Trainable):
          def setup(self, config, data_str=None, data_obj=None):
              assert data_str is not None and data_obj is not None
              self.idx = 0
              self.fail_marker = config.get("fail_marker", None)
  
          def step(self):
              if self.fail_marker and self.fail_marker.exists():
                  raise RuntimeError("==== Run is failing ====")
              self.idx += 1
              return {"score": self.idx}
  
          def save_checkpoint(self, checkpoint_dir):
              return {"idx": self.idx}
  
          def load_checkpoint(self, checkpoint_dict):
              self.idx = checkpoint_dict["idx"]
  
      trainable = (
          train_func if use_function_trainable else FailingTrainable
      )
  
      def create_trainable_with_params():
          data = MockData()
          trainable_with_params = tune.with_parameters(
              trainable, data_str="data", data_obj=data
          )
          return trainable_with_params
  
      exp_name = "restore_with_params"
      fail_marker = tmp_path / "fail_marker"
      fail_marker.write_text("", encoding="utf-8")
  
      tuner = Tuner(
          create_trainable_with_params(),
          run_config=RunConfig(
              name=exp_name,
              storage_path=str(tmp_path),
              stop={"training_iteration": 3},
              failure_config=FailureConfig(max_failures=0),
              checkpoint_config=CheckpointConfig(
                  checkpoint_frequency=0
                  if use_function_trainable
                  else 1
              ),
          ),
          param_space={"fail_marker": fail_marker},
      )
      results = tuner.fit()
      assert results.errors
  
      fail_marker.unlink()
      tuner = Tuner.restore(
          str(tmp_path / exp_name),
          trainable=create_trainable_with_params(),
          resume_errored=True,
      )
      results = tuner.fit()
      assert not results.errors
  
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 20 for calling a global function with example usage: test_restore_with_parameters(ray_start_2_cpus, tmp_path, use_function_trainable) and returns: trainable_with_params, dict, dict