Skip to content

Conversation

@jClugstor
Copy link
Member

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

This time for real and without Static

@jClugstor jClugstor marked this pull request as ready for review August 15, 2025 18:35
themselves, for an example of how this can be confusing to a user see
https://discourse.julialang.org/t/typeerror-in-julia-turing-when-sampling-for-a-forced-differential-equation/82937
"""
@generated function anyeltypedual(x, ::Type{Val{counter}}) where {counter}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed in SciMLBase?

Copy link
Member Author

Choose a reason for hiding this comment

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

anyeltypedual is used in promote_u0, which is used by get_concrete_problem for NonlinearProblem and also differential equations. So it's needed for both. So this either needs to be in SciMLBase, or it needs to be in both DiffEqBase and NonlinearSolveBase.

Copy link
Member

Choose a reason for hiding this comment

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

why would nonlinearproblem need it? It should use implicit diff, and it requires p as an array for that just like linearproblem?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well promote_u0 is also used for a few other things, like Tracker, ReverseDiff, Measurements, and Montecarlo measurements. So we still need to use promote_u0 for NonlinearProblems in those cases.

Also,
Current behavior:

using NonlinearSolve
using ForwardDiff

f(u, p) = u .* u .- p
u0 = [1.0, 1.0]
p = ForwardDiff.Dual(2.0, 1.0)
prob = NonlinearProblem(f, u0, p)
sol = solve(prob)

in the solve call u0 does get promoted to Dual through promote_u0 and the problem passed to solve_call actually does have a dual u0. Of course it ends up being stripped in the overloads, but I didn't really want to mess with the current behavior.

So we could put anyeltypedual back in to DiffEqBase, but we would also need to put promote_u0 back in that case because it uses anyeltypedual. We would just need each FooBase package to define it's own implementation or variation of promote_u0 in that case.

@ChrisRackauckas ChrisRackauckas merged commit 68034ab into SciML:master Aug 18, 2025
43 of 62 checks passed
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.

2 participants