class_docstr: Tests for LBFGS optimization algorithm.
class_docstr_tok: ["Tests","for","LBFGS","optimization","algorithm","."]
docstr: Fails promptly when encountering a non-finite but not -inf objective.
docstr_tok: ["Fails","promptly","when","encountering","a","non-finite","but","not","-inf","objective","."]
code: def test_fail_at_non_finite(self, start):
      """Fails promptly when encountering a non-finite but not -inf objective."""
      # Meaning, +inf (tested here) and nan (not tested separately due to nearly
      # identical code paths) objective values cause a "stop with failure".
      # Actually, there is a further nitpick: +inf is currently treated a little
      # inconsistently.  To wit, if the outer loop hits a +inf, it gives up and
      # reports failure, because it assumes the gradient from a +inf value is
      # garbage and no further progress is possible.  However, if the line search
      # encounters an intermediate +inf, it in some cases knows to just treat it
      # as a large finite value and avoid it.  So in principle, minimizing this
      # test function starting outside the +inf region could stop at the actual
      # minimum at the edge of said +inf region.  However, currently it happens to
      # fail.
      minimum = np.array([1.0, 1.0])
      scales = np.array([2.0, 3.0])
  
      @_make_val_and_grad_fn
      def quadratic_with_spike(x):
          quadratic = tf.reduce_sum(
              scales * tf.math.squared_difference(x, minimum), axis=-1
          )
          square_hole = tf.reduce_all(
              tf.logical_and((x > 0.7), (x < 1.3)), axis=-1
          )
          infty = tf.constant(float("+inf"), dtype=quadratic.dtype)
          answer = tf.where(square_hole, infty, quadratic)
          return answer
  
      start = tf.constant(start)
      results = self.evaluate(
          lbfgs.minimize(
              quadratic_with_spike,
              initial_position=start,
              tolerance=1e-8,
          )
      )
      self.assertAllFalse(results.converged)
      self.assertAllTrue(results.failed)
      self.assertAllFinite(results.position)
  
imports: from absl.testing import parameterized
  import numpy
  from scipy.stats import special_ortho_group
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.optimizer import bfgs_utils
  from tensorflow_probability.python.optimizer import lbfgs
label_desc: Use image node_id 18 for calling the LBfgsTest obj's underlying member method code with example usage: obj.test_fail_at_non_finite(start) and returns: answer