Skip to content
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

Fix ambiguity in __solve with polyalgorithm due to dispatch on Va #498

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

ChrisRackauckas
Copy link
Member

@ChrisRackauckas ChrisRackauckas commented Nov 12, 2024

Fixes #497 . Noticed downstream

  Candidates:
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), prob::SciMLBase.AbstractNonlinearProblem, alg::NonlinearSolveBase.NonlinearSolvePolyAlgorithm{Val{N}}, args...) where N
      @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/54f3T/src/solve.jl:106
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), prob::Union{SciMLBase.NonlinearLeastSquaresProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}, SciMLBase.NonlinearProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}}, alg::NonlinearSolveBase.AbstractNonlinearSolveAlgorithm, args...)
      @ NonlinearSolve ~/.julia/packages/NonlinearSolve/LuVnf/src/forward_diff.jl:14
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), prob::Union{SciMLBase.NonlinearLeastSquaresProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}, SciMLBase.NonlinearProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}}, alg::NonlinearSolveBase.NonlinearSolvePolyAlgorithm, args...)
      @ NonlinearSolve ~/.julia/packages/NonlinearSolve/LuVnf/src/forward_diff.jl:14
  
  Possible fix, define
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), ::Union{SciMLBase.NonlinearLeastSquaresProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}, SciMLBase.NonlinearProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}}, ::NonlinearSolveBase.NonlinearSolvePolyAlgorithm{Val{N}}, ::Vararg{Any}) where N

https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/11786040241/job/32828542508?pr=2522

The issue is that the polyalgorithm code is dispatching on more details of the polyalgorithm than https://github.com/SciML/NonlinearSolve.jl/blob/master/src/forward_diff.jl#L13-L25 which leads to an ambiguity. But it only needs that information since it's a generated function. The easy fix is to just make the generated function be one step lower.

…{N}`

Noticed downstream

```
  Candidates:
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), prob::SciMLBase.AbstractNonlinearProblem, alg::NonlinearSolveBase.NonlinearSolvePolyAlgorithm{Val{N}}, args...) where N
      @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/54f3T/src/solve.jl:106
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), prob::Union{SciMLBase.NonlinearLeastSquaresProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}, SciMLBase.NonlinearProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}}, alg::NonlinearSolveBase.AbstractNonlinearSolveAlgorithm, args...)
      @ NonlinearSolve ~/.julia/packages/NonlinearSolve/LuVnf/src/forward_diff.jl:14
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), prob::Union{SciMLBase.NonlinearLeastSquaresProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}, SciMLBase.NonlinearProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}}, alg::NonlinearSolveBase.NonlinearSolvePolyAlgorithm, args...)
      @ NonlinearSolve ~/.julia/packages/NonlinearSolve/LuVnf/src/forward_diff.jl:14
  
  Possible fix, define
    kwcall(::NamedTuple, ::typeof(SciMLBase.__solve), ::Union{SciMLBase.NonlinearLeastSquaresProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}, SciMLBase.NonlinearProblem{<:Union{Number, var"#s15"} where var"#s15"<:AbstractArray, iip, <:Union{var"#s14", var"#s13"} where {var"#s14"<:ForwardDiff.Dual{T, V, P}, var"#s13"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}} where {iip, T, V, P}}, ::NonlinearSolveBase.NonlinearSolvePolyAlgorithm{Val{N}}, ::Vararg{Any}) where N
```

https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/11786040241/job/32828542508?pr=2522

The issue is that the polyalgorithm code is dispatching on more details of the polyalgorithm than https://github.com/SciML/NonlinearSolve.jl/blob/master/src/forward_diff.jl#L13-L25 which leads to an ambiguity. But it only needs that information since it's a generated function. The easy fix is to just make the generated function be one step lower.
@ChrisRackauckas
Copy link
Member Author

UndefVarError: GeneralizedFirstOrderAlgorithmCache not defined in NonlinearSolve

@AayushSabharwal that seems like a you thing.

@avik-pal this ReTest thing seems to keep failing due to biting itself 😅

It doesn't look like any test failures are related, though the tests here are pretty worrisome...

@ChrisRackauckas ChrisRackauckas merged commit fe4950d into master Nov 12, 2024
62 of 87 checks passed
@ChrisRackauckas ChrisRackauckas deleted the ChrisRackauckas-patch-1 branch November 12, 2024 11:02
@AayushSabharwal
Copy link
Member

Looks like the SII value provider impl needs an update. Will PR

@@ -103,7 +103,12 @@ end
return Expr(:block, calls...)
end

@generated function SciMLBase.__solve(
function SciMLBase.__solve(prob::AbstractNonlinearProblem, alg::NonlinearSolvePolyAlgorithm,
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function SciMLBase.__solve(prob::AbstractNonlinearProblem, alg::NonlinearSolvePolyAlgorithm,
function SciMLBase.__solve(
prob::AbstractNonlinearProblem, alg::NonlinearSolvePolyAlgorithm,

@generated function SciMLBase.__solve(
function SciMLBase.__solve(prob::AbstractNonlinearProblem, alg::NonlinearSolvePolyAlgorithm,
args...; kwargs...)
__generated_polysolve(prob, alg, args...; kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
__generated_polysolve(prob, alg, args...; kwargs...)
__generated_polysolve(prob, alg, args...; kwargs...)

@avik-pal
Copy link
Member

@avik-pal this ReTest thing seems to keep failing due to biting itself 😅

Just for windows 😢

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.

Ambiguity error when solving NonlinearProblem on master
3 participants