class_docstr: A helper class to group updates and operations on an Instance object defined
  in instance_manager.proto
class_docstr_tok: ["A","helper","class","to","group","updates","and","operations","on","an","Instance","object","defined","in","instance_manager.proto"]
code: def get_valid_transitions() -> (
      Dict["Instance.InstanceStatus", Set["Instance.InstanceStatus"]]
  ):
      return {
          # This is the initial status of a new instance.
          Instance.QUEUED: {
              # Cloud provider requested to launch a node for the instance.
              # This happens when the a launch request is made to the node provider.
              Instance.REQUESTED
          },
          # When in this status, a launch request to the node provider is made.
          Instance.REQUESTED: {
              # Cloud provider allocated a cloud node for the instance.
              # This happens when the cloud node first appears in the list of running
              # cloud nodes from the cloud node provider.
              Instance.ALLOCATED,
              # Cloud provider fails to allocate one. Either as a timeout or
              # the launch request fails immediately.
              Instance.ALLOCATION_FAILED,
          },
          # When in this status, the cloud node is allocated and running. This
          # happens when the cloud node is present in node provider's list of
          # running cloud nodes.
          Instance.ALLOCATED: {
              # Ray needs to be install and launch on the provisioned cloud node.
              # This happens when the cloud node is allocated, and the autoscaler
              # is responsible for installing and launching ray on the cloud node.
              # For node provider that manages the ray installation and launching,
              # this state is skipped.
              Instance.RAY_INSTALLING,
              # Ray is already installed and running on the provisioned cloud node.
              # This happens when a ray node joins the ray cluster, and the instance
              # is discovered in the set of running ray nodes from the Ray cluster.
              Instance.RAY_RUNNING,
              # Instance is requested to be stopped, e.g. instance leaked: no matching
              # Instance with the same type is found in the autoscaler's state.
              Instance.STOPPING,
              # Cloud node somehow failed.
              Instance.STOPPED,
          },
          # Ray process is being installed and started on the cloud node.
          # This status is skipped for node provider that manages the ray
          # installation and launching. (e.g. Ray-on-Spark)
          Instance.RAY_INSTALLING: {
              # Ray installed and launched successfully, reported by the ray cluster.
              # Similar to the Instance.ALLOCATED -> Instance.RAY_RUNNING transition,
              # where the ray process is managed by the node provider.
              Instance.RAY_RUNNING,
              # Ray installation failed. This happens when the ray process failed to
              # be installed and started on the cloud node.
              Instance.RAY_INSTALL_FAILED,
              # Wen the ray node is reported as stopped by the ray cluster.
              # This could happen that the ray process was stopped quickly after start
              # such that a ray running node  wasn't discovered and the RAY_RUNNING
              # transition was skipped.
              Instance.RAY_STOPPED,
              # Cloud node somehow failed during the installation process.
              Instance.STOPPED,
          },
          # Ray process is installed and running on the cloud node. When in this
          # status, a ray node must be present in the ray cluster.
          Instance.RAY_RUNNING: {
              # Ray is requested to be stopped to the ray cluster,
              # e.g. idle termination.
              Instance.RAY_STOPPING,
              # Ray is already stopped, as reported by the ray cluster.
              Instance.RAY_STOPPED,
              # Cloud node somehow failed.
              Instance.STOPPED,
          },
          # When in this status, the ray process is requested to be stopped to the
          # ray cluster, but not yet present in the dead ray node list reported by
          # the ray cluster.
          Instance.RAY_STOPPING: {
              # Ray is stopped, and the ray node is present in the dead ray node list
              # reported by the ray cluster.
              Instance.RAY_STOPPED,
              # Cloud node somehow failed.
              Instance.STOPPED,
          },
          # When in this status, the ray process is stopped, and the ray node is
          # present in the dead ray node list reported by the ray cluster.
          Instance.RAY_STOPPED: {
              # Cloud node is requested to be stopped.
              Instance.STOPPING,
              # Cloud node somehow failed.
              Instance.STOPPED,
          },
          # When in this status, the cloud node is requested to be stopped to
          # the node provider.
          Instance.STOPPING: {
              # When a cloud node no longer appears in the list of running cloud nodes
              # from the node provider.
              Instance.STOPPED
          },
          # Whenever a cloud node disappears from the list of running cloud nodes
          # from the node provider, the instance is marked as stopped. Since
          # we guarantee 1:1 mapping of a Instance to a cloud node, this is a
          # terminal state.
          Instance.STOPPED: set(),  # Terminal state.
          # When in this status, the cloud node failed to be allocated by the
          # node provider.
          Instance.ALLOCATION_FAILED: {
              # Autoscaler might retry to allocate the instance.
              Instance.QUEUED
          },
          Instance.RAY_INSTALL_FAILED: {
              # Autoscaler requests to shutdown the instance when ray install failed.
              Instance.STOPPING,
              # Cloud node somehow failed.
              Instance.STOPPED,
          },
          # Initial state before the instance is created. Should never be used.
          Instance.UNKNOWN: set(),
      }
  
file_path: ray/python/ray/autoscaler/v2/instance_manager/instance_manager.py
imports: import logging
  import time
  from abc import ABC, abstractmethod
  from typing import Dict, List, Optional, Set
  from ray.autoscaler.v2.schema import InvalidInstanceStatusError
  from ray.core.generated.instance_manager_pb2 import GetInstanceManagerStateReply, GetInstanceManagerStateRequest, Instance, UpdateInstanceManagerStateReply, UpdateInstanceManagerStateRequest
label_desc: Use image node_id 6 for calling the InstanceUtil obj's underlying member method code with example usage: obj.get_valid_transitions() and returns: dict