code: def test_fractional_resources(shutdown_only):
      ray.init(
          num_cpus=6,
          num_gpus=3,
          resources={"Custom": 3, "Custom2": 3, "TPU": 3},
      )
  
      @ray.remote(num_gpus=0.5)
      class Foo1:
          def method(self):
              gpu_ids = ray.get_gpu_ids()
              assert len(gpu_ids) == 1
              return gpu_ids[0]
  
      foos = [Foo1.remote() for _ in range(6)]
      gpu_ids = ray.get([f.method.remote() for f in foos])
      for i in range(3):
          assert gpu_ids.count(i) == 2
      del foos
  
      @ray.remote
      class Foo2:
          def method(self):
              pass
  
      # Create an actor that requires 0.7 of the custom resource.
      f1 = Foo2._remote([], {}, resources={"Custom": 2.7})
      ray.get(f1.method.remote())
      # Make sure that we cannot create an actor that requires 0.7 of the
      # custom resource. TODO(rkn): Re-enable this once ray.wait is
      # implemented.
      f2 = Foo2._remote([], {}, resources={"Custom": 0.7})
      ready, _ = ray.wait([f2.method.remote()], timeout=0.5)
      assert len(ready) == 0
      # Make sure we can start an actor that requries only 0.3 of the custom
      # resource.
      f3 = Foo2._remote([], {}, resources={"Custom": 0.3})
      ray.get(f3.method.remote())
  
      del f1, f3
  
      # Non unit resources (e.g. CPU, ) allow fractional
      # number of resources greather than 1.
      @ray.remote(num_cpus=1.5, resources={"Custom2": 2.5})
      def test_frac_cpu():
          return True
  
      assert ray.get(test_frac_cpu.remote())
  
      # Unit instance resources (GPU, TPU, neuron_core) throw exceptions
      # for fractional number of resources greater than 1.
      @ray.remote(num_gpus=1.5)
      def test_frac_gpu():
          pass
  
      with pytest.raises(ValueError):
          test_frac_gpu.remote()
  
      with pytest.raises(ValueError):
          Foo2._remote([], {}, resources={"TPU": 2.5})
  
imports: import logging
  import os
  import sys
  import time
  import numpy
  import pytest
  import ray
  import ray.cluster_utils
  from ray._private.test_utils import RayTestTimeoutException, wait_for_condition
  from ray.util.placement_group import placement_group
  from ray.util.accelerators import AWS_NEURON_CORE
  from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
label_desc: Use image node_id 4 for calling a global function with example usage: test_fractional_resources(shutdown_only) and returns: True, gpu_ids