code: def test_against_numerical(
      sde_cls, sde_type, method, options, adaptive
  ):
      # 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
      t0, t1 = ts = torch.tensor([0.0, 0.5], device=device)
      dt = 1e-3
      y0 = torch.full((batch_size, d), 0.1, device=device)
      sde = sde_cls(d=d, m=m, sde_type=sde_type).to(device)
  
      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=dtype,
          device=device,
          levy_area_approximation=levy_area_approximation,
      )
  
      if method == METHODS.reversible_heun:
          tol = 1e-6
          adjoint_method = METHODS.adjoint_reversible_heun
          adjoint_options = options
      else:
          tol = 1e-2
          adjoint_method = None
          adjoint_options = None
  
      def func(inputs, modules):
          y0, sde = inputs[0], modules[0]
          ys = torchsde.sdeint_adjoint(
              sde,
              y0,
              ts,
              dt=dt,
              method=method,
              adjoint_method=adjoint_method,
              adaptive=adaptive,
              bm=bm,
              options=options,
              adjoint_options=adjoint_options,
          )
          return (ys[-1] ** 2).sum(dim=1).mean(dim=0)
  
      # `grad_inputs=True` also works, but we really only care about grad wrt params and want fast tests.
      utils.gradcheck(
          func, y0, sde, eps=1e-6, rtol=tol, atol=tol, grad_params=True
      )
  
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 2 for calling a global function with example usage: test_against_numerical(sde_cls, sde_type, method, options, adaptive) and returns: unknown