-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DiffEqDiffTools API changes #224
DiffEqDiffTools API changes #224
Conversation
I'm not involved in the DiffeqDiffTools development, so maybe it's a stupid question, but why don't you just pass |
We could go even further and implement DiffEqDiffTools.derivative!(dT, tf, du2, t, integrator) (or something similar), which depending on These changes would simplify the code in OrdinaryDiffEq but maybe |
That's a question of how much flexibility @ChrisRackauckas prefers to retain on the OrdinaryDiffEq side (and, eventually, other DiffEq packages). I kept the checks on the OrdinaryDiffEq side of things because I assumed Chris might want to later expose the choice between real and complex in the user-facing API for explicit overriding. If that's not viewed as necessary I have no objection to moving as much of the boilerplate as possible over to DiffEqDiffTools and simplifying the calls used in OrdinaryDiffEq along the lines you suggested. |
Yes, that's what I was wondering about, hence I assumed it might be desired to keep the form with By the way, a method like |
Yeah, my response was mostly about the Broadly speaking, my goal with DiffEqDiffTools was just to write the low level stuff in a way that delivers close to optimal performance without sacrificing flexibility. That's pretty much done now, at the cost of a rather ugly and verbose API. This commit just uses it directly, in order to get the features out there ASAP, since other people are waiting for them. I'm happy to write up any convenience wrappers people would like to see, but any DiffEq API level decisions are up to Chris, so my PRs just expose the new features without making any assumptions about the higher level stuff. For what it's worth, I like the |
This was done for the Optim.jl guys who always want a real output, say from the cost equation, which may have complex inputs. We won't have this problem, but we hope to replace the Calculus.jl they use to help them get some more speed and abstract type support.
That's probably a nice way to handle this. This could even just be defined on the abstract integrator from DiffEqBase and it'll work then in other packages like StochasticDiffEq.jl as well.
API refactoring can always be done later (and it seems like @devmotion came up with a good solution for it), so I am not making it a necessity. What I want to see more is speed + complex number and abstract array support, which this gives, so I'm happy to take it and maybe implement the cleaner form in a different PR (unless you're willing to make the change). But I think that while I have your attention I'd rather try to push forward on JuliaDiff/FiniteDiff.jl#16 and JuliaDiff/FiniteDiff.jl#13 . Of course, as always with open source, choose what you want to spend your time with, but I am pushing towards solving the methods issues first because API refactoring is something that can always be done on a flight or as an intro issue for a GSoC student (or one of us when we're bored can just bang it out in 20 minutes). |
Now that I have your okay on the API thing, that's a very easy change. The |
Yes, NLsolve doesn't need them but Optim.jl needs them to fully dump Calculus.jl |
Okay, then I'll try to get the API and |
Wrote up quick convenience wrappers for derivatives and Jacobians as per @devmotion's suggestion. It temporarily resides in OrdinaryDiffEq and should be moved over to DiffEqDiffTools along with the derivative wrapper types. As we've discussed previously, I'm holding off on such refactoring until the major features are done, but this should at least make writing and maintaining integrators a bit less painful. |
I like these convenience wrappers 👍 It just feels a bit inconsistent that these wrappers allow arguments of type |
Or is it even possible to remove those |
You're right, I need to tighten up the type constraints both here and on the DiffEqDiffTools side as well. At least on the latter, they should be |
I haven't been able to review yet but after the ForwardDiff change we shouldn't need to |
I reviewed it. It's already a lot of changes in the right direction, so I think it's good to accept it and keep iterating on it instead of trying to get it all in one perfect PR. |
@@ -46,3 +46,23 @@ mutable struct UDerivativeWrapper{F,tType} <: Function | |||
t::tType | |||
end | |||
(p::UDerivativeWrapper)(u) = p.f(p.t,u) | |||
|
|||
function derivative!(df::AbstractArray{<:Number}, f, x::Union{Number,AbstractArray{<:Number}}, fx::AbstractArray{<:Number}, integrator::DEIntegrator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really clean way to handle all of this. Nice.
Codecov Report
@@ Coverage Diff @@
## master #224 +/- ##
==========================================
+ Coverage 76.74% 76.81% +0.07%
==========================================
Files 61 61
Lines 21476 21434 -42
==========================================
- Hits 16482 16465 -17
+ Misses 4994 4969 -25
Continue to review full report at Codecov.
|
This reflects API changes with respect to JuliaDiff/FiniteDiff.jl@4803b91 and passes OrdinaryDiffEq.jl tests.