code: def test_placement_group_max_cpu_frac_edge_cases(ray_start_cluster):
      """
      _max_cpu_fraction_per_node <= 0  ---> should raise error (always)
      _max_cpu_fraction_per_node = 0.999 --->
          should exclude 1 CPU (this is already the case)
      _max_cpu_fraction_per_node = 0.001 --->
          should exclude 3 CPUs (not currently the case, we'll exclude all 4 CPUs).
  
      Related: https://github.com/ray-project/ray/issues/26635
      """
      cluster = ray_start_cluster
      cluster.add_node(num_cpus=4)
      cluster.wait_for_nodes()
      ray.init(address=cluster.address)
  
      """
      0 or 1 is not allowed.
      """
      with pytest.raises(ValueError):
          ray.util.placement_group(
              [{"CPU": 1}], _max_cpu_fraction_per_node=0
          )
  
      """
      Make sure when _max_cpu_fraction_per_node = 0.999, 1 CPU is always excluded.
      """
      pg = ray.util.placement_group(
          [{"CPU": 1} for _ in range(4)],
          _max_cpu_fraction_per_node=0.999,
      )
      # Since 1 CPU is excluded, we cannot schedule this pg.
      with pytest.raises(ray.exceptions.GetTimeoutError):
          ray.get(pg.ready(), timeout=5)
      ray.util.remove_placement_group(pg)
  
      # Since 1 CPU is excluded, we can schedule 1 num_cpus actor after creating
      # CPU: 1 * 3 bundle placement groups.
      @ray.remote(num_cpus=1)
      class A:
          def ready(self):
              pass
  
      # Try actor creation -> pg creation.
      a = A.remote()
      ray.get(a.ready.remote())
      pg = ray.util.placement_group(
          [{"CPU": 1} for _ in range(3)],
          _max_cpu_fraction_per_node=0.999,
      )
      ray.get(pg.ready())
  
      ray.kill(a)
      ray.util.remove_placement_group(pg)
  
      # Make sure the opposite order also works. pg creation -> actor creation.
      pg = ray.util.placement_group(
          [{"CPU": 1} for _ in range(3)],
          _max_cpu_fraction_per_node=0.999,
      )
      a = A.remote()
      ray.get(a.ready.remote())
      ray.get(pg.ready())
  
      ray.kill(a)
      ray.util.remove_placement_group(pg)
  
      """
      _max_cpu_fraction_per_node = 0.001 --->
          should exclude 3 CPUs (not currently the case, we'll exclude all 4 CPUs).
      """
      # We can schedule up to 1 pg.
      pg = ray.util.placement_group(
          [{"CPU": 1}], _max_cpu_fraction_per_node=0.001
      )
      ray.get(pg.ready())
      # Cannot schedule any more PG.
      pg2 = ray.util.placement_group(
          [{"CPU": 1}], _max_cpu_fraction_per_node=0.001
      )
      with pytest.raises(ray.exceptions.GetTimeoutError):
          ray.get(pg2.ready(), timeout=5)
  
      # Since 3 CPUs are excluded, we can schedule actors.
      actors = [A.remote() for _ in range(3)]
      ray.get([a.ready.remote() for a in actors])
  
      # Once pg 1 is removed, pg 2 can be created since there's 1 CPU that can be
      # used for this pg.
      ray.util.remove_placement_group(pg)
      ray.get(pg2.ready())
  
file_path: ray/python/ray/tests/test_placement_group_5.py
imports: import sys
  import pytest
  import ray
  from ray.tests.test_placement_group import are_pairwise_unique
  from ray.util.client.ray_client_helpers import connect_to_client_or_not
  from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
label_desc: Use image node_id 4 for calling a global function with example usage: test_placement_group_max_cpu_frac_edge_cases(ray_start_cluster) without return types