class_docstr: Tests for discrete_policy_gradient op.
class_docstr_tok: ["Tests","for","discrete_policy_gradient","op","."]
code: def testGradients(self):
      with self.test_session() as sess:
          policy_logits = tf.constant(
              [[0, 1], [0, 1], [1, 1], [0, 100]], dtype=tf.float32
          )
          action_values = tf.constant([0, 1, 2, 1], dtype=tf.float32)
          actions = tf.constant([0, 0, 1, 1], dtype=tf.int32)
          loss = pg_ops.discrete_policy_gradient(
              policy_logits, actions, action_values
          )
          total_loss = tf.reduce_sum(loss)
          gradients = tf.gradients([total_loss], [policy_logits])
          grad_policy_logits = sess.run(gradients[0])
          #  The final case (with large logits), runs out of precision and gets
          #  truncated to 0, but isn't `nan`.
          self.assertAllClose(
              grad_policy_logits,
              [[0, 0], [-0.731, 0.731], [1, -1], [0, 0]],
              atol=1e-4,
          )
  
          self.assertAllEqual(
              tf.gradients([total_loss], [actions, action_values]),
              [None, None],
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import numpy
  from six.moves import xrange
  import tensorflow.compat.v1
  import tree
  from trfl import discrete_policy_gradient_ops
label_desc: Use image node_id 2 for calling the DiscretePolicyGradientTest obj's underlying member method code with example usage: obj.testGradients() without return types