(func, y0, t0, *, event_fn, reverse_time=False, odeint_interface=odeint, **kwargs)
return event_t, solution
Automatically links up the gradient from the event time.
Automatically links up the gradient from the event time.
Automatically links up the gradient from the event time .
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
def odeint_event ( func , y0 , t0 , * , event_fn , reverse_time = False , odeint_interface = odeint , * * kwargs ) : 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