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

Ambiguity error for DynamicalDDEProblem #42

Closed
SebastianM-C opened this issue Mar 28, 2021 · 3 comments
Closed

Ambiguity error for DynamicalDDEProblem #42

SebastianM-C opened this issue Mar 28, 2021 · 3 comments

Comments

@SebastianM-C
Copy link
Contributor

Running

using Test
using SciMLBase

problems = detect_ambiguities(SciMLBase)

gives

8-element Vector{Tuple{Method, Method}}:
 (DynamicalDDEProblem(f::DynamicalDDEFunction, h, tspan) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:77, DynamicalDDEProblem(f1::Function, f2::Function, args...; kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 (DynamicalDDEProblem(f::DynamicalDDEFunction, h, tspan, p; kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:77, DynamicalDDEProblem(f1::Function, f2::Function, args...; kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 ((var"#s255"::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f::DynamicalDDEFunction, h, tspan, p) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:77, (::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f1::Function, f2::Function, args...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 (DynamicalDDEProblem(f::DynamicalDDEFunction, v0, u0, h, tspan, p; dependent_lags, kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:71, DynamicalDDEProblem(f1::Function, f2::Function, args...; kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 (DynamicalDDEProblem(f::DynamicalDDEFunction, v0, u0, h, tspan) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:71, DynamicalDDEProblem(f1::Function, f2::Function, args...; kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 ((var"#s255"::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f::DynamicalDDEFunction, v0, u0, h, tspan) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:71, (::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f1::Function, f2::Function, args...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 ((var"#s255"::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f::DynamicalDDEFunction, v0, u0, h, tspan, p) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:71, (::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f1::Function, f2::Function, args...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)
 ((var"#s255"::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f::DynamicalDDEFunction, h, tspan) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:77, (::Core.var"#Type##kw")(::Any, ::Type{DynamicalDDEProblem}, f1::Function, f2::Function, args...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80)

The above ambiguities refer only to two function definitions:
https://github.com/SciML/SciMLBase.jl/blob/v1.9.0/src/problems/dde_problems.jl#L77-L82

As a MWE:

using SciMLBase

f1(u,t,h) = u
f2(v,h) = v
f = DynamicalDDEFunction(f1, f2)
h(p,t) = (1,1)

DynamicalDDEProblem(f, h, (0,1))

which gives

ERROR: MethodError: DynamicalDDEProblem(::DynamicalDDEFunction{false, DDEFunction{false, typeof(f1), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, DDEFunction{false, typeof(f2), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, ::typeof(h), ::Tuple{Int64, Int64}) is ambiguous. Candidates:
  DynamicalDDEProblem(f1::Function, f2::Function, args...; kwargs...) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:80
  DynamicalDDEProblem(f::DynamicalDDEFunction, h, tspan) in SciMLBase at C:\Users\sebastian\.julia\dev\SciMLBase\src\problems\dde_problems.jl:77
Possible fix, define
  DynamicalDDEProblem(::DynamicalDDEFunction, ::Function, ::Any)
Stacktrace:
 [1] top-level scope

The problem appears due to the fact that DynamicalDDEFunction <: Function and the commit c555ead removed the restriction on the h argument and thus in both

function DynamicalDDEProblem(f::DynamicalDDEFunction,h,tspan,p=NullParameters();kwargs...)

and

function DynamicalDDEProblem(f1::Function,f2::Function,args...;kwargs...)

the first argument fits the method, but for the second argument we have Any in the first case (which was more specific) and Function in the second (which is more specific than Any).

One option would be to revert the suggestion by @devmotion in c555ead
The other would be to replace

function DynamicalDDEProblem(f1::Function,f2::Function,args...;kwargs...)

with two separate methods, but this would result in code duplication as mentioned in #14 (comment)

I can open a PR to fix this if you would like, just let me know what approach do you think is best.

@ChrisRackauckas
Copy link
Member

I think that could work.

@devmotion
Copy link
Member

devmotion commented Mar 28, 2021

In general, the history function h does not have to be a subtype of Function, so adding a type constraint on h seems wrong.

Would it be possible to remove the type constraints on f1 and f2 in

function DynamicalDDEProblem(f1::Function,f2::Function,args...;kwargs...)
and
function DynamicalDDEProblem{iip}(f1::Function,f2::Function,args...;kwargs...) where iip
? Would that work? IMO it seems also unnecessarily restrictive to impose these constraints on f1 and f2.

@SebastianM-C
Copy link
Contributor Author

Closed by #43

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

No branches or pull requests

3 participants