-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Cache for QuadGKJL #168
Cache for QuadGKJL #168
Conversation
In general it looks good. Any new interface like this needs to make sure it's documented. We might want to consider making the cache mutable. This was recently changed in LinearSolve. It was done there mostly for correctness reasons SciML/LinearSolve.jl#303, but it means that Integrals is the only thing on an immutable cache now. There may still be reasons for it, but it is the odd one out now. |
Sounds good, I added documentation and tests. I can see why a mutable cache gives more flexibility, though for integral problems all of the information needed to build the cache is contingent on the types of the limits and the integrand. To show this, I changed the To be thorough, I can list what I think are pros and cons of mutable caches are for different algorithms that I know can currently use caches (there may be more)
In summary, I believe constructing the cache can always be done at Additionally, I noticed that |
@ArnoStrouwen is there a reason this never merged? |
@lxvm have a look at JuliaFormatter.jl, use it to get this PR into SciML style. Hopefully the tests will all pass and then we can merge. |
@ArnoStrouwen I updated the format I also wanted to request a code review on whether or not the user should be able to control allocation of a segment buffer for QuadGK. |
I think an immutable cache style with an
That's expected. I think for integrals the main use case for the cache would be changing parameters? If we setup function wrappers this will not be the case anyways, since then all functions are the same type. |
Ok, so to be consistent with the other SciML libraries I can make the cache mutable, specialize |
@ChrisRackauckas the cache is now mutable and I documented that its fields cannot change type when updated. I'm happy with the PR as-is, although I was wondering what you meant by setting up function wrappers? I assume you mean |
I meant this, and instead of |
This is fantastic. Thanks so much for taking it to completion! |
Hi, this pr makes the
IntegralCache
mechanism nontrivial and adds a working cache for theQuadGKJL
algorithm. What makes this cache somewhat tricky is that it needs to be rebuilt eagerly, i.e. whenever the integrand or parameters are reset, we allocate a new cache since these changes could change the return type of the integrand. Consider the example belowIf we could let the caller specify that the cache need not be changed, since they guarantee that the return type of the integral is unchanged, I think this would let us reuse the allocated cache across multiple calls. Otherwise I think we cannot safely reuse an immutable, concretely-typed cache without some guarantee of type stability when changing the integrand or input parameters.
In summary, the following cache-resetting methods were added
set_f(cache, f, [nout])
: rebuilds cacheset_lb(cache, lb)
: does not rebuild cacheset_ub(cache, ub)
: does not rebuild cacheset_p(cache, p)
: rebuilds cacheI also made an effort to get the AD to work with these changes. ForwardDiff.jl should still be working, however I still run into #99 with Zygote.jl.
I would appreciate any feedback on the design and will gladly implement those changes!