code: def _validate_trajectory(
      value: trajectory.Trajectory,
      trajectory_spec: trajectory.Trajectory,
      sequence_length: typing.Optional[int],
      num_outer_dims: te.Literal[
          1, 2
      ] = 2,  # pylint: disable=bad-whitespace
  ):
      """Validate a Trajectory given its spec and a sequence length."""
      if not nest_utils.is_batched_nested_tensors(
          value,
          trajectory_spec,
          num_outer_dims=num_outer_dims,
          allow_extra_fields=True,
      ):
          debug_str_1 = tf.nest.map_structure(
              lambda tp: tp.shape, value
          )
          debug_str_2 = tf.nest.map_structure(
              lambda spec: spec.shape, trajectory_spec
          )
  
          shape_str = (
              "two outer dimensions"
              if num_outer_dims == 2
              else "one outer dimension"
          )
          shape_prefix_str = "[B, T]" if num_outer_dims == 2 else "[B]"
          raise ValueError(
              "All of the Tensors in `value` must have {shape_str}. Specifically, "
              "tensors must have shape `{shape_prefix_str} + spec.shape`.\n"
              "Full shapes of value tensors:\n  {debug_str_1}.\n"
              "Expected shapes (excluding the {shape_str}):\n  {debug_str_2}.".format(
                  shape_str=shape_str,
                  debug_str_1=debug_str_1,
                  debug_str_2=debug_str_2,
                  shape_prefix_str=shape_prefix_str,
              )
          )
  
      # If we have a time dimension and a train_sequence_length, make sure they
      # match.
      if sequence_length is not None:
  
          def check_shape(path, t):  # pylint: disable=invalid-name
              if t.shape[1] != sequence_length:
                  debug_str = tf.nest.map_structure(
                      lambda tp: tp.shape, value
                  )
                  raise ValueError(
                      "The agent was configured to expect a `sequence_length` "
                      "of '{seq_len}'. Value is expected to be shaped `[B, T] + "
                      "spec.shape` but at least one of the Tensors in `value` has a "
                      "time axis dim value '{t_dim}' vs "
                      "the expected '{seq_len}'.\nFirst such tensor is:\n\t"
                      "value.{path}. \nFull shape structure of "
                      "value:\n\t{debug_str}".format(
                          seq_len=sequence_length,
                          t_dim=t.shape[1],
                          path=path,
                          debug_str=debug_str,
                      )
                  )
  
          nest_utils.map_structure_with_paths(check_shape, value)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import typing
  import tensorflow
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import composite
  from tf_agents.utils import nest_utils
  import typing_extensions
label_desc: Use image node_id 4 for calling a global function with example usage: _validate_trajectory(value, trajectory_spec, sequence_length, num_outer_dims) without return types