docstr: Tests that optimizers can handle variables whose gradients are None.
docstr_tok: ["Tests","that","optimizers","can","handle","variables","whose","gradients","are","None","."]
code: def testNoneGradients(self, cls, num_microbatches, expected_answer):
      """Tests that optimizers can handle variables whose gradients are None."""
      del expected_answer  # Unused.
  
      with self.cached_session() as sess:
          var0 = tf.Variable([1.0, 2.0])
          data0 = tf.Variable(
              [[3.0, 4.0], [5.0, 6.0], [7.0, 8.0], [-1.0, 0.0]]
          )
          # Create a string variable whose gradient will be None.
          extra_variable = tf.Variable(
              "foo", trainable=True, dtype=tf.string
          )
  
          dp_sum_query = gaussian_query.GaussianSumQuery(1.0e9, 0.0)
  
          opt = cls(
              dp_sum_query,
              num_microbatches=num_microbatches,
              learning_rate=2.0,
          )
  
          self.evaluate(tf.compat.v1.global_variables_initializer())
          # Fetch params to validate initial values
          self.assertAllClose([1.0, 2.0], self.evaluate(var0))
  
          minimize_op = opt.minimize(
              loss=self._loss(data0, var0),
              var_list=[var0, extra_variable],
          )
          sess.run(minimize_op)
  
imports: import os
  import unittest
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow import estimator
  from tensorflow.compat.v1 import estimator
  from tensorflow_privacy.privacy.dp_query import gaussian_query
  from tensorflow_privacy.privacy.optimizers import dp_optimizer
label_desc: Use image node_id 13 for calling the DPOptimizerTest obj's underlying member method code with example usage: obj.testNoneGradients(cls, num_microbatches, expected_answer) without return types