class_docstr: Test class for conjugate gradient optimizer.
class_docstr_tok: ["Test","class","for","conjugate","gradient","optimizer","."]
docstr: Test if line search stops when loss is decreasing, and constraint is satisfied.
docstr_tok: ["Test","if","line","search","stops","when","loss","is","decreasing",",","and","constraint","is","satisfied","."]
code: def test_line_search_should_stop(self):
      """Test if line search stops when loss is decreasing, and constraint is satisfied."""  # noqa: E501
      p1 = torch.tensor([0.1])
      p2 = torch.tensor([0.1])
      params = [p1, p2]
      optimizer = ConjugateGradientOptimizer(params, 0.01)
      expected_num_steps = 1
  
      loss_calls = 0
      first_time = True
  
      def f_loss():
          nonlocal loss_calls, first_time
          if first_time:
              first_time = False
          else:
              loss_calls += 1
  
          return -torch.tensor(loss_calls)
  
      kl_calls = 0
  
      def f_constrint():
          nonlocal kl_calls
          kl_calls += 1
          return -torch.tensor(kl_calls)
  
      descent_step = torch.tensor([0.05, 0.05])
      optimizer._backtracking_line_search(
          params, descent_step, f_loss, f_constrint
      )
  
      assert loss_calls == expected_num_steps
      assert kl_calls == expected_num_steps
  
imports: import pickle
  import numpy
  import pytest
  import torch
  from garage.torch.optimizers.conjugate_gradient_optimizer import ConjugateGradientOptimizer
  from garage.torch.optimizers.conjugate_gradient_optimizer import _build_hessian_vector_product
  from garage.torch.optimizers.conjugate_gradient_optimizer import _conjugate_gradient
label_desc: Use image node_id 1 for calling the TestTorchConjugateGradientOptimizer obj's underlying member method code with example usage: obj.test_line_search_should_stop() and returns: unknown, unknown