Skip to content

Implement Discontinuity Detection Algorithm - #3121

Merged
oscardssmith merged 57 commits into
SciML:masterfrom
Shreyas-Ekanathan:fresh-disco
Jun 4, 2026
Merged

oscardssmith merged 57 commits into
SciML:masterfrom
Shreyas-Ekanathan:fresh-disco

Conversation

@Shreyas-Ekanathan

Copy link
Copy Markdown
Contributor

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

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.

@ChrisRackauckas

Copy link
Copy Markdown
Member

disco_handling should be discontinuity_detection, and needs a docstring, then I think this is good to go.

Comment thread lib/OrdinaryDiffEqCore/Project.toml Resolved
Comment thread lib/OrdinaryDiffEqCore/src/solve.jl Resolved
Comment thread lib/OrdinaryDiffEqCore/src/solve.jl Outdated
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}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? doesn't the nlp hold the zerofunc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's voodoo, it wouldn't effect type-stability. Where's the actual inference lost?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A functionwrapper is effectively a type with that information 😅 what's the issue you're hitting with that?

Comment thread lib/OrdinaryDiffEqCore/src/solve.jl Outdated
alias = ODEAliasSpecifier(),
initializealg = DefaultInit(),
rng = nothing,
disco_probs = nothing,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for? I thought it was grabbed from the callabacks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this happened before we had a dedicated controller cache. Now that exists so we should probably use it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored into controller cache and got tests passing again

Comment thread lib/OrdinaryDiffEqCore/src/solve.jl Resolved
(; cache) = controller
(; dt, success_iter) = integrator
(; discontinuity_detection) = controller.basic
(; dt, success_iter, cache) = integrator

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a different cache from the controller cache?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@oscardssmith
oscardssmith merged commit 7bb5995 into SciML:master Jun 4, 2026
227 of 253 checks passed
ChrisRackauckas added a commit that referenced this pull request Jun 24, 2026
…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]>
@Shreyas-Ekanathan
Shreyas-Ekanathan deleted the fresh-disco branch August 18, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants