docstr: Expect sub-envs to fail (and not recover), but re-start them individually.
docstr_tok: ["Expect","sub-envs","to","fail","(","and","not","recover",")",",","but","re-start","them","individually","."]
code: def test_crash_sub_envs_during_sampling_but_restart_sub_envs(self):
      """Expect sub-envs to fail (and not recover), but re-start them individually."""
      config = (
          PPOConfig()
          .rollouts(
              num_rollout_workers=2,
              num_envs_per_worker=3,
              # Re-start failed individual sub-envs (then continue).
              # This means no workers will ever fail due to individual env errors
              # (only maybe for reasons other than the env).
              restart_failed_sub_environments=True,
              # If the worker was affected by an error (other than the env error),
              # allow it to be removed, but training will continue.
              ignore_worker_failures=True,
          )
          .environment(
              env=CartPoleCrashing,
              env_config={
                  # Crash prob=1%.
                  "p_crash": 0.01,
                  # Make sure nothing happens during pre-checks.
                  "skip_env_checking": True,
              },
          )
      )
      # Pre-checking disables, so building the Algorithm is save.
      algo = config.build()
      # Try to re-create the sub-env for infinite amount of times.
      # The worker recreation/ignore tolerance used to be hard-coded to 3, but this
      # has now been
      for _ in range(10):
          # Expect some errors being logged here, but in general, should continue
          # as we recover from all sub-env failures.
          algo.train()
          # No worker has been removed. Still 2 left.
          self.assertEqual(algo.workers.num_healthy_remote_workers(), 2)
      algo.stop()
  
file_path: ray/python/ray/rllib/evaluation/tests/test_envs_that_crash.py
imports: import unittest
  import ray
  from ray.rllib.algorithms.pg import PGConfig
  from ray.rllib.algorithms.ppo import PPOConfig
  from ray.rllib.algorithms.tests.test_worker_failures import ForwardHealthCheckToEnvWorker
  from ray.rllib.examples.env.cartpole_crashing import CartPoleCrashing
  from ray.rllib.utils.error import EnvError
label_desc: Use image node_id 7 for calling the TestEnvsThatCrash obj's underlying member method code with example usage: obj.test_crash_sub_envs_during_sampling_but_restart_sub_envs() without return types