code: def fn_with_name(
      optimizer_name,
      learning_rate_schedule="constant",
      cosine_decay_steps=None,
  ):
      """Returns an optimizer_fn with the given name.
  
      Args:
        optimizer_name: Optimizer name string for identifying the optimizer. Either
          'adagrad', 'adam', 'momentum', or 'sgd'.
        learning_rate_schedule: Type of learning rate schedule to use. Opened for
          future extensions.
        cosine_decay_steps: See `Cosine`.
  
      Returns:
        An optimizer_fn which takes a `learning_rate` scalar `Tensor` argument and
          returns an `Optimizer` instance.
  
      Raises:
        ValueError: If `optimizer_name` is invalid.
      """
  
      optimizers = {
          "adagrad": tf.train.AdagradOptimizer,
          "adam": tf.train.AdamOptimizer,
          "lazy_adam": tf.contrib.opt.LazyAdamOptimizer,
          "momentum": functools.partial(
              tf.train.MomentumOptimizer, momentum=0.9
          ),
          "rmsprop": tf.train.RMSPropOptimizer,
          "sgd": tf.train.GradientDescentOptimizer,
      }
      optimizer_name = optimizer_name.lower()
      if optimizer_name not in optimizers:
          raise ValueError(
              "Invalid optimizer '{}'".format(optimizer_name)
          )
      optimizer_fn = optimizers[optimizer_name]
      schedules = {
          "constant": Constant(),
          "cosine": Cosine(decay_steps=cosine_decay_steps, alpha=0.0),
      }
      schedule_name = learning_rate_schedule.lower()
      if schedule_name not in schedules:
          raise ValueError(
              "Invalid learning_rate_schedule '{}'".format(
                  schedule_name
              )
          )
      schedule = schedules[schedule_name]
  
      def _optimizer_with_schedule(learning_rate):
          learning_rate = schedule.apply(learning_rate)
          optimizer = optimizer_fn(learning_rate)
          return optimizer, learning_rate
  
      return _optimizer_with_schedule
  
file_path: adanet/research/improve_nas/trainer/optimizer.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import functools
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: fn_with_name(optimizer_name, learning_rate_schedule, cosine_decay_steps) and returns: _optimizer_with_schedule, optimizer,  learning_rate