code: def test_against_sdeint(
      sde_cls, sde_type, method, options, dt, rtol, atol, len_ts
  ):
      # Skipping below, since method not supported for corresponding noise types.
      if sde_cls.noise_type == NOISE_TYPES.general and method in (
          METHODS.milstein,
          METHODS.srk,
      ):
          return
  
      d = 3
      m = {
          NOISE_TYPES.scalar: 1,
          NOISE_TYPES.diagonal: d,
          NOISE_TYPES.general: 2,
          NOISE_TYPES.additive: 2,
      }[sde_cls.noise_type]
      batch_size = 4
      ts = torch.linspace(
          0.0, 1.0, len_ts, device=device, dtype=torch.float64
      )
      t0 = ts[0]
      t1 = ts[-1]
      y0 = torch.full(
          (batch_size, d),
          0.1,
          device=device,
          dtype=torch.float64,
          requires_grad=True,
      )
      sde = sde_cls(d=d, m=m, sde_type=sde_type).to(
          device, torch.float64
      )
  
      if method == METHODS.srk:
          levy_area_approximation = LEVY_AREA_APPROXIMATIONS.space_time
      else:
          levy_area_approximation = LEVY_AREA_APPROXIMATIONS.none
      bm = torchsde.BrownianInterval(
          t0=t0,
          t1=t1,
          size=(batch_size, m),
          dtype=torch.float64,
          device=device,
          levy_area_approximation=levy_area_approximation,
      )
  
      if method == METHODS.reversible_heun:
          adjoint_method = METHODS.adjoint_reversible_heun
          adjoint_options = options
      else:
          adjoint_method = None
          adjoint_options = None
  
      ys_true = torchsde.sdeint(
          sde, y0, ts, dt=dt, method=method, bm=bm, options=options
      )
      grad = torch.randn_like(ys_true)
      ys_true.backward(grad)
  
      true_grad = torch.cat(
          [y0.grad.view(-1)]
          + [param.grad.view(-1) for param in sde.parameters()]
      )
      y0.grad.zero_()
      for param in sde.parameters():
          param.grad.zero_()
  
      ys_test = torchsde.sdeint_adjoint(
          sde,
          y0,
          ts,
          dt=dt,
          method=method,
          bm=bm,
          adjoint_method=adjoint_method,
          options=options,
          adjoint_options=adjoint_options,
      )
      ys_test.backward(grad)
      test_grad = torch.cat(
          [y0.grad.view(-1)]
          + [param.grad.view(-1) for param in sde.parameters()]
      )
  
      torch.testing.assert_allclose(ys_true, ys_test)
      torch.testing.assert_allclose(
          true_grad, test_grad, rtol=rtol, atol=atol
      )
  
file_path: torchsde/tests/test_adjoint.py
imports: import sys
  import pytest
  import torch
  import torchsde
  from torchsde.settings import LEVY_AREA_APPROXIMATIONS, METHODS, NOISE_TYPES, SDE_TYPES
  from .None import utils
  from .None import problems
label_desc: Use image node_id 4 for calling a global function with example usage: test_against_sdeint(sde_cls, sde_type, method, options, dt, rtol, atol, len_ts) without return types