Skip to content

Tighten the interval returned by InternalITP when there's an exact zero crossing #1137

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Apr 3, 2025

Conversation

DaniGlez
Copy link
Contributor

@DaniGlez DaniGlez commented Apr 1, 2025

Background is here: https://github.com/SciML/DiffEqBase.jl/pull/1127/files#r2022436123

To summarize: inside the branch where the callback condition is evaluated to an exact zero, this PR fills the left and right fields of the solution with the location of the zero crossing instead of the values at the start of that ITP iteration.

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 1, 2025

BTW, in that branch we assume that yps is an exact zero because it's an else after if yps > T0 and elseif yps < T0, but a NaN would also fall into that branch; should an appropriate exception be raised in that case?

@oscardssmith
Copy link
Member

I do think this code is missing a branch for if right and left get within 1 ULP of each other. I think currently for a function like f(x) = x^2-2 it will run to maxiters since the function never hits 0.

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 1, 2025

Shouldn't that case be covered by the if later down in the function?

if nextfloat_tdir(left, left, right) == right

@oscardssmith
Copy link
Member

This looks good to me. Would you object to either you adding the change from https://github.com/SciML/DiffEqBase.jl/actions/runs/14193284895/job/39762654888?pr=1137 or vice versa? There are some CI failures here that look potentially related (on both branches) so it would be nice to consolidate the changes so I can only investigate once.

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 1, 2025

Either is fine by me, whatever is most convenient for you

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 1, 2025

I've incorporated the change from #1136 here for convenience

Copy link
Member

@oscardssmith oscardssmith left a comment

Choose a reason for hiding this comment

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

Looks good to me! Let's see if CI agrees.

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 1, 2025

CI not too happy, it seems

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 1, 2025

In this CI run, the only test failure that I can connect to callback rootfinding with InternalITP is this one: https://github.com/SciML/DiffEqBase.jl/actions/runs/14203971489/job/39797246048?pr=1137#step:6:17566

LoadError: MethodError: no method matching exponent(::ReverseDiff.TrackedReal{Float64, Float64, Nothing})

@oscardssmith oscardssmith reopened this Apr 3, 2025
@oscardssmith
Copy link
Member

I think the CI results might be bogus let's try again. We really don't want to be autodiffing the ITP so hopefully we aren't...

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 3, 2025

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Apr 3, 2025

Yeah, I think I can reproduce it (from https://github.com/SciML/DelayDiffEq.jl/blob/master/test/integrators/events.jl#L8 ). It seems that the callback location is now shifted 1 ulp to the right compared to previous behaviour. So the test failure could be remediated by:

  1. When building the solution, shift the left field 1 ulp to the left, which I think would restore pre-6.167.1 behavior
  2. Accept the new behavior, since the crossing is an exact zero and arguably the behavior is more sensible, and as a consequence amend the relevant DelayDiffEq tests to replace the prevfloat(2.6) instances in that test set by a plain 2.6

@oscardssmith
Copy link
Member

@ChrisRackauckas thoughts on the right approach here?

@ChrisRackauckas
Copy link
Member

Yeah if we are now better at stopping at the exact zero, that's better. We should accept that and change the test. Our goal has always been to get there, it just wasn't robust before.

@oscardssmith
Copy link
Member

sounds good. In that case, I think this is ready to merge and we can fix the test.

@ChrisRackauckas ChrisRackauckas merged commit fce3589 into SciML:master Apr 3, 2025
109 of 127 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants