class_docstr: A class that stores useful data for performing data conversions.
class_docstr_tok: ["A","class","that","stores","useful","data","for","performing","data","conversions","."]
docstr: Creates a DataContext.
  
  Note: The context does not store a state spec, or other information about
  a Policy's internal state.  Policy state is not typically stored in a
  replay buffer or on disk, except when the policy explicitly chooses to
  store it by adding the state as a field inside its `info` output.  In
  those cases, the internal policy state spec is represented as part of the
  `info_spec`.
  
  Args:
    time_step_spec: A nest of `tf.TimeStep` representing the time_steps.
    action_spec: A nest of `tf.TypeSpec` representing the actions.
    info_spec: A nest of `tf.TypeSpec` representing the policy's info.
      (Typically this is the info emitted by the collect policy).
    policy_state_spec: A nest of `tf.TypeSpec` representing the policy's
      state.
    use_half_transition: A special transition that the next_time_step contains
      a dummy observation.
  
  Raises:
    TypeError: If any of the specs are not nests containing tf.TypeSpec
      objects.
code: def __init__(
      self,
      time_step_spec: ts.TimeStep,
      action_spec: types.NestedTensorSpec,
      info_spec: types.NestedTensorSpec,
      policy_state_spec: types.NestedTensorSpec = (),
      use_half_transition: bool = False,
  ):
      """Creates a DataContext.
  
      Note: The context does not store a state spec, or other information about
      a Policy's internal state.  Policy state is not typically stored in a
      replay buffer or on disk, except when the policy explicitly chooses to
      store it by adding the state as a field inside its `info` output.  In
      those cases, the internal policy state spec is represented as part of the
      `info_spec`.
  
      Args:
        time_step_spec: A nest of `tf.TimeStep` representing the time_steps.
        action_spec: A nest of `tf.TypeSpec` representing the actions.
        info_spec: A nest of `tf.TypeSpec` representing the policy's info.
          (Typically this is the info emitted by the collect policy).
        policy_state_spec: A nest of `tf.TypeSpec` representing the policy's
          state.
        use_half_transition: A special transition that the next_time_step contains
          a dummy observation.
  
      Raises:
        TypeError: If any of the specs are not nests containing tf.TypeSpec
          objects.
      """
  
      def _each_isinstance(spec, spec_types):
          """Checks if each element of `spec` is instance of `spec_types`."""
          return all(
              [isinstance(s, spec_types) for s in tf.nest.flatten(spec)]
          )
  
      for spec, label in (
          (time_step_spec, "time_step_spec"),
          (action_spec, "action_spec"),
          (info_spec, "info_spec"),
      ):
          if not _each_isinstance(spec, tf.TypeSpec):
              raise TypeError(
                  "{} has to contain TypeSpec (TensorSpec, "
                  "SparseTensorSpec, etc) objects, but received: {}".format(
                      label, spec
                  )
              )
  
      self._time_step_spec = time_step_spec
      self._action_spec = action_spec
      self._info_spec = info_spec
      self._policy_state_spec = policy_state_spec
      self._trajectory_spec = trajectory.Trajectory(
          step_type=time_step_spec.step_type,
          observation=time_step_spec.observation,
          action=action_spec,
          policy_info=info_spec,
          next_step_type=time_step_spec.step_type,
          reward=time_step_spec.reward,
          discount=time_step_spec.discount,
      )
  
      if use_half_transition:
          next_time_step_spec = time_step_spec._replace(
              observation=tensor_spec.TensorSpec(
                  (), dtype=tf.float32, name="observation"
              )
          )
      else:
          next_time_step_spec = time_step_spec
      self._transition_spec = trajectory.Transition(
          time_step=time_step_spec,
          action_step=policy_step.PolicyStep(
              action=action_spec,
              state=policy_state_spec,
              info=info_spec,
          ),
          next_time_step=next_time_step_spec,
      )
  
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 1 to create a new DataContext object from inherited base classes: tf with example: obj = DataContext(time_step_spec, action_spec, info_spec, policy_state_spec, use_half_transition)