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

Promote tspan for discrete probs #928

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/problems/discrete_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct DiscreteProblem{uType, tType, isinplace, P, F, K} <:
""" A callback to be applied to every solver which uses the problem."""
kwargs::K
@add_kwonly function DiscreteProblem{iip}(f::AbstractDiscreteFunction{iip},
u0, tspan::Tuple, p = NullParameters();
u0, tspan, p = NullParameters();
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this give an ambiguity?

Copy link
Member Author

Choose a reason for hiding this comment

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

With which method?

Aqua reports:

julia> Aqua.test_ambiguities(SciMLBase)
8 ambiguities found. To get a list, set `broken = false`.
Ambiguity #1
(L::SciMLBase.AffineDiffEqOperator)(du, u, p, t::Number) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/diffeq_operator.jl:49
(L::SciMLOperators.AbstractSciMLOperator)(du::Number, u::Number, p, t, args...; kwargs...) @ SciMLOperators ~/.julia/packages/SciMLOperators/KVzmP/src/interface.jl:122

Possible fix, define
  (::SciMLBase.AffineDiffEqOperator)(::Number, ::Number, ::Any, ::Number)

Ambiguity #2
(L::SciMLBase.DiffEqArrayOperator)(du, u, p, t) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:205
(L::SciMLOperators.AbstractSciMLOperator)(du::Number, u::Number, p, t, args...; kwargs...) @ SciMLOperators ~/.julia/packages/SciMLOperators/KVzmP/src/interface.jl:122

Possible fix, define
  (::SciMLBase.DiffEqArrayOperator)(::Number, ::Number, ::Any, ::Any)

Ambiguity #3
(L::SciMLBase.DiffEqIdentity)(du, u, p, t) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:205
(L::SciMLOperators.AbstractSciMLOperator)(du::Number, u::Number, p, t, args...; kwargs...) @ SciMLOperators ~/.julia/packages/SciMLOperators/KVzmP/src/interface.jl:122

Possible fix, define
  (::SciMLBase.DiffEqIdentity)(::Number, ::Number, ::Any, ::Any)

Ambiguity #4
(L::SciMLBase.DiffEqScalar)(du, u, p, t) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:205
(L::SciMLOperators.AbstractSciMLOperator)(du::Number, u::Number, p, t, args...; kwargs...) @ SciMLOperators ~/.julia/packages/SciMLOperators/KVzmP/src/interface.jl:122

Possible fix, define
  (::SciMLBase.DiffEqScalar)(::Number, ::Number, ::Any, ::Any)

Ambiguity #5
(L::SciMLBase.FactorizedDiffEqArrayOperator)(du, u, p, t) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:205
(L::SciMLOperators.AbstractSciMLOperator)(du::Number, u::Number, p, t, args...; kwargs...) @ SciMLOperators ~/.julia/packages/SciMLOperators/KVzmP/src/interface.jl:122

Possible fix, define
  (::SciMLBase.FactorizedDiffEqArrayOperator)(::Number, ::Number, ::Any, ::Any)

Ambiguity #6
mul!(Y::AbstractArray, α::SciMLBase.DiffEqScalar, B::AbstractArray) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:76
mul!(Y::AbstractVecOrMat, L::SciMLBase.AbstractDiffEqLinearOperator, B::AbstractVecOrMat) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/common_defaults.jl:43

Possible fix, define
  mul!(::AbstractVecOrMat, ::SciMLBase.DiffEqScalar, ::AbstractVecOrMat)

Ambiguity #7
size(L::SciMLBase.FactorizedDiffEqArrayOperator, args...) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:188
size(A::SciMLOperators.AbstractSciMLOperator, d::Integer) @ SciMLOperators ~/.julia/packages/SciMLOperators/KVzmP/src/interface.jl:178

Possible fix, define
  size(::SciMLBase.FactorizedDiffEqArrayOperator, ::Integer)

Ambiguity #8
size(L::SciMLBase.FactorizedDiffEqArrayOperator, args...) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/basic_operators.jl:188
size(L::SciMLBase.AbstractDiffEqLinearOperator, i::Integer) @ SciMLBase ~/.julia/dev/SciMLBase/src/operators/common_defaults.jl:7

Possible fix, define
  size(::SciMLBase.FactorizedDiffEqArrayOperator, ::Integer)

Test Failed at /Users/isaacsas/.julia/packages/Aqua/epbUr/src/ambiguities.jl:78
  Expression: iszero(num_ambiguities)

ERROR: There was an error during testing

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean the second and third constructors when passing three arguments with the first two being nothing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I make tspan a union of vectors, tuples, and numbers? tspan::T where {T <: Union{Vector,Tuple,Number}?

Copy link
Member

Choose a reason for hiding this comment

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

I think so. I don't think the no function or f = identity dispatch is compatible with getting rid of the tspan::Tuple or some form of a type marker, since otherwise you cannot distinguish it from p.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't the old version have the same ambiguity though. I don't see how changing the first constructor, the only one I modified, impacts that. The ambiguity is between the second and third constructors isn't it?

I also don't get any messages about ambiguities locally on 1.11.3 when calling

p = (0.1 / 1000, 0.01)
dprob4 = DiscreteProblem{true}(nothing, nothing, p)

kwargs...) where {iip}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
Expand Down Expand Up @@ -138,12 +138,12 @@ end

Defines a discrete problem with the specified functions.
"""
function DiscreteProblem(f::AbstractDiscreteFunction, u0, tspan::Tuple,
function DiscreteProblem(f::AbstractDiscreteFunction, u0, tspan,
p = NullParameters(); kwargs...)
DiscreteProblem{isinplace(f)}(f, u0, tspan, p; kwargs...)
end

function DiscreteProblem(f::Base.Callable, u0, tspan::Tuple, p = NullParameters();
function DiscreteProblem(f::Base.Callable, u0, tspan, p = NullParameters();
kwargs...)
iip = isinplace(f, 4)
DiscreteProblem(DiscreteFunction{iip}(f), u0, tspan, p; kwargs...)
Expand All @@ -154,7 +154,7 @@ $(SIGNATURES)

Define a discrete problem with the identity map.
"""
function DiscreteProblem(u0::Union{AbstractArray, Number}, tspan::Tuple,
function DiscreteProblem(u0::Union{AbstractArray, Number}, tspan,
p = NullParameters(); kwargs...)
iip = u0 isa AbstractArray
if iip
Expand Down Expand Up @@ -197,6 +197,3 @@ struct DiscreteAliasSpecifier
end
end
end



15 changes: 15 additions & 0 deletions test/problem_building_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,18 @@ prob_bvp = BVProblem(simplependulum!, bc!, [pi / 2, pi / 2], (0, 1.0))
@test typeof(newprob) == typeof(prob)
end
end

# test for tspan promotion in DiscreteProblem
let
p = (0.1 / 1000, 0.01)
u₀ = [1.0]
tspan = (0.0, 1.0)
dprob = DiscreteProblem(u₀, tspan, p)
@test dprob.tspan === (0.0, 1.0)

dprob2 = DiscreteProblem(u₀, 1.0, p)
@test dprob.tspan === (0.0, 1.0)

dprob3 = DiscreteProblem(u₀, [0.0, 1.0], p)
@test dprob.tspan === (0.0, 1.0)
end
Loading