autopdex.dae.discrete_value_with_derivatives

autopdex.dae.discrete_value_with_derivatives = <jax._src.custom_derivatives.custom_jvp object>[source]

Evaluate the discrete state value with custom derivative propagation.

This function returns the discrete state value q, but it is equipped with a custom Jacobian-vector product (JVP) rule to correctly propagate derivative information through discrete operations. This custom derivative rule is designed to support higher-order derivative calculations by processing a sequence of derivative values provided in q_derivs.

In the absence of derivative information (i.e. when q_derivs is empty), the derivative is taken to be q_dot. When derivative information is available, the first derivative in q_derivs is used recursively along with the time derivative t_dot to compute the overall derivative contribution.

It is used to construct a differentiable q_fun based on a value and its derivative defined by an integration rule, e.g.:

def diffable_q_fun(t): # q_ts is a tuple of (q, q_t, q_tt, ...) coming from the integrator
  return {key: discrete_value_with_derivatives(t, q_ts[key][0], q_ts[key][1:]) for key in template.keys()}
Parameters:
  • t – Scalar representing the time variable.

  • q – The discrete state value.

  • q_derivs – A sequence (e.g., list or tuple) of derivative values corresponding to q. The first element represents the first derivative, with subsequent elements (if any) representing higher-order derivatives.

Returns:

  • If no derivative information is provided (q_derivs is empty): returns q_dot.

  • Otherwise: returns q_dot + (discrete_value_with_derivatives(t, first_deriv, remaining_derivs) * t_dot), where first_deriv is the first element of q_derivs and remaining_derivs contains any higher-order derivatives.

Return type:

The discrete state value q. The custom derivative rule ensures that during differentiation the returned derivative follows the form