SciML / DiffEqCallbacks.jl

A library of useful callbacks for hybrid scientific machine learning (SciML) with augmented differential equation solvers
https://docs.sciml.ai/DiffEqCallbacks/stable/
Other
95 stars 47 forks source link

Callback for new adjoint method #151

Closed acoh64 closed 1 year ago

acoh64 commented 1 year ago

I made a new callback which works very similar to SavingCallback. save_func now becomes integrand_func which is a function passed to the callback to compute the integrand in the adjoint integral. The callback computes this at each time step of the integrator and saves the result. I need to change this so the callback computes this at the Gaussian quadrature nodes. @ChrisRackauckas let me know if you had something different in mind.

ChrisRackauckas commented 1 year ago

This is still a bit off. In a given step, integrator(t) is an interpolation from integrator(t) to integrator(t + dt). What this should be doing is evaluating at Gauss points theta[i] with weights w[i], and doing saveval = sum(w[i]*integrator(t + theta[i]*dt), length(theta)). No tstops setting is necessary.

acoh64 commented 1 year ago

I think I fixed this now. I had to use integrator(t) and integrator(tprev) though since if the next time step was not exactly equal to dt the results would not be accurate.

ChrisRackauckas commented 1 year ago

It might be good to include another test case that's simpler to work out by hand, like a linear ODE and check against the analytical solution. The vjp one is good too, but you need to add it to runtests.jl and update the test dependencies. Otherwise, this is looking really good!

acoh64 commented 1 year ago

sounds good, I'll add a test like this soon!

ChrisRackauckas commented 1 year ago

We can do the mentioned optimizations in a follow up PR. I think other than that, this is good to go with the final suggestions.

acoh64 commented 1 year ago

I added a test for a simple linear system with an analytical solution. Let me know if I should make any other changes and I can start working on the method in SciMLSensitivity.jl

ChrisRackauckas commented 1 year ago

🎉