Repository navigation
Implement Discontinuity Detection Algorithm - #3121
Conversation
|
|
| determine_controller_datatype(u::AbstractVector{<:Number}, internalnorm, ts::Tuple{<:Integer, <:Integer}) = promote_type(typeof(DiffEqBase.value(internalnorm(u, ts[1]))), typeof(DiffEqBase.value(internalnorm(u, ts[2]))), eltype(float.(DiffEqBase.value(ts)))) | ||
| determine_controller_datatype(u, internalnorm, ts::Tuple{<:Integer, <:Integer}) = promote_type(typeof(float(DiffEqBase.value(ts[1]))), typeof(float(DiffEqBase.value(ts[2])))) # This seems to be an assumption implicitly taken somewhere | ||
|
|
||
| struct DiscoProblem{ZF, NLP} |
There was a problem hiding this comment.
why do we need this? doesn't the nlp hold the zerofunc?
There was a problem hiding this comment.
I was working with Claude and it suggested that the extraction of the zerofunc from the NLP might create some of the type instability we were seeing so I tried this out and it seemed to help from a performance perspective. I removed functionwrappers for the same reason because it was hurting the type stability
There was a problem hiding this comment.
that's voodoo, it wouldn't effect type-stability. Where's the actual inference lost?
There was a problem hiding this comment.
so the instability happens during the updates to disco_zero in find_discontinuity, the root cause appears to be the Vector{IntervalNonLinearProblem} which leaves us no info about the zero_func_struct contained inside each function and creates the inference loss.
There was a problem hiding this comment.
so the previous fix would actually help something I think, becuase when you put everything into that custom wrapper that stores the information about the zero_func_struct, we maintain that type info and so the updates become stable
There was a problem hiding this comment.
A functionwrapper is effectively a type with that information 😅 what's the issue you're hitting with that?
| alias = ODEAliasSpecifier(), | ||
| initializealg = DefaultInit(), | ||
| rng = nothing, | ||
| disco_probs = nothing, |
There was a problem hiding this comment.
what is this for? I thought it was grabbed from the callabacks?
There was a problem hiding this comment.
the idea is that instead of creating and allocating a new problem object each time we hit an event, we will just frontload the creation of all of the event problems (which internally use the callbacks) to determine the discontinuity events.
There was a problem hiding this comment.
I think this happened before we had a dedicated controller cache. Now that exists so we should probably use it.
There was a problem hiding this comment.
Refactored into controller cache and got tests passing again
| (; cache) = controller | ||
| (; dt, success_iter) = integrator | ||
| (; discontinuity_detection) = controller.basic | ||
| (; dt, success_iter, cache) = integrator |
There was a problem hiding this comment.
this is a different cache from the controller cache?
There was a problem hiding this comment.
yes the algorithm cache is taken out of the integrator for the adaptivity fields, distinct from the controller cache which tells you whether or not to run disco
…erOptions importers (#3774) The fresh-disco merge (#3121) added `set_discontinuity` (disco.jl) and a second type parameter to `CommonControllerOptions{T, NLPType}` to OrdinaryDiffEqCore, and #3773 released those changes as OrdinaryDiffEqCore v4.4.0. But the sublibraries that import those new symbols still carried `OrdinaryDiffEqCore = "4.1"`, so the resolver is free to pick a registered OrdinaryDiffEqCore in [4.1, 4.4) (e.g. 4.3.0, which predates the disco merge) that lacks `set_discontinuity` and has the old one-parameter `CommonControllerOptions`. That mis-resolution makes the dependents fail to precompile: WARNING: could not import OrdinaryDiffEqCore.set_discontinuity into OrdinaryDiffEqBDF ERROR: LoadError: too many parameters for type @ .../OrdinaryDiffEqBDF/src/controllers.jl This is the root cause of the master CI AD (julia lts) and ODEInterfaceRegression (julia lts) failures (OrdinaryDiffEqBDF precompile error). Reproduced locally on Julia 1.10 with path-OrdinaryDiffEqBDF + registered OrdinaryDiffEqCore 4.3.0, producing the identical error; after raising the floor to "4.4", the resolver correctly rejects OrdinaryDiffEqCore < 4.4.0 ("restricted to versions 4.4.0-4 ... no versions left") and the full root env precompiles and solves FBDF cleanly. Affected importers (all bumped to floor 4.4 + patch version bump): - OrdinaryDiffEqBDF (set_discontinuity + 2-param CommonControllerOptions) - OrdinaryDiffEqFIRK (set_discontinuity) - OrdinaryDiffEqNordsieck (2-param CommonControllerOptions) - OrdinaryDiffEqExtrapolation (2-param CommonControllerOptions) - ImplicitDiscreteSolve (2-param CommonControllerOptions) Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
A preliminary implementation of autonomous discontinuity detection in Radau. Uses a PR to SciML base at SciML/SciMLBase.jl#1219 to modify callbacks to support a is_discontinuous flag.