code: def testCriticLossNStep(self):
      agent = categorical_dqn_agent.CategoricalDqnAgent(
          self._time_step_spec,
          self._action_spec,
          self._dummy_categorical_net,
          self._optimizer,
          n_step_update=2,
      )
  
      observations = tf.constant([[1, 2], [3, 4]], dtype=tf.float32)
      time_steps = ts.restart(observations, batch_size=2)
  
      actions = tf.constant([0, 1], dtype=tf.int32)
      action_steps = policy_step.PolicyStep(actions)
  
      rewards = tf.constant([10, 20], dtype=tf.float32)
      discounts = tf.constant([0.9, 0.9], dtype=tf.float32)
      next_observations = tf.constant(
          [[5, 6], [7, 8]], dtype=tf.float32
      )
      next_time_steps = ts.transition(
          next_observations, rewards, discounts
      )
  
      third_observations = tf.constant(
          [[9, 10], [11, 12]], dtype=tf.float32
      )
      third_time_steps = ts.transition(
          third_observations, rewards, discounts
      )
  
      experience1 = trajectory.from_transition(
          time_steps, action_steps, next_time_steps
      )
      experience2 = trajectory.from_transition(
          next_time_steps, action_steps, third_time_steps
      )
      experience3 = trajectory.from_transition(
          third_time_steps, action_steps, third_time_steps
      )
  
      experience = tf.nest.map_structure(
          lambda x, y, z: tf.stack([x, y, z], axis=1),
          experience1,
          experience2,
          experience3,
      )
  
      loss_info = agent._loss(experience)
  
      # discounted_returns should evaluate to 10 + 0.9 * 10 = 19 and
      # 20 + 0.9 * 20 = 38.
      evaluated_discounted_returns = self.evaluate(
          agent._discounted_returns
      )
      self.assertAllClose(
          evaluated_discounted_returns, [[19], [38]], atol=1e-4
      )
  
      # Both final_value_discount values should be 0.9 * 0.9 = 0.81.
      evaluated_final_value_discount = self.evaluate(
          agent._final_value_discount
      )
      self.assertAllClose(
          evaluated_final_value_discount, [[0.81], [0.81]], atol=1e-4
      )
  
      # Due to the constant initialization of the DummyCategoricalNet, we can
      # expect the same loss every time.
      expected_loss = 2.19525
      self.evaluate(tf.compat.v1.global_variables_initializer())
      evaluated_loss = self.evaluate(loss_info).loss
      self.assertAllClose(evaluated_loss, expected_loss, atol=1e-4)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow
  from tf_agents.agents.categorical_dqn import categorical_dqn_agent
  from tf_agents.networks import categorical_q_network
  from tf_agents.networks import network
  from tf_agents.networks import q_rnn_network
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import test_utils
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import common
label_desc: Use image node_id 9 for calling the CategoricalDqnAgentTest obj's underlying member method code with example usage: obj.testCriticLossNStep() without return types