Skip to content

Commit 2fed2d3

Browse files
refactor: simplify deprecations
1 parent 0828cd9 commit 2fed2d3

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
@@ -15,161 +15,59 @@ end
1515

1616
for T in [:ODEProblem, :DDEProblem, :SDEProblem, :SDDEProblem, :DAEProblem,
1717
:BVProblem, :DiscreteProblem, :ImplicitDiscreteProblem]
18-
for (pType, pCanonical) in [
19-
(AbstractDict, :p),
20-
(AbstractArray{<:Pair}, :(Dict(p))),
21-
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
22-
],
23-
(uType, uCanonical) in [
24-
(Nothing, :(Dict())),
25-
(AbstractDict, :u0),
26-
(AbstractArray{<:Pair}, :(Dict(u0))),
27-
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
28-
]
29-
30-
@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
31-
ctor = string($T)
32-
uCan = string($(QuoteNode(uCanonical)))
33-
pCan = string($(QuoteNode(pCanonical)))
34-
@warn """
35-
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
36-
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
37-
"""
38-
SciMLBase.$T(sys, merge($uCanonical, $pCanonical), tspan; kw...)
39-
end
40-
@eval function SciMLBase.$T{iip}(
41-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
42-
ctor = string($T{iip})
43-
uCan = string($(QuoteNode(uCanonical)))
44-
pCan = string($(QuoteNode(pCanonical)))
45-
@warn """
46-
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
47-
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
48-
"""
49-
return SciMLBase.$T{iip}(sys, merge($uCanonical, $pCanonical), tspan; kw...)
50-
end
51-
@eval function SciMLBase.$T{iip, spec}(
52-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
53-
ctor = string($T{iip, spec})
54-
uCan = string($(QuoteNode(uCanonical)))
55-
pCan = string($(QuoteNode(pCanonical)))
56-
@warn """
57-
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
58-
`$ctor(sys, merge($uCan, $pCan), tspan)` instead.
59-
"""
60-
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical), tspan; kw...)
61-
end
62-
end
63-
64-
for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]
65-
66-
@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
67-
ctor = string($T)
68-
pT = string($(QuoteNode(pType)))
69-
@warn """
70-
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
71-
`$ctor(sys, u0, tspan)` instead.
72-
"""
73-
$T(sys, u0, tspan; kw...)
74-
end
75-
@eval function SciMLBase.$T{iip}(
76-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
77-
ctor = string($T{iip})
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-
return $T{iip}(sys, u0, tspan; kw...)
18+
@eval @fallback_iip_specialize function SciMLBase.$T{iip, spec}(sys::System, u0, tspan, p; kw...) where {iip, spec}
19+
@warn """
20+
`$($T)(sys, u0, tspan, p)` is deprecated. Use `$($T)(sys, op, tspan)` instead and provide
21+
both unknown and parameter values in the operating point `op`.
22+
"""
23+
if u0 === nothing
24+
u0 = Dict()
25+
elseif u0 isa AbstractDict
26+
u0 = u0
27+
elseif u0 isa AbstractArray{<:Pair}
28+
u0 = Dict(u0)
29+
elseif u0 isa AbstractArray
30+
u0 = isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)
8431
end
85-
@eval function SciMLBase.$T{iip, spec}(
86-
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
87-
ctor = string($T{iip, spec})
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, spec}(sys, u0, tspan; kw...)
32+
if p === nothing || p isa SciMLBase.NullParameters
33+
p = Dict()
34+
elseif p isa AbstractDict
35+
p = p
36+
elseif p isa AbstractArray{<:Pair}
37+
p = Dict(p)
38+
elseif p isa AbstractArray
39+
p = isempty(p) ? Dict() : Dict(parameters(sys) .=> p)
9440
end
41+
return SciMLBase.$T{iip, spec}(sys, merge(u0, p), tspan; kw...)
9542
end
9643
end
9744

9845
for T in [:NonlinearProblem, :NonlinearLeastSquaresProblem,
9946
:SCCNonlinearProblem, :OptimizationProblem, :SteadyStateProblem]
100-
for (pType, pCanonical) in [
101-
(AbstractDict, :p),
102-
(AbstractArray{<:Pair}, :(Dict(p))),
103-
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
104-
],
105-
(uType, uCanonical) in [
106-
(Nothing, :(Dict())),
107-
(AbstractDict, :u0),
108-
(AbstractArray{<:Pair}, :(Dict(u0))),
109-
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
110-
]
111-
112-
@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
113-
ctor = string($T)
114-
uCan = string($(QuoteNode(uCanonical)))
115-
pCan = string($(QuoteNode(pCanonical)))
116-
@warn """
117-
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
118-
instead.
119-
"""
120-
$T(sys, merge($uCanonical, $pCanonical); kw...)
121-
end
122-
@eval function SciMLBase.$T{iip}(
123-
sys::System, u0::$uType, p::$pType; kw...) where {iip}
124-
ctor = string($T{iip})
125-
uCan = string($(QuoteNode(uCanonical)))
126-
pCan = string($(QuoteNode(pCanonical)))
127-
@warn """
128-
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
129-
instead.
130-
"""
131-
return $T{iip}(sys, merge($uCanonical, $pCanonical); kw...)
132-
end
133-
@eval function SciMLBase.$T{iip, spec}(
134-
sys::System, u0::$uType, p::$pType; kw...) where {iip, spec}
135-
ctor = string($T{iip, spec})
136-
uCan = string($(QuoteNode(uCanonical)))
137-
pCan = string($(QuoteNode(pCanonical)))
138-
@warn """
139-
`$ctor(sys, u0, p; kw...)` is deprecated. Use `$ctor(sys, merge($uCan, $pCan))`
140-
instead.
141-
"""
142-
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical); kw...)
143-
end
144-
end
145-
for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]
146-
147-
@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
148-
ctor = string($T)
149-
pT = string($(QuoteNode(pType)))
150-
@warn """
151-
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
152-
"""
153-
$T(sys, u0; kw...)
154-
end
155-
@eval function SciMLBase.$T{iip}(
156-
sys::System, u0::$uType, p::$pType; kw...) where {iip}
157-
ctor = string($T{iip})
158-
pT = string($(QuoteNode(pType)))
159-
@warn """
160-
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
161-
"""
162-
return $T{iip}(sys, u0; kw...)
47+
@eval @fallback_iip_specialize function SciMLBase.$T{iip, spec}(sys::System, u0, p; kw...) where {iip, spec}
48+
@warn """
49+
`$($T)(sys, u0, p)` is deprecated. Use `$($T)(sys, op)` instead and provide
50+
both unknown and parameter values in the operating point `op`.
51+
"""
52+
if u0 === nothing
53+
u0 = Dict()
54+
elseif u0 isa AbstractDict
55+
u0 = u0
56+
elseif u0 isa AbstractArray{<:Pair}
57+
u0 = Dict(u0)
58+
elseif u0 isa AbstractArray
59+
u0 = isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)
16360
end
164-
@eval function SciMLBase.$T{iip, spec}(
165-
sys::System, u0::$uType, p::$pType; kw...) where {iip, spec}
166-
ctor = string($T{iip, spec})
167-
pT = string($(QuoteNode(pType)))
168-
@warn """
169-
`$ctor(sys, u0, p::$pT; kw...)` is deprecated. Use `$ctor(sys, u0)` instead
170-
"""
171-
return $T{iip, spec}(sys, u0; kw...)
61+
if p === nothing || p isa SciMLBase.NullParameters
62+
p = Dict()
63+
elseif p isa AbstractDict
64+
p = p
65+
elseif p isa AbstractArray{<:Pair}
66+
p = Dict(p)
67+
elseif p isa AbstractArray
68+
p = isempty(p) ? Dict() : Dict(parameters(sys) .=> p)
17269
end
70+
return SciMLBase.$T{iip, spec}(sys, merge(u0, p); kw...)
17371
end
17472
end
17573

0 commit comments

Comments
 (0)