# Path: disentanglement_lib/methods/shared/optimizers.py
# def make_optimizer(optimizer_fn, learning_rate):
# def make_vae_optimizer(optimizer_fn=gin.REQUIRED, learning_rate=None):
# def make_discriminator_optimizer(optimizer_fn=gin.REQUIRED, learning_rate=None):


from absl.testing import parameterized
from disentanglement_lib.methods.shared import optimizers
from six.moves import range
import tensorflow.compat.v1 as tf
import gin.tf.external_configurables  # pylint: disable=unused-import
import gin.tf
  # Piecewise constant learning rate.
  bindings = [
      "vae_optimizer.optimizer_fn = @GradientDescentOptimizer",
      "vae_optimizer.learning_rate = @piecewise_constant",
      "piecewise_constant.boundaries = (3, 5)",
      "piecewise_constant.values = (0.2, 0.1, 0.01)",
  ]
  yield (bindings, 0.01)

  # Exponential decay learning rate.
  bindings = [
      "vae_optimizer.optimizer_fn = @GradientDescentOptimizer",
      "vae_optimizer.learning_rate = @exponential_decay",
      "exponential_decay.learning_rate = 0.1",
      "exponential_decay.decay_steps = 1",
      "exponential_decay.decay_rate = 0.9",
  ]
  yield (bindings, 0.03486784401)


class OptimizerTest(parameterized.TestCase, tf.test.TestCase):

  @parameterized.parameters(list(_make_vae_optimizer_configs()))
  def test_vae_optimizer(self, gin_bindings, expected_learning_rate):
    gin.parse_config_files_and_bindings([], gin_bindings)

    with self.test_session():
      x = tf.Variable(0.0)
      y = tf.pow(x + 2.0, 2.0)
      global_step = tf.train.get_or_create_global_step()

# Path: disentanglement_lib/methods/shared/optimizers.py
# def make_optimizer(optimizer_fn, learning_rate):
# def make_vae_optimizer(optimizer_fn=gin.REQUIRED, learning_rate=None):
# def make_discriminator_optimizer(optimizer_fn=gin.REQUIRED, learning_rate=None):


# Path: disentanglement_lib/methods/shared/optimizers_test.py
from absl.testing import parameterized
from disentanglement_lib.methods.shared import optimizers
from six.moves import range
import tensorflow.compat.v1 as tf
import gin.tf.external_configurables  # pylint: disable=unused-import
import gin.tf

  # Piecewise constant learning rate.
  bindings = [
      "vae_optimizer.optimizer_fn = @GradientDescentOptimizer",
      "vae_optimizer.learning_rate = @piecewise_constant",
      "piecewise_constant.boundaries = (3, 5)",
      "piecewise_constant.values = (0.2, 0.1, 0.01)",
  ]
  yield (bindings, 0.01)

  # Exponential decay learning rate.
  bindings = [
      "vae_optimizer.optimizer_fn = @GradientDescentOptimizer",
      "vae_optimizer.learning_rate = @exponential_decay",
      "exponential_decay.learning_rate = 0.1",
      "exponential_decay.decay_steps = 1",
      "exponential_decay.decay_rate = 0.9",
  ]
  yield (bindings, 0.03486784401)


class OptimizerTest(parameterized.TestCase, tf.test.TestCase):

  @parameterized.parameters(list(_make_vae_optimizer_configs()))
  def test_vae_optimizer(self, gin_bindings, expected_learning_rate):
    gin.parse_config_files_and_bindings([], gin_bindings)

    with self.test_session():
      x = tf.Variable(0.0)
      y = tf.pow(x + 2.0, 2.0)
      global_step = tf.train.get_or_create_global_step()

      optimizer = optimizers.make_vae_optimizer()