code: def main():
      ray.init()
  
      head_node_ip = ray.util.get_node_ip_address()
  
      assert (
          len([n for n in ray.nodes() if n["Alive"]]) == 1
      ), "Too many nodes available at start of script"
  
      node_counter = NodeCountCallback()
  
      tune.run(
          train_fn,
          num_samples=3,
          config={"head_node_ip": head_node_ip},
          callbacks=[node_counter],
          resources_per_trial={"cpu": 4},
      )
  
      node_counts = Counter(node_counter.node_counts)
      assert node_counts[3] > 0, "Cluster never scaled to 3 nodes"
      assert (
          node_counter.node_counts[-1] == 1
      ), "Cluster didn't scale down to 1 node."
  
file_path: ray/release/cluster_tests/workloads/tune_scale_up_down.py
imports: from collections import Counter
  import time
  import ray
  from ray import train, tune
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types