docstr: Tests, whether SingleAgentGymEnvRunner can be distributed.
docstr_tok: ["Tests",",","whether","SingleAgentGymEnvRunner","can","be","distributed","."]
code: def test_distributed_env_runner(self):
      """Tests, whether SingleAgentGymEnvRunner can be distributed."""
  
      remote_class = ray.remote(num_cpus=1, num_gpus=0)(
          SingleAgentEnvRunner
      )
  
      # Test with both parallelized sub-envs and w/o.
      remote_worker_envs = [False, True]
  
      for envs_parallel in remote_worker_envs:
          config = (
              AlgorithmConfig().environment("CartPole-v1")
              # Vectorize x2 and by default, rollout 64 timesteps per individual env.
              .rollouts(
                  num_rollout_workers=5,
                  num_envs_per_worker=5,
                  rollout_fragment_length=10,
                  remote_worker_envs=envs_parallel,
              )
          )
  
          array = [
              remote_class.remote(config=config)
              for _ in range(config.num_rollout_workers)
          ]
          # Sample in parallel.
          results = [
              a.sample.remote(random_actions=True) for a in array
          ]
          results = ray.get(results)
          # Loop over individual EnvRunner Actor's results and inspect each.
          for episodes in results:
              # Assert length of all fragments is  `rollout_fragment_length`.
              self.assertEqual(
                  sum(len(e) for e in episodes),
                  config.num_envs_per_worker
                  * config.rollout_fragment_length,
              )
  
file_path: ray/rllib/env/tests/test_single_agent_env_runner.py
imports: import unittest
  import ray
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  from ray.rllib.env.single_agent_env_runner import SingleAgentEnvRunner
label_desc: Use image node_id 4 for calling the TestSingleAgentEnvRunner obj's underlying member method code with example usage: obj.test_distributed_env_runner() without return types