Skip to content

refactor: simplify deprecations #3802

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
190 changes: 44 additions & 146 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,161 +25,59 @@ end

for T in [:ODEProblem, :DDEProblem, :SDEProblem, :SDDEProblem, :DAEProblem,
:BVProblem, :DiscreteProblem, :ImplicitDiscreteProblem]
for (pType, pCanonical) in [
(AbstractDict, :p),
(AbstractArray{<:Pair}, :(Dict(p))),
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
],
(uType, uCanonical) in [
(Nothing, :(Dict())),
(AbstractDict, :u0),
(AbstractArray{<:Pair}, :(Dict(u0))),
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
]

@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
ctor = string($T)
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
"""
SciMLBase.$T(sys, merge($uCanonical, $pCanonical), tspan; kw...)
end
@eval function SciMLBase.$T{iip}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
ctor = string($T{iip})
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
"""
return SciMLBase.$T{iip}(sys, merge($uCanonical, $pCanonical), tspan; kw...)
end
@eval function SciMLBase.$T{iip, spec}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
ctor = string($T{iip, spec})
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
"""
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical), tspan; kw...)
end
end

for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]

@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
ctor = string($T)
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
`$ctor(sys, u0, tspan)` instead.
"""
$T(sys, u0, tspan; kw...)
end
@eval function SciMLBase.$T{iip}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
ctor = string($T{iip})
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
`$ctor(sys, u0, tspan)` instead.
"""
return $T{iip}(sys, u0, tspan; kw...)
@eval @fallback_iip_specialize function SciMLBase.$T{iip, spec}(sys::System, u0, tspan, p; kw...) where {iip, spec}
@warn """
`$($T)(sys, u0, tspan, p)` is deprecated. Use `$($T)(sys, op, tspan)` instead and provide
both unknown and parameter values in the operating point `op`.
"""
if u0 === nothing
u0 = Dict()
elseif u0 isa AbstractDict
u0 = u0
elseif u0 isa AbstractArray{<:Pair}
u0 = Dict(u0)
elseif u0 isa AbstractArray
u0 = isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)
end
@eval function SciMLBase.$T{iip, spec}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
ctor = string($T{iip, spec})
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
`$ctor(sys, u0, tspan)` instead.
"""
return $T{iip, spec}(sys, u0, tspan; kw...)
if p === nothing || p isa SciMLBase.NullParameters
p = Dict()
elseif p isa AbstractDict
p = p
elseif p isa AbstractArray{<:Pair}
p = Dict(p)
elseif p isa AbstractArray
p = isempty(p) ? Dict() : Dict(parameters(sys) .=> p)
end
return SciMLBase.$T{iip, spec}(sys, merge(u0, p), tspan; kw...)
end
end

for T in [:NonlinearProblem, :NonlinearLeastSquaresProblem,
:SCCNonlinearProblem, :OptimizationProblem, :SteadyStateProblem]
for (pType, pCanonical) in [
(AbstractDict, :p),
(AbstractArray{<:Pair}, :(Dict(p))),
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
],
(uType, uCanonical) in [
(Nothing, :(Dict())),
(AbstractDict, :u0),
(AbstractArray{<:Pair}, :(Dict(u0))),
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
]

@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
ctor = string($T)
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
instead.
"""
$T(sys, merge($uCanonical, $pCanonical); kw...)
end
@eval function SciMLBase.$T{iip}(
sys::System, u0::$uType, p::$pType; kw...) where {iip}
ctor = string($T{iip})
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
instead.
"""
return $T{iip}(sys, merge($uCanonical, $pCanonical); kw...)
end
@eval function SciMLBase.$T{iip, spec}(
sys::System, u0::$uType, p::$pType; kw...) where {iip, spec}
ctor = string($T{iip, spec})
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
instead.
"""
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical); kw...)
end
end
for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]

@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
ctor = string($T)
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
"""
$T(sys, u0; kw...)
end
@eval function SciMLBase.$T{iip}(
sys::System, u0::$uType, p::$pType; kw...) where {iip}
ctor = string($T{iip})
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
"""
return $T{iip}(sys, u0; kw...)
@eval @fallback_iip_specialize function SciMLBase.$T{iip, spec}(sys::System, u0, p; kw...) where {iip, spec}
@warn """
`$($T)(sys, u0, p)` is deprecated. Use `$($T)(sys, op)` instead and provide
both unknown and parameter values in the operating point `op`.
"""
if u0 === nothing
u0 = Dict()
elseif u0 isa AbstractDict
u0 = u0
elseif u0 isa AbstractArray{<:Pair}
u0 = Dict(u0)
elseif u0 isa AbstractArray
u0 = isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)
end
@eval function SciMLBase.$T{iip, spec}(
sys::System, u0::$uType, p::$pType; kw...) where {iip, spec}
ctor = string($T{iip, spec})
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
"""
return $T{iip, spec}(sys, u0; kw...)
if p === nothing || p isa SciMLBase.NullParameters
p = Dict()
elseif p isa AbstractDict
p = p
elseif p isa AbstractArray{<:Pair}
p = Dict(p)
elseif p isa AbstractArray
p = isempty(p) ? Dict() : Dict(parameters(sys) .=> p)
end
return SciMLBase.$T{iip, spec}(sys, merge(u0, p); kw...)
end
end

Expand Down
Loading