class_docstr: BaseEnv that executes its sub environments as @ray.remote actors.
  
  This provides dynamic batching of inference as observations are returned
  from the remote simulator actors. Both single and multi-agent child envs
  are supported, and envs can be stepped synchronously or asynchronously.
  
  NOTE: This class implicitly assumes that the remote envs are gym.Env's
  
  You shouldn't need to instantiate this class directly. It's automatically
  inserted when you use the `remote_worker_envs=True` option in your
  Algorithm's config.
class_docstr_tok: ["BaseEnv","that","executes","its","sub","environments","as","@","ray.remote","actors",".","This","provides","dynamic","batching","of","inference","as","observations","are","returned","from","the","remote","simulator","actors",".","Both","single","and","multi-agent","child","envs","are","supported",",","and","envs","can","be","stepped","synchronously","or","asynchronously",".","NOTE",":","This","class","implicitly","assumes","that","the","remote","envs","are","gym.Env's","You","should","n't","need","to","instantiate","this","class","directly",".","It","'s","automatically","inserted","when","you","use","the","`","remote_worker_envs=True","`","option","in","your","Algorithm","'s","config","."]
docstr: Initializes a RemoteVectorEnv instance.
  
  Args:
      make_env: Callable that produces a single (non-vectorized) env,
          given the vector env index as only arg.
      num_envs: The number of sub-environments to create for the
          vectorization.
      multiagent: Whether this is a multiagent env or not.
      remote_env_batch_wait_ms: Time to wait for (ray.remote)
          sub-environments to have new observations available when
          polled. Only when none of the sub-environments is ready,
          repeat the `ray.wait()` call until at least one sub-env
          is ready. Then return only the observations of the ready
          sub-environment(s).
      existing_envs: Optional list of already created sub-environments.
          These will be used as-is and only as many new sub-envs as
          necessary (`num_envs - len(existing_envs)`) will be created.
      worker: An optional RolloutWorker that owns the env. This is only
          used if `remote_worker_envs` is True in your config and the
          `on_sub_environment_created` custom callback needs to be
          called on each created actor.
      restart_failed_sub_environments: If True and any sub-environment (within
          a vectorized env) throws any error during env stepping, the
          Sampler will try to restart the faulty sub-environment. This is done
          without disturbing the other (still intact) sub-environment and without
          the RolloutWorker crashing.
docstr_tok: ["Initializes","a","RemoteVectorEnv","instance",".","Args",":","make_env",":","Callable","that","produces","a","single","(","non-vectorized",")","env",",","given","the","vector","env","index","as","only","arg",".","num_envs",":","The","number","of","sub-environments","to","create","for","the","vectorization",".","multiagent",":","Whether","this","is","a","multiagent","env","or","not",".","remote_env_batch_wait_ms",":","Time","to","wait","for","(","ray.remote",")","sub-environments","to","have","new","observations","available","when","polled",".","Only","when","none","of","the","sub-environments","is","ready",",","repeat","the","`","ray.wait","(",")","`","call","until","at","least","one","sub-env","is","ready",".","Then","return","only","the","observations","of","the","ready","sub-environment","(","s",")",".","existing_envs",":","Optional","list","of","already","created","sub-environments",".","These","will","be","used","as-is","and","only","as","many","new","sub-envs","as","necessary","(","`","num_envs","-","len","(","existing_envs",")","`",")","will","be","created",".","worker",":","An","optional","RolloutWorker","that","owns","the","env",".","This","is","only","used","if","`","remote_worker_envs","`","is","True","in","your","config","and","the","`","on_sub_environment_created","`","custom","callback","needs","to","be","called","on","each","created","actor",".","restart_failed_sub_environments",":","If","True","and","any","sub-environment","(","within","a","vectorized","env",")","throws","any","error","during","env","stepping",",","the","Sampler","will","try","to","restart","the","faulty","sub-environment",".","This","is","done","without","disturbing","the","other","(","still","intact",")","sub-environment","and","without","the","RolloutWorker","crashing","."]
code: def __init__(
      self,
      make_env: Callable[[int], EnvType],
      num_envs: int,
      multiagent: bool,
      remote_env_batch_wait_ms: int,
      existing_envs: Optional[List[ray.actor.ActorHandle]] = None,
      worker: Optional["RolloutWorker"] = None,
      restart_failed_sub_environments: bool = False,
  ):
      """Initializes a RemoteVectorEnv instance.
  
      Args:
          make_env: Callable that produces a single (non-vectorized) env,
              given the vector env index as only arg.
          num_envs: The number of sub-environments to create for the
              vectorization.
          multiagent: Whether this is a multiagent env or not.
          remote_env_batch_wait_ms: Time to wait for (ray.remote)
              sub-environments to have new observations available when
              polled. Only when none of the sub-environments is ready,
              repeat the `ray.wait()` call until at least one sub-env
              is ready. Then return only the observations of the ready
              sub-environment(s).
          existing_envs: Optional list of already created sub-environments.
              These will be used as-is and only as many new sub-envs as
              necessary (`num_envs - len(existing_envs)`) will be created.
          worker: An optional RolloutWorker that owns the env. This is only
              used if `remote_worker_envs` is True in your config and the
              `on_sub_environment_created` custom callback needs to be
              called on each created actor.
          restart_failed_sub_environments: If True and any sub-environment (within
              a vectorized env) throws any error during env stepping, the
              Sampler will try to restart the faulty sub-environment. This is done
              without disturbing the other (still intact) sub-environment and without
              the RolloutWorker crashing.
      """
  
      # Could be creating local or remote envs.
      self.make_env = make_env
      self.num_envs = num_envs
      self.multiagent = multiagent
      self.poll_timeout = remote_env_batch_wait_ms / 1000
      self.worker = worker
      self.restart_failed_sub_environments = (
          restart_failed_sub_environments
      )
  
      # Already existing env objects (generated by the RolloutWorker).
      existing_envs = existing_envs or []
  
      # Whether the given `make_env` callable already returns ActorHandles
      # (@ray.remote class instances) or not.
      self.make_env_creates_actors = False
  
      self._observation_space = None
      self._action_space = None
  
      # List of ray actor handles (each handle points to one @ray.remote
      # sub-environment).
      self.actors: Optional[List[ray.actor.ActorHandle]] = None
  
      # `self.make_env` already produces Actors: Use it directly.
      if len(existing_envs) > 0 and isinstance(
          existing_envs[0], ray.actor.ActorHandle
      ):
          self.make_env_creates_actors = True
          self.actors = existing_envs
          while len(self.actors) < self.num_envs:
              self.actors.append(self._make_sub_env(len(self.actors)))
  
      # `self.make_env` produces gym.Envs (or children thereof, such
      # as MultiAgentEnv): Need to auto-wrap it here. The problem with
      # this is that custom methods wil get lost. If you would like to
      # keep your custom methods in your envs, you should provide the
      # env class directly in your config (w/o tune.register_env()),
      # such that your class can directly be made a @ray.remote
      # (w/o the wrapping via `_Remote[Multi|Single]AgentEnv`).
      # Also, if `len(existing_envs) > 0`, we have to throw those away
      # as we need to create ray actors here.
      else:
          self.actors = [
              self._make_sub_env(i) for i in range(self.num_envs)
          ]
          # Utilize existing envs for inferring observation/action spaces.
          if len(existing_envs) > 0:
              self._observation_space = existing_envs[
                  0
              ].observation_space
              self._action_space = existing_envs[0].action_space
          # Have to call actors' remote methods to get observation/action spaces.
          else:
              self._observation_space, self._action_space = ray.get(
                  [
                      self.actors[0].observation_space.remote(),
                      self.actors[0].action_space.remote(),
                  ]
              )
  
      # Dict mapping object refs (return values of @ray.remote calls),
      # whose actual values we are waiting for (via ray.wait in
      # `self.poll()`) to their corresponding actor handles (the actors
      # that created these return values).
      # Call `reset()` on all @ray.remote sub-environment actors.
      self.pending: Dict[ray.actor.ActorHandle] = {
          a.reset.remote(): a for a in self.actors
      }
  
imports: import gymnasium
  import logging
  from typing import Callable, Dict, List, Optional, Set, Tuple, TYPE_CHECKING
  import ray
  from ray.util import log_once
  from ray.rllib.env.base_env import BaseEnv, _DUMMY_AGENT_ID, ASYNC_RESET_RETURN
  from ray.rllib.utils.annotations import override, PublicAPI
  from ray.rllib.utils.typing import AgentID, EnvID, EnvType, MultiEnvDict
label_desc: Use image node_id 1 to create a new RemoteBaseEnv object from inherited base classes: BaseEnv with example: obj = RemoteBaseEnv(make_env, num_envs, multiagent, remote_env_batch_wait_ms, existing_envs, worker, restart_failed_sub_environments)