class_docstr: Penalized Limited-memory BFGS (L-BFGS) optimizer.
  
  Performs constrained optimization via penalized L-BFGS. The penalty term is
  adaptively adjusted to make sure that the constraint is satisfied.
  
  Args:
      max_opt_itr (int): Maximum iteration for update.
      initial_penalty (float): Initial penalty.
      min_penalty (float): Minimum penalty allowed. Penalty will be clipped
          if lower than this value.
      max_penalty (float): Maximum penalty allowed. Penalty will be clipped
          if higher than this value.
      increase_penalty_factor (float): Factor to increase penalty in each
          penalty iteration.
      decrease_penalty_factor (float): Factor to decrease penalty in each
          penalty iteration.
      max_penalty_itr (int): Maximum penalty iterations to perform.
      adapt_penalty (bool): Whether the penalty is adaptive or not. If false,
          penalty will not change.
class_docstr_tok: ["Penalized","Limited-memory","BFGS","(","L-BFGS",")","optimizer",".","Performs","constrained","optimization","via","penalized","L-BFGS",".","The","penalty","term","is","adaptively","adjusted","to","make","sure","that","the","constraint","is","satisfied",".","Args",":","max_opt_itr","(","int",")",":","Maximum","iteration","for","update",".","initial_penalty","(","float",")",":","Initial","penalty",".","min_penalty","(","float",")",":","Minimum","penalty","allowed",".","Penalty","will","be","clipped","if","lower","than","this","value",".","max_penalty","(","float",")",":","Maximum","penalty","allowed",".","Penalty","will","be","clipped","if","higher","than","this","value",".","increase_penalty_factor","(","float",")",":","Factor","to","increase","penalty","in","each","penalty","iteration",".","decrease_penalty_factor","(","float",")",":","Factor","to","decrease","penalty","in","each","penalty","iteration",".","max_penalty_itr","(","int",")",":","Maximum","penalty","iterations","to","perform",".","adapt_penalty","(","bool",")",":","Whether","the","penalty","is","adaptive","or","not",".","If","false",",","penalty","will","not","change","."]
docstr: Construct operation graph for the optimizer.
  
  Args:
      loss (tf.Tensor): Loss objective to minimize.
      target (object): Target object to optimize. The object should
          implemenet `get_params()` and `get_param_values`.
      leq_constraint (tuple): It contains a tf.Tensor and a float value.
          The tf.Tensor represents the constraint term, and the float
          value is the constraint value.
      inputs (list[tf.Tensor]): List of input placeholders.
      constraint_name (str): Constraint name for logging.
      name (str): Name scope.
      kwargs (dict): Extra unused keyword arguments. Some optimizers
          have extra input, e.g. KL constraint.
docstr_tok: ["Construct","operation","graph","for","the","optimizer",".","Args",":","loss","(","tf.Tensor",")",":","Loss","objective","to","minimize",".","target","(","object",")",":","Target","object","to","optimize",".","The","object","should","implemenet","`","get_params","(",")","`","and","`","get_param_values","`",".","leq_constraint","(","tuple",")",":","It","contains","a","tf.Tensor","and","a","float","value",".","The","tf.Tensor","represents","the","constraint","term",",","and","the","float","value","is","the","constraint","value",".","inputs","(","list","[","tf.Tensor","]",")",":","List","of","input","placeholders",".","constraint_name","(","str",")",":","Constraint","name","for","logging",".","name","(","str",")",":","Name","scope",".","kwargs","(","dict",")",":","Extra","unused","keyword","arguments",".","Some","optimizers","have","extra","input",",","e.g",".","KL","constraint","."]
code: def update_opt(
      self,
      loss,
      target,
      leq_constraint,
      inputs,
      constraint_name="constraint",
      name="PenaltyLBFGSOptimizer",
      **kwargs,
  ):
      """Construct operation graph for the optimizer.
  
      Args:
          loss (tf.Tensor): Loss objective to minimize.
          target (object): Target object to optimize. The object should
              implemenet `get_params()` and `get_param_values`.
          leq_constraint (tuple): It contains a tf.Tensor and a float value.
              The tf.Tensor represents the constraint term, and the float
              value is the constraint value.
          inputs (list[tf.Tensor]): List of input placeholders.
          constraint_name (str): Constraint name for logging.
          name (str): Name scope.
          kwargs (dict): Extra unused keyword arguments. Some optimizers
              have extra input, e.g. KL constraint.
  
      """
      del kwargs
      params = target.get_params()
      with tf.name_scope(name):
          constraint_term, constraint_value = leq_constraint
          penalty_var = tf.compat.v1.placeholder(
              tf.float32, tuple(), name="penalty"
          )
          penalized_loss = loss + penalty_var * constraint_term
  
          self._target = target
          self._max_constraint_val = constraint_value
          self._constraint_name = constraint_name
  
          def get_opt_output():
              """Helper function to construct graph.
  
              Returns:
                  list[tf.Tensor]: Penalized loss and gradient tensor.
  
              """
              with tf.name_scope("get_opt_output"):
                  grads = tf.gradients(penalized_loss, params)
                  for idx, (grad, param) in enumerate(
                      zip(grads, params)
                  ):
                      if grad is None:
                          grads[idx] = tf.zeros_like(param)
                  flat_grad = flatten_tensor_variables(grads)
                  return [
                      tf.cast(penalized_loss, tf.float64),
                      tf.cast(flat_grad, tf.float64),
                  ]
  
          self._opt_fun = LazyDict(
              f_loss=lambda: compile_function(inputs, loss),
              f_constraint=lambda: compile_function(
                  inputs, constraint_term
              ),
              f_penalized_loss=lambda: compile_function(
                  inputs=inputs + [penalty_var],
                  outputs=[penalized_loss, loss, constraint_term],
              ),
              f_opt=lambda: compile_function(
                  inputs=inputs + [penalty_var],
                  outputs=get_opt_output(),
              ),
          )
  
file_path: garage/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py
imports: from dowel import logger
  import numpy
  import scipy.optimize
  import tensorflow
  from garage.tf import compile_function, flatten_tensor_variables
  from garage.tf.optimizers._dtypes import LazyDict
label_desc: Use image node_id 2 for calling the PenaltyLBFGSOptimizer obj's underlying member method code with example usage: obj.update_opt(loss, target, leq_constraint, inputs, constraint_name, name) and returns: list