code: def validate_py_environment(
      environment: py_environment.PyEnvironment,
      episodes: int = 5,
      observation_and_action_constraint_splitter: Optional[
          types.Splitter
      ] = None,
  ):
      """Validates the environment follows the defined specs."""
      time_step_spec = environment.time_step_spec()
      action_spec = environment.action_spec()
  
      random_policy = random_py_policy.RandomPyPolicy(
          time_step_spec=time_step_spec,
          action_spec=action_spec,
          observation_and_action_constraint_splitter=(
              observation_and_action_constraint_splitter
          ),
      )
  
      if environment.batch_size is not None:
          batched_time_step_spec = array_spec.add_outer_dims_nest(
              time_step_spec, outer_dims=(environment.batch_size,)
          )
      else:
          batched_time_step_spec = time_step_spec
  
      episode_count = 0
      time_step = environment.reset()
  
      while episode_count < episodes:
          if not array_spec.check_arrays_nest(
              time_step, batched_time_step_spec
          ):
              raise ValueError(
                  "Given `time_step`: %r does not match expected `time_step_spec`: %r"
                  % (time_step, batched_time_step_spec)
              )
  
          action = random_policy.action(time_step).action
          time_step = environment.step(action)
  
          episode_count += np.sum(time_step.is_last())
  
file_path: agents/tf_agents/environments/utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Optional, Union
  import numpy
  from tf_agents.environments import py_environment
  from tf_agents.environments import tf_environment
  from tf_agents.environments import tf_py_environment
  from tf_agents.policies import random_py_policy
  from tf_agents.specs import array_spec
  from tf_agents.typing import types
label_desc: Use image node_id 2 for calling a global function with example usage: validate_py_environment(environment, episodes, observation_and_action_constraint_splitter) without return types