code: def test_actor_gpus(ray_start_cluster):
      cluster = ray_start_cluster
      num_nodes = 3
      num_gpus_per_raylet = 4
      for i in range(num_nodes):
          cluster.add_node(
              num_cpus=10 * num_gpus_per_raylet,
              num_gpus=num_gpus_per_raylet,
          )
      ray.init(address=cluster.address)
  
      @ray.remote(num_gpus=1)
      class Actor1:
          def __init__(self):
              self.gpu_ids = ray.get_gpu_ids()
  
          def get_location_and_ids(self):
              assert ray.get_gpu_ids() == self.gpu_ids
              return (
                  ray._private.worker.global_worker.node.unique_id,
                  tuple(self.gpu_ids),
              )
  
      # Create one actor per GPU.
      actors = [
          Actor1.remote()
          for _ in range(num_nodes * num_gpus_per_raylet)
      ]
      # Make sure that no two actors are assigned to the same GPU.
      locations_and_ids = ray.get(
          [actor.get_location_and_ids.remote() for actor in actors]
      )
      node_names = {location for location, gpu_id in locations_and_ids}
      assert len(node_names) == num_nodes
      location_actor_combinations = []
      for node_name in node_names:
          for gpu_id in range(num_gpus_per_raylet):
              location_actor_combinations.append((node_name, (gpu_id,)))
      assert set(locations_and_ids) == set(location_actor_combinations)
  
      # Creating a new actor should fail because all of the GPUs are being
      # used.
      a = Actor1.remote()
      ready_ids, _ = ray.wait(
          [a.get_location_and_ids.remote()], timeout=0.01
      )
      assert ready_ids == []
  
imports: import collections
  import os
  import sys
  import time
  import pytest
  import ray
  import ray.cluster_utils
label_desc: Use image node_id 4 for calling a global function with example usage: test_actor_gpus(ray_start_cluster) and returns: ray,  tuple