class_docstr: Test class for conjugate gradient optimizer.
class_docstr_tok: ["Test","class","for","conjugate","gradient","optimizer","."]
docstr: Line search step size should always decrease.
docstr_tok: ["Line","search","step","size","should","always","decrease","."]
code: def test_line_search_step_size_should_decrease(self):
      """Line search step size should always decrease."""
      p1 = torch.tensor([0.1])
      p2 = torch.tensor([0.1])
      params = [p1, p2]
      optimizer = ConjugateGradientOptimizer(params, 0.01)
      p1_history = []
      p2_history = []
      loss = 0
  
      first_time = True
  
      def f_loss():
          nonlocal loss, first_time
          if first_time:
              first_time = False
          else:
              p1_history.append(p1.clone())
              p2_history.append(p2.clone())
              loss += 1
  
          return torch.tensor(loss)
  
      def f_constrint():
          return torch.tensor(0)
  
      descent_step = torch.tensor([0.05, 0.05])
      optimizer._backtracking_line_search(
          params, descent_step, f_loss, f_constrint
      )
  
      p1_steps = []
      p2_steps = []
      for i in range(len(p1_history) - 1):
          p1_steps.append(p1_history[i + 1] - p1_history[i])
          p2_steps.append(p2_history[i + 1] - p2_history[i])
  
      for i in range(len(p1_steps) - 1):
          assert p1_steps[i] > p1_steps[i + 1]
          assert p2_steps[i] > p2_steps[i + 1]
  
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 2 for calling the TestTorchConjugateGradientOptimizer obj's underlying member method code with example usage: obj.test_line_search_step_size_should_decrease() and returns: torch, torch