code: def odeint_event(
      func,
      y0,
      t0,
      *,
      event_fn,
      reverse_time=False,
      odeint_interface=odeint,
      **kwargs,
  ):
      """Automatically links up the gradient from the event time."""
  
      if reverse_time:
          t = torch.cat([t0.reshape(-1), t0.reshape(-1).detach() - 1.0])
      else:
          t = torch.cat([t0.reshape(-1), t0.reshape(-1).detach() + 1.0])
  
      event_t, solution = odeint_interface(
          func, y0, t, event_fn=event_fn, **kwargs
      )
  
      # Dummy values for rtol, atol, method, and options.
      shapes, _func, _, t, _, _, _, _, event_fn, _ = _check_inputs(
          func, y0, t, 0.0, 0.0, None, None, event_fn, SOLVERS
      )
  
      if shapes is not None:
          state_t = torch.cat([s[-1].reshape(-1) for s in solution])
      else:
          state_t = solution[-1]
  
      # Event_fn takes in negated time value if reverse_time is True.
      if reverse_time:
          event_t = -event_t
  
      event_t, state_t = ImplicitFnGradientRerouting.apply(
          _func, event_fn, event_t, state_t
      )
  
      # Return the user expected time value.
      if reverse_time:
          event_t = -event_t
  
      if shapes is not None:
          state_t = _flat_to_shape(state_t, (), shapes)
          solution = tuple(
              torch.cat([s[:-1], s_t[None]], dim=0)
              for s, s_t in zip(solution, state_t)
          )
      else:
          solution = torch.cat([solution[:-1], state_t[None]], dim=0)
  
      return event_t, solution
  
file_path: torchdiffeq/torchdiffeq/_impl/odeint.py
imports: import torch
  from torch.autograd.functional import vjp
  from .dopri5 import Dopri5Solver
  from .bosh3 import Bosh3Solver
  from .adaptive_heun import AdaptiveHeunSolver
  from .fehlberg2 import Fehlberg2
  from .fixed_grid import Euler, Midpoint, Heun3, RK4
  from .fixed_adams import AdamsBashforth, AdamsBashforthMoulton
  from .dopri8 import Dopri8Solver
  from .scipy_wrapper import ScipyWrapperODESolver
  from .misc import _check_inputs, _flat_to_shape
  from .interp import _interp_evaluate
label_desc: Use image node_id 3 for calling a global function with example usage: odeint_event(func, y0, t0) and returns: event_t,  solution