docstr: Runs algorithm on given test case and verifies result.
docstr_tok: ["Runs","algorithm","on","given","test","case","and","verifies","result","."]
code: def _check_algorithm(
      self, func=None, start_point=None, gtol=1e-4, expected_argmin=None
  ):
      """Runs algorithm on given test case and verifies result."""
      val_grad_func = lambda x: tff.math.value_and_gradient(func, x)
      start_point = tf.constant(start_point, dtype=tf.float64)
      expected_argmin = np.array(expected_argmin, dtype=np.float64)
  
      f_call_ctr = tf.Variable(0, dtype=tf.int32)
  
      def val_grad_func_with_counter(x):
          with tf.compat.v1.control_dependencies(
              [tf.compat.v1.assign_add(f_call_ctr, 1)]
          ):
              return val_grad_func(x)
  
      result = tff.math.optimizer.conjugate_gradient_minimize(
          val_grad_func_with_counter,
          start_point,
          tolerance=gtol,
          max_iterations=200,
      )
      self.evaluate(tf.compat.v1.global_variables_initializer())
      result = self.evaluate(result)
      f_call_ctr = self.evaluate(f_call_ctr)
  
      # Check that minimum is found.
      with self.subTest(name="Position"):
          self.assertAllClose(
              result.position, expected_argmin, rtol=1e-3, atol=1e-3
          )
      # Check that gradient norm is below tolerance.
      grad_norm = np.max(result.objective_gradient)
      with self.subTest(name="GradientNorm"):
          self.assertLessEqual(grad_norm, 100 * gtol)
      # Check that number of function calls, declared by algorithm, is correct.
      with self.subTest(name="NumberOfEvals"):
          self.assertEqual(result.num_objective_evaluations, f_call_ctr)
      # Check returned function and gradient values.
      pos = tf.constant(result.position, dtype=tf.float64)
      f_at_pos, grad_at_pos = self.evaluate(val_grad_func(pos))
      with self.subTest(name="ObjectiveValue"):
          self.assertAllClose(result.objective_value, f_at_pos)
      with self.subTest(name="ObjectiveGradient"):
          self.assertAllClose(result.objective_gradient, grad_at_pos)
      # Check that all converged and none failed.
      with self.subTest(name="AllConverged"):
          self.assertTrue(np.all(result.converged))
      with self.subTest("NoneFailed"):
          self.assertFalse(np.any(result.failed))
  
imports: import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 1 for calling the ConjugateGradientTest obj's underlying member method code with example usage: obj._check_algorithm(func, start_point, gtol, expected_argmin) and returns: val_grad_func