code: def test_multi_trial_reuse_heterogeneous(ray_start_4_cpus_extra):
      """Test that actors with heterogeneous resource requirements are reused efficiently.
  
      - Run 6 trials in total
      - Only 1 trial can run at the same time
      - Trials 1 and 6, 2 and 4, and 3 and 5, have the same resource request, respectively
      - Assert that trials 4, 5, and 6 re-use their respective previous actors
  
      """
      # We need to set this to 6 so that all trials will be scheduled and actors will
      # be correctly cached.
      os.environ["TUNE_MAX_PENDING_TRIALS_PG"] = "6"
  
      register_trainable("foo2", MyResettableClass)
  
      trials = tune.run(
          "foo2",
          config={
              # The extra resources are selected so that only any 1 placement group
              # can be scheduled at the same time at all times (to force sequential
              # execution of trials)
              "required_resources": tune.grid_search(
                  [
                      {"cpu": 4, "custom_resources": {"extra": 4}},
                      {"cpu": 2, "custom_resources": {"extra": 4}},
                      {"cpu": 1, "custom_resources": {"extra": 4}},
                      {"cpu": 2, "custom_resources": {"extra": 4}},
                      {"cpu": 1, "custom_resources": {"extra": 4}},
                      {"cpu": 4, "custom_resources": {"extra": 4}},
                  ]
              ),
              "id": -1,
          },
          reuse_actors=True,
      ).trials
  
      # Actors may be re-used in a different order as the staged_trials set is unsorted
      assert sorted([t.last_result["num_resets"] for t in trials]) == [
          0,
          0,
          0,
          1,
          1,
          1,
      ]
  
imports: import inspect
  import os
  from pathlib import Path
  import tempfile
  from typing import Callable
  import pytest
  import sys
  import time
  import ray
  from ray import train, tune, logger
  from ray.train import CheckpointConfig
  from ray.tune import Trainable, run_experiments, register_trainable
  from ray.tune.error import TuneError
  from ray.tune.result_grid import ResultGrid
  from ray.tune.schedulers.trial_scheduler import FIFOScheduler, TrialScheduler
  from ray.tune.tune import _check_mixin
  from ray.train.tests.util import create_dict_checkpoint, load_dict_checkpoint
label_desc: Use image node_id 16 for calling a global function with example usage: test_multi_trial_reuse_heterogeneous(ray_start_4_cpus_extra) without return types