code: def make_gaussian_optimizer_class(cls):
      """Given a subclass of `tf.compat.v1.train.Optimizer`, returns a subclass using DP-SGD with Gaussian averaging.
  
      Args:
        cls: Class from which to derive a DP subclass. Should be a subclass of
          `tf.compat.v1.train.Optimizer`.
  
      Returns:
        A subclass of `cls` using DP-SGD with Gaussian averaging.
      """
  
      class DPGaussianOptimizerClass(
          make_optimizer_class(cls)
      ):  # pylint: disable=missing-class-docstring
          __doc__ = (
              """DP subclass of `{}`.
  
         You can use this as a differentially private replacement for
         `tf.compat.v1.train.{}`. This optimizer implements DP-SGD using
         the standard Gaussian mechanism.
  
         When instantiating this optimizer, you need to supply several
         DP-related arguments followed by the standard arguments for
         `{}`.
  
         Examples:
  
         ```python
         # Create optimizer.
         opt = {}(l2_norm_clip=1.0, noise_multiplier=0.5, num_microbatches=1,
                  <standard arguments>)
         ```
  
         When using the optimizer, be sure to pass in the loss as a
         rank-one tensor with one entry for each example.
  
         ```python
         # Compute loss as a tensor. Do not call tf.reduce_mean as you
         # would with a standard optimizer.
         loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
             labels=labels, logits=logits)
  
         train_op = opt.minimize(loss, global_step=global_step)
         ```
  
         """
          ).format(
              "tf.compat.v1.train." + cls.__name__,
              cls.__name__,
              cls.__name__,
              "DP"
              + cls.__name__.replace("Optimizer", "GaussianOptimizer"),
          )
  
          def __init__(
              self,
              l2_norm_clip,
              noise_multiplier,
              num_microbatches=None,
              unroll_microbatches=False,
              *args,  # pylint: disable=keyword-arg-before-vararg
              **kwargs,
          ):
              """Initializes the `DPGaussianOptimizerClass`.
  
              Args:
                l2_norm_clip: Clipping norm (max L2 norm of per microbatch gradients).
                noise_multiplier: Ratio of the standard deviation to the clipping norm.
                num_microbatches: Number of microbatches into which each minibatch is
                  split. If `None`, will default to the size of the minibatch, and
                  per-example gradients will be computed.
                unroll_microbatches: If true, processes microbatches within a Python
                  loop instead of a `tf.while_loop`. Can be used if using a
                  `tf.while_loop` raises an exception.
                *args: These will be passed on to the base class `__init__` method.
                **kwargs: These will be passed on to the base class `__init__` method.
              """
              self._l2_norm_clip = l2_norm_clip
              self._noise_multiplier = noise_multiplier
              self._num_microbatches = num_microbatches
              self._base_optimizer_class = cls
  
              dp_sum_query = gaussian_query.GaussianSumQuery(
                  l2_norm_clip, l2_norm_clip * noise_multiplier
              )
  
              super(DPGaussianOptimizerClass, self).__init__(
                  dp_sum_query,
                  num_microbatches,
                  unroll_microbatches,
                  *args,
                  **kwargs,
              )
  
          def get_config(self):
              """Creates configuration for Keras serialization.
  
              This method will be called when Keras creates model checkpoints
              and is necessary so that deserialization can be performed.
  
              Returns:
                A dict object storing arguments to be passed to the __init__ method
                upon deserialization.
              """
  
              config = self._base_optimizer_class.get_config(self)
              config.update(
                  {
                      "l2_norm_clip": self._l2_norm_clip,
                      "noise_multiplier": self._noise_multiplier,
                      "num_microbatches": self._num_microbatches,
                  }
              )
  
              return config
  
      return DPGaussianOptimizerClass
  
imports: from absl import logging
  import tensorflow
  from tensorflow_privacy.privacy.dp_query import gaussian_query
label_desc: Use image node_id 2 for calling a global function with example usage: make_gaussian_optimizer_class(cls) and returns: DPGaussianOptimizerClass, config