# Path: tensorflow_constrained_optimization/python/graph_and_eager_test_case.py
# class _EagerPlaceholder(object):
# class _GraphWrappedSession(object):
# class _EagerWrappedSession(object):
# class GraphAndEagerTestCase(tf.test.TestCase):
#   def __init__(self):
#   def set(self, tensor):
#   def __call__(self):
#   def __init__(self, session):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def wrapped_placeholder(self, dtype, shape=None, name=None):
#   def wrapped_session(self):
# 
# Path: tensorflow_constrained_optimization/python/train/lagrangian_model_optimizer.py
# class _LagrangianModelFormulation(lagrangian_optimizer._LagrangianFormulation):  # pylint: disable=protected-access
#   def __init__(self, create_fn, dual_scale=1.0, variable_fn=tf.Variable):
#   def state(self):
#   def create_state(self, num_constraints):
# def create_lagrangian_model_loss(minimization_problem,
#                                  create_fn,
#                                  dual_scale=1.0,
#                                  variable_fn=tf.Variable):
# 
# Path: tensorflow_constrained_optimization/python/train/test_util.py
# class ConstantMinimizationProblem(
#     constrained_minimization_problem.ConstrainedMinimizationProblem):
#   def __init__(self, constraints):
#   def objective(self):
#   def num_constraints(self):
#   def constraints(self):
#   def variables(self):


import numpy as np
import tensorflow as tf
from six.moves import xrange  # pylint: disable=redefined-builtin
from tensorflow_constrained_optimization.python import graph_and_eager_test_case
from tensorflow_constrained_optimization.python.train import lagrangian_model_optimizer
from tensorflow_constrained_optimization.python.train import test_util
    with self.wrapped_session() as session:
      while len(states) < len(expected_states):
        session.run_ops(update_ops_fn)
        states.append(session.run(state_variable))
        session.run_ops(train_op_fn)

    # Compare the observed sequence of Lagrange multipliers to the expected one.
    for expected, actual in zip(expected_states, states):
      self.assertAllClose(expected, actual, rtol=0, atol=1e-6)

  def test_lagrangian_optimizer(self):
    """Tests that the Lagrangian model works with the usual Lagrangian."""
    minimization_problem = test_util.ConstantMinimizationProblem(
        np.array([0.6, -0.1, 0.4]))

    # The second element alternates between 0 and -0.1 since the
    # _LagrangianModelFormulation takes the absolute value of the Lagrange
    # multipliers before using them.
    expected_states = [
        np.array([0.0, 0.0, 0.0]),
        np.array([0.6, -0.1, 0.4]),
        np.array([1.2, 0.0, 0.8]),
        np.array([1.8, -0.1, 1.2]),
    ]

    self._test_helper(minimization_problem, Lagrangian, expected_states)

  def test_lagrangian_model_optimizer(self):
    """Tests that the Lagrangian model works with a linear Lagrangian."""
    gradient = np.array([0.6, -0.1, 0.4])

# Path: tensorflow_constrained_optimization/python/graph_and_eager_test_case.py
# class _EagerPlaceholder(object):
# class _GraphWrappedSession(object):
# class _EagerWrappedSession(object):
# class GraphAndEagerTestCase(tf.test.TestCase):
#   def __init__(self):
#   def set(self, tensor):
#   def __call__(self):
#   def __init__(self, session):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def wrapped_placeholder(self, dtype, shape=None, name=None):
#   def wrapped_session(self):
# 
# Path: tensorflow_constrained_optimization/python/train/lagrangian_model_optimizer.py
# class _LagrangianModelFormulation(lagrangian_optimizer._LagrangianFormulation):  # pylint: disable=protected-access
#   def __init__(self, create_fn, dual_scale=1.0, variable_fn=tf.Variable):
#   def state(self):
#   def create_state(self, num_constraints):
# def create_lagrangian_model_loss(minimization_problem,
#                                  create_fn,
#                                  dual_scale=1.0,
#                                  variable_fn=tf.Variable):
# 
# Path: tensorflow_constrained_optimization/python/train/test_util.py
# class ConstantMinimizationProblem(
#     constrained_minimization_problem.ConstrainedMinimizationProblem):
#   def __init__(self, constraints):
#   def objective(self):
#   def num_constraints(self):
#   def constraints(self):
#   def variables(self):


# Path: tensorflow_constrained_optimization/python/train/lagrangian_model_optimizer_test.py
import numpy as np
import tensorflow as tf
from six.moves import xrange  # pylint: disable=redefined-builtin
from tensorflow_constrained_optimization.python import graph_and_eager_test_case
from tensorflow_constrained_optimization.python.train import lagrangian_model_optimizer
from tensorflow_constrained_optimization.python.train import test_util

    with self.wrapped_session() as session:
      while len(states) < len(expected_states):
        session.run_ops(update_ops_fn)
        states.append(session.run(state_variable))
        session.run_ops(train_op_fn)

    # Compare the observed sequence of Lagrange multipliers to the expected one.
    for expected, actual in zip(expected_states, states):
      self.assertAllClose(expected, actual, rtol=0, atol=1e-6)

  def test_lagrangian_optimizer(self):
    """Tests that the Lagrangian model works with the usual Lagrangian."""
    minimization_problem = test_util.ConstantMinimizationProblem(
        np.array([0.6, -0.1, 0.4]))

    # The second element alternates between 0 and -0.1 since the
    # _LagrangianModelFormulation takes the absolute value of the Lagrange
    # multipliers before using them.
    expected_states = [
        np.array([0.0, 0.0, 0.0]),
        np.array([0.6, -0.1, 0.4]),
        np.array([1.2, 0.0, 0.8]),
        np.array([1.8, -0.1, 1.2]),
    ]

    self._test_helper(minimization_problem, Lagrangian, expected_states)

  def test_lagrangian_model_optimizer(self):
    """Tests that the Lagrangian model works with a linear Lagrangian."""
    gradient = np.array([0.6, -0.1, 0.4])

    minimization_problem = test_util.ConstantMinimizationProblem(gradient)