class_docstr: Set of EnvRunners with n @ray.remote workers and zero or one local worker.
  
  Where: n >= 0.
class_docstr_tok: ["Set","of","EnvRunners","with","n","@","ray.remote","workers","and","zero","or","one","local","worker",".","Where",":","n",">","=","0","."]
docstr: Initializes a WorkerSet instance.
  Args:
      validate_env: Optional callable to validate the generated
          environment (only on worker=0).
      config: Optional dict that extends the common config of
          the Algorithm class.
      num_workers: Number of remote rollout workers to create.
      local_worker: Whether to create a local (non @ray.remote) worker
          in the returned set as well (default: True). If `num_workers`
          is 0, always create a local worker.
docstr_tok: ["Initializes","a","WorkerSet","instance",".","Args",":","validate_env",":","Optional","callable","to","validate","the","generated","environment","(","only","on","worker=0",")",".","config",":","Optional","dict","that","extends","the","common","config","of","the","Algorithm","class",".","num_workers",":","Number","of","remote","rollout","workers","to","create",".","local_worker",":","Whether","to","create","a","local","(","non","@","ray.remote",")","worker","in","the","returned","set","as","well","(","default",":","True",")",".","If","`","num_workers","`","is","0",",","always","create","a","local","worker","."]
code: def _setup(
      self,
      *,
      validate_env: Optional[Callable[[EnvType], None]] = None,
      config: Optional["AlgorithmConfig"] = None,
      num_workers: int = 0,
      local_worker: bool = True,
  ):
      """Initializes a WorkerSet instance.
      Args:
          validate_env: Optional callable to validate the generated
              environment (only on worker=0).
          config: Optional dict that extends the common config of
              the Algorithm class.
          num_workers: Number of remote rollout workers to create.
          local_worker: Whether to create a local (non @ray.remote) worker
              in the returned set as well (default: True). If `num_workers`
              is 0, always create a local worker.
      """
      # Force a local worker if num_workers == 0 (no remote workers).
      # Otherwise, this WorkerSet would be empty.
      self._local_worker = None
      if num_workers == 0:
          local_worker = True
      # Create a local (learner) version of the config for the local worker.
      # The only difference is the tf_session_args, which - for the local worker -
      # will be `config.tf_session_args` updated/overridden with
      # `config.local_tf_session_args`.
      local_tf_session_args = config.tf_session_args.copy()
      local_tf_session_args.update(config.local_tf_session_args)
      self._local_config = config.copy(copy_frozen=False).framework(
          tf_session_args=local_tf_session_args
      )
  
      if config.input_ == "dataset":
          # Create the set of dataset readers to be shared by all the
          # rollout workers.
          self._ds, self._ds_shards = get_dataset_and_shards(
              config, num_workers
          )
      else:
          self._ds = None
          self._ds_shards = None
  
      # Create a number of @ray.remote workers.
      self.add_workers(
          num_workers,
          validate=config.validate_workers_after_construction,
      )
  
      # If num_workers > 0 and we don't have an env on the local worker,
      # get the observation- and action spaces for each policy from
      # the first remote worker (which does have an env).
      if (
          local_worker
          and self.__worker_manager.num_actors() > 0
          and not config.create_env_on_local_worker
          and (not config.observation_space or not config.action_space)
      ):
          spaces = self._get_spaces_from_remote_worker()
      else:
          spaces = None
  
      # Create a local worker, if needed.
      if local_worker:
          self._local_worker = self._make_worker(
              cls=self.env_runner_cls,
              env_creator=self._env_creator,
              validate_env=validate_env,
              worker_index=0,
              num_workers=num_workers,
              config=self._local_config,
              spaces=spaces,
          )
  
imports: import functools
  import gymnasium
  import logging
  import importlib.util
  import os
  from typing import Callable, Container, Dict, List, Optional, Tuple, Type, TYPE_CHECKING, TypeVar, Union
  import ray
  from ray.actor import ActorHandle
  from ray.exceptions import RayActorError
  from ray.rllib.core.rl_module.rl_module import SingleAgentRLModuleSpec
  from ray.rllib.evaluation.rollout_worker import RolloutWorker
  from ray.rllib.utils.actor_manager import RemoteCallResults
  from ray.rllib.env.base_env import BaseEnv
  from ray.rllib.env.env_context import EnvContext
  from ray.rllib.env.env_runner import EnvRunner
  from ray.rllib.offline import get_dataset_and_shards
  from ray.rllib.policy.policy import Policy, PolicyState
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
  from ray.rllib.utils.actor_manager import FaultTolerantActorManager
  from ray.rllib.utils.annotations import DeveloperAPI
  from ray.rllib.utils.deprecation import Deprecated, deprecation_warning, DEPRECATED_VALUE
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.policy import validate_policy_id
  from ray.rllib.utils.typing import AgentID, EnvCreator, EnvType, EpisodeID, PartialAlgorithmConfigDict, PolicyID, SampleBatchType, TensorType
label_desc: Use image node_id 2 for calling the WorkerSet obj's underlying member method code with example usage: obj._setup() without return types