class_docstr: Tests for get_gradient method.
  
  Since get_gradients must run in graph mode, the method is tested within
  the Estimator framework.
class_docstr_tok: ["Tests","for","get_gradient","method",".","Since","get_gradients","must","run","in","graph","mode",",","the","method","is","tested","within","the","Estimator","framework","."]
docstr: Tests that DP optimizers work with tf.estimator.
code: def testClippingNorm(self, optimizer_class, requires_varlist):
      """Tests that DP optimizers work with tf.estimator."""
  
      true_weights = np.array([[6.0], [0.0], [0], [0]]).astype(
          np.float32
      )
      true_bias = np.array([0]).astype(np.float32)
  
      train_data = np.array([[1.0, 0.0, 0.0, 0.0]]).astype(np.float32)
      train_labels = np.matmul(train_data, true_weights) + true_bias
  
      def train_input_fn():
          return tf.data.Dataset.from_tensor_slices(
              (train_data, train_labels)
          ).batch(1)
  
      unclipped_linear_regressor = tf_estimator.Estimator(
          model_fn=self._make_linear_model_fn(
              optimizer_class=optimizer_class,
              l2_norm_clip=1.0e9,
              noise_multiplier=0.0,
              num_microbatches=1,
              requires_varlist=requires_varlist,
              learning_rate=1.0,
          )
      )
      unclipped_linear_regressor.train(input_fn=train_input_fn, steps=1)
  
      kernel_value = unclipped_linear_regressor.get_variable_value(
          "dense/kernel"
      )
      bias_value = unclipped_linear_regressor.get_variable_value(
          "dense/bias"
      )
      global_norm = np.linalg.norm(
          np.concatenate((kernel_value, [bias_value]))
      )
  
      clipped_linear_regressor = tf_estimator.Estimator(
          model_fn=self._make_linear_model_fn(
              optimizer_class=optimizer_class,
              l2_norm_clip=1.0,
              noise_multiplier=0.0,
              num_microbatches=1,
              requires_varlist=requires_varlist,
              learning_rate=1.0,
          )
      )
      clipped_linear_regressor.train(input_fn=train_input_fn, steps=1)
  
      self.assertAllClose(
          clipped_linear_regressor.get_variable_value("dense/kernel"),
          kernel_value / global_norm,
          atol=0.001,
      )
      self.assertAllClose(
          clipped_linear_regressor.get_variable_value("dense/bias"),
          bias_value / global_norm,
          atol=0.001,
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow import estimator
  from tensorflow_privacy.privacy.optimizers import dp_optimizer_keras
  from tensorflow_privacy.privacy.optimizers import dp_optimizer_keras_vectorized
label_desc: Use image node_id 3 for calling the DPOptimizerGetGradientsTest obj's underlying member method code with example usage: obj.testClippingNorm(optimizer_class, requires_varlist) and returns: tf