SciML / DifferentialEquations.jl

Multi-language suite for high-performance solvers of differential equations and scientific machine learning (SciML) components. Ordinary differential equations (ODEs), stochastic differential equations (SDEs), delay differential equations (DDEs), differential-algebraic equations (DAEs), and more in Julia.
https://docs.sciml.ai/DiffEqDocs/stable/
Other
2.85k stars 226 forks source link

tstops should give meaningful error if given duals #1033

Open elbert5770 opened 4 months ago

elbert5770 commented 4 months ago

It's entirely plausible that during an optimization, tstops (e.g. for callbacks) might depend on an optimized variable, and this can lead to a subtle problem with AD. When setting up an ODE, it would be pretty easy and fast to check to see if tstops is of type dual, and if so it should give a meaningful error (other than the generic Float64(Dual...) error), perhaps with instructions of how to extract values from a dual. I can't think of a case where you would want tstops to be a dual.

ChrisRackauckas commented 2 months ago

Almost missed this one.

Differentiating tstops is used for example in optimal experimental design. There's tests for this because it's a pretty common application that requires learning what the right time points would be.

nd this can lead to a subtle problem with AD

Can you share what this problem is? Maybe handling that problem is the better solution.