Skip to content

Commit 68da2ff

Browse files
refactor: simplify deprecations
1 parent 7ff680d commit 68da2ff

File tree

1 file changed

+44
-146
lines changed

1 file changed

+44
-146
lines changed

src/deprecations.jl

Lines changed: 44 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -25,161 +25,59 @@ end
2525

2626
for T in [:ODEProblem, :DDEProblem, :SDEProblem, :SDDEProblem, :DAEProblem,
2727
:BVProblem, :DiscreteProblem, :ImplicitDiscreteProblem]
28-
for (pType, pCanonical) in [
29-
(AbstractDict, :p),
30-
(AbstractArray{<:Pair}, :(Dict(p))),
31-
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
32-
],
33-
(uType, uCanonical) in [
34-
(Nothing, :(Dict())),
35-
(AbstractDict, :u0),
36-
(AbstractArray{<:Pair}, :(Dict(u0))),
37-
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
38-
]
39-
40-
@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
41-
ctor = string($T)
42-
uCan = string($(QuoteNode(uCanonical)))
43-
pCan = string($(QuoteNode(pCanonical)))
44-
@warn """
45-
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
46-
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
47-
"""
48-
SciMLBase.$T(sys, merge($uCanonical, $pCanonical), tspan; kw...)
49-
end
50-
@eval function SciMLBase.$T{iip}(
51-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
52-
ctor = string($T{iip})
53-
uCan = string($(QuoteNode(uCanonical)))
54-
pCan = string($(QuoteNode(pCanonical)))
55-
@warn """
56-
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
57-
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
58-
"""
59-
return SciMLBase.$T{iip}(sys, merge($uCanonical, $pCanonical), tspan; kw...)
60-
end
61-
@eval function SciMLBase.$T{iip, spec}(
62-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
63-
ctor = string($T{iip, spec})
64-
uCan = string($(QuoteNode(uCanonical)))
65-
pCan = string($(QuoteNode(pCanonical)))
66-
@warn """
67-
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
68-
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
69-
"""
70-
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical), tspan; kw...)
71-
end
72-
end
73-
74-
for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]
75-
76-
@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
77-
ctor = string($T)
78-
pT = string($(QuoteNode(pType)))
79-
@warn """
80-
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
81-
`$ctor(sys, u0, tspan)` instead.
82-
"""
83-
$T(sys, u0, tspan; kw...)
84-
end
85-
@eval function SciMLBase.$T{iip}(
86-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
87-
ctor = string($T{iip})
88-
pT = string($(QuoteNode(pType)))
89-
@warn """
90-
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
91-
`$ctor(sys, u0, tspan)` instead.
92-
"""
93-
return $T{iip}(sys, u0, tspan; kw...)
28+
@eval @fallback_iip_specialize function SciMLBase.$T{iip, spec}(sys::System, u0, tspan, p; kw...) where {iip, spec}
29+
@warn """
30+
`$($T)(sys, u0, tspan, p)` is deprecated. Use `$($T)(sys, op, tspan)` instead and provide
31+
both unknown and parameter values in the operating point `op`.
32+
"""
33+
if u0 === nothing
34+
u0 = Dict()
35+
elseif u0 isa AbstractDict
36+
u0 = u0
37+
elseif u0 isa AbstractArray{<:Pair}
38+
u0 = Dict(u0)
39+
elseif u0 isa AbstractArray
40+
u0 = isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)
9441
end
95-
@eval function SciMLBase.$T{iip, spec}(
96-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
97-
ctor = string($T{iip, spec})
98-
pT = string($(QuoteNode(pType)))
99-
@warn """
100-
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
101-
`$ctor(sys, u0, tspan)` instead.
102-
"""
103-
return $T{iip, spec}(sys, u0, tspan; kw...)
42+
if p === nothing || p isa SciMLBase.NullParameters
43+
p = Dict()
44+
elseif p isa AbstractDict
45+
p = p
46+
elseif p isa AbstractArray{<:Pair}
47+
p = Dict(p)
48+
elseif p isa AbstractArray
49+
p = isempty(p) ? Dict() : Dict(parameters(sys) .=> p)
10450
end
51+
return SciMLBase.$T{iip, spec}(sys, merge(u0, p), tspan; kw...)
10552
end
10653
end
10754

10855
for T in [:NonlinearProblem, :NonlinearLeastSquaresProblem,
10956
:SCCNonlinearProblem, :OptimizationProblem, :SteadyStateProblem]
110-
for (pType, pCanonical) in [
111-
(AbstractDict, :p),
112-
(AbstractArray{<:Pair}, :(Dict(p))),
113-
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
114-
],
115-
(uType, uCanonical) in [
116-
(Nothing, :(Dict())),
117-
(AbstractDict, :u0),
118-
(AbstractArray{<:Pair}, :(Dict(u0))),
119-
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
120-
]
121-
122-
@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
123-
ctor = string($T)
124-
uCan = string($(QuoteNode(uCanonical)))
125-
pCan = string($(QuoteNode(pCanonical)))
126-
@warn """
127-
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
128-
instead.
129-
"""
130-
$T(sys, merge($uCanonical, $pCanonical); kw...)
131-
end
132-
@eval function SciMLBase.$T{iip}(
133-
sys::System, u0::$uType, p::$pType; kw...) where {iip}
134-
ctor = string($T{iip})
135-
uCan = string($(QuoteNode(uCanonical)))
136-
pCan = string($(QuoteNode(pCanonical)))
137-
@warn """
138-
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
139-
instead.
140-
"""
141-
return $T{iip}(sys, merge($uCanonical, $pCanonical); kw...)
142-
end
143-
@eval function SciMLBase.$T{iip, spec}(
144-
sys::System, u0::$uType, p::$pType; kw...) where {iip, spec}
145-
ctor = string($T{iip, spec})
146-
uCan = string($(QuoteNode(uCanonical)))
147-
pCan = string($(QuoteNode(pCanonical)))
148-
@warn """
149-
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
150-
instead.
151-
"""
152-
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical); kw...)
153-
end
154-
end
155-
for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]
156-
157-
@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
158-
ctor = string($T)
159-
pT = string($(QuoteNode(pType)))
160-
@warn """
161-
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
162-
"""
163-
$T(sys, u0; kw...)
164-
end
165-
@eval function SciMLBase.$T{iip}(
166-
sys::System, u0::$uType, p::$pType; kw...) where {iip}
167-
ctor = string($T{iip})
168-
pT = string($(QuoteNode(pType)))
169-
@warn """
170-
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
171-
"""
172-
return $T{iip}(sys, u0; kw...)
57+
@eval @fallback_iip_specialize function SciMLBase.$T{iip, spec}(sys::System, u0, p; kw...) where {iip, spec}
58+
@warn """
59+
`$($T)(sys, u0, p)` is deprecated. Use `$($T)(sys, op)` instead and provide
60+
both unknown and parameter values in the operating point `op`.
61+
"""
62+
if u0 === nothing
63+
u0 = Dict()
64+
elseif u0 isa AbstractDict
65+
u0 = u0
66+
elseif u0 isa AbstractArray{<:Pair}
67+
u0 = Dict(u0)
68+
elseif u0 isa AbstractArray
69+
u0 = isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)
17370
end
174-
@eval function SciMLBase.$T{iip, spec}(
175-
sys::System, u0::$uType, p::$pType; kw...) where {iip, spec}
176-
ctor = string($T{iip, spec})
177-
pT = string($(QuoteNode(pType)))
178-
@warn """
179-
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
180-
"""
181-
return $T{iip, spec}(sys, u0; kw...)
71+
if p === nothing || p isa SciMLBase.NullParameters
72+
p = Dict()
73+
elseif p isa AbstractDict
74+
p = p
75+
elseif p isa AbstractArray{<:Pair}
76+
p = Dict(p)
77+
elseif p isa AbstractArray
78+
p = isempty(p) ? Dict() : Dict(parameters(sys) .=> p)
18279
end
80+
return SciMLBase.$T{iip, spec}(sys, merge(u0, p); kw...)
18381
end
18482
end
18583

0 commit comments

Comments
 (0)