code: def test_on_sub_environment_created(self):
      config = (
          dqn.DQNConfig().environment("CartPole-v1")
          # Create 4 sub-environments per remote worker.
          # Create 2 remote workers.
          .rollouts(num_envs_per_worker=4, num_rollout_workers=2)
      )
  
      for callbacks in (
          OnSubEnvironmentCreatedCallback,
          make_multi_callbacks([OnSubEnvironmentCreatedCallback]),
      ):
          config.callbacks(callbacks)
  
          for _ in framework_iterator(
              config, frameworks=("tf", "torch")
          ):
              algo = config.build()
              # Fake the counter on the local worker (doesn't have an env) and
              # set it to -1 so the below `foreach_worker()` won't fail.
              algo.workers.local_worker().sum_sub_env_vector_indices = (
                  -1
              )
  
              # Get sub-env vector index sums from the 2 remote workers:
              sum_sub_env_vector_indices = algo.workers.foreach_worker(
                  lambda w: w.sum_sub_env_vector_indices
              )
              # Local worker has no environments -> Expect the -1 special
              # value returned by the above lambda.
              self.assertTrue(sum_sub_env_vector_indices[0] == -1)
              # Both remote workers (index 1 and 2) have a vector index counter
              # of 6 (sum of vector indices: 0 + 1 + 2 + 3).
              self.assertTrue(sum_sub_env_vector_indices[1] == 6)
              self.assertTrue(sum_sub_env_vector_indices[2] == 6)
              algo.stop()
  
imports: from collections import Counter
  import unittest
  import ray
  from ray.rllib.algorithms.callbacks import DefaultCallbacks, make_multi_callbacks
  import ray.rllib.algorithms.dqn
  from ray.rllib.algorithms.ppo import PPOConfig
  from ray.rllib.evaluation.episode import Episode
  from ray.rllib.examples.env.random_env import RandomEnv
  from ray.rllib.utils.test_utils import framework_iterator
label_desc: Use image node_id 4 for calling the TestCallbacks obj's underlying member method code with example usage: obj.test_on_sub_environment_created() without return types