docstr: Test against dopri5
docstr_tok: ["Test","against","dopri5"]
code: def test_adjoint_against_odeint(self):
      """
      Test against dopri5
      """
      for device in DEVICES:
          for ode in PROBLEMS:
              for t_grad in (True, False):
                  if ode == "constant":
                      eps = 1e-12
                  elif ode == "linear":
                      eps = 1e-5
                  elif ode == "sine":
                      eps = 5e-3
                  else:
                      raise RuntimeError
  
                  with self.subTest(
                      device=device, ode=ode, t_grad=t_grad
                  ):
                      f, y0, t_points, _ = construct_problem(
                          device=device, ode=ode
                      )
                      t_points.requires_grad_(t_grad)
  
                      ys = torchdiffeq.odeint(
                          f, y0, t_points, rtol=1e-9, atol=1e-12
                      )
                      torch.manual_seed(0)
                      gradys = torch.rand_like(ys)
                      ys.backward(gradys)
  
                      reg_y0_grad = y0.grad.clone()
                      reg_t_grad = (
                          t_points.grad.clone() if t_grad else None
                      )
                      reg_params_grads = []
                      for param in f.parameters():
                          reg_params_grads.append(param.grad.clone())
  
                      y0.grad.zero_()
                      if t_grad:
                          t_points.grad.zero_()
                      for param in f.parameters():
                          param.grad.zero_()
  
                      ys = torchdiffeq.odeint_adjoint(
                          f, y0, t_points, rtol=1e-9, atol=1e-12
                      )
                      ys.backward(gradys)
  
                      adj_y0_grad = y0.grad
                      adj_t_grad = t_points.grad if t_grad else None
                      adj_params_grads = []
                      for param in f.parameters():
                          adj_params_grads.append(param.grad)
  
                      self.assertLess(
                          max_abs(reg_y0_grad - adj_y0_grad), eps
                      )
                      if t_grad:
                          self.assertLess(
                              max_abs(reg_t_grad - adj_t_grad), eps
                          )
                      for reg_grad, adj_grad in zip(
                          reg_params_grads, adj_params_grads
                      ):
                          self.assertLess(
                              max_abs(reg_grad - adj_grad), eps
                          )
  
file_path: torchdiffeq/tests/gradient_tests.py
imports: import unittest
  import torch
  import torchdiffeq
  from problems import construct_problem, PROBLEMS, DEVICES, METHODS
label_desc: Use image node_id 3 for calling the TestGradient obj's underlying member method code with example usage: obj.test_adjoint_against_odeint() without return types