class_docstr: Tests for Hager Zhang line search algorithm.
class_docstr_tok: ["Tests","for","Hager","Zhang","line","search","algorithm","."]
code: def _test_eval_count_graph(self, start):
      def get_fn():
          eval_count = tf.Variable(0)
  
          def _fdf(x):
              # Enabling locking is critical here. Otherwise, there are race
              # conditions between various call sites which causes some of the
              # invocations to be missed.
              with tf.control_dependencies(
                  [eval_count.assign_add(1, use_locking=True)]
              ):
                  f = x * x - 2 * x + 1
                  df = 2 * (x - 1)
                  return ValueAndGradient(x, f, df)
  
          return _fdf, eval_count
  
      fdf, counter = get_fn()
      results = hager_zhang(fdf, initial_step_size=tf.constant(start))
      self.evaluate(counter.initializer)
      results = self.evaluate(results)
      actual_evals = self.evaluate(counter)
      self.assertTrue(results.converged)
      self.assertEqual(actual_evals, results.func_evals)
  
imports: import collections
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.optimizer.linesearch.hager_zhang import hager_zhang
label_desc: Use image node_id 8 for calling the HagerZhangTest obj's underlying member method code with example usage: obj._test_eval_count_graph(start) and returns: _fdf,  eval_count, ValueAndGradient