Skip to content

Commit d6f0721

Browse files
fix and cover more problems; needs corresponding remake in SciMLBase
1 parent f26a31b commit d6f0721

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/variables.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ $(SIGNATURES)
125125
Intercept the call to `process_p_u0_symbolic` and process symbolic maps of `p` and/or `u0` if the
126126
user has `ModelingToolkit` loaded.
127127
"""
128-
function SciMLBase.process_p_u0_symbolic(prob::Union{ODEProblem, OptimizationProblem}, p,
128+
function SciMLBase.process_p_u0_symbolic(prob::Union{SciMLBase.AbstractDEProblem,
129+
NonlinearProblem, OptimizationProblem},
130+
p,
129131
u0)
130132
# check if a symbolic remake is possible
131133
if eltype(p) <: Pair

test/nonlinearsystem.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ eq = [v1 ~ sin(2pi * t * h)
189189
@named sys = ODESystem(eq)
190190
@test length(equations(structural_simplify(sys))) == 0
191191

192-
#1504
193-
let
192+
@testset "Issue: 1504" begin
194193
@variables u[1:4]
195194

196195
eqs = [u[1] ~ 1,
@@ -213,3 +212,23 @@ eqs = [0 ~ a * x]
213212
testdict = Dict([:test => 1])
214213
@named sys = NonlinearSystem(eqs, [x], [a], metadata = testdict)
215214
@test get_metadata(sys) == testdict
215+
216+
@testset "Remake" begin
217+
@parameters a=1.0 b=1.0 c=1.0
218+
@constants h = 1
219+
@variables x y z
220+
221+
eqs = [0 ~ a * (y - x) * h,
222+
0 ~ x * (b - z) - y,
223+
0 ~ x * y - c * z]
224+
@named sys = NonlinearSystem(eqs, [x, y, z], [a, b, c], defaults = Dict(x => 2.0))
225+
prob = NonlinearProblem(sys, ones(length(states(sys))))
226+
227+
prob_ = remake(prob, u0 = [1.0, 2.0, 3.0], p = [1.1, 1.2, 1.3])
228+
@test prob_.u0 == [1.0, 2.0, 3.0]
229+
@test prob_.p == [1.1, 1.2, 1.3]
230+
231+
prob_ = remake(prob, u0 = Dict(sys.y => 2.0), p = Dict(sys.a => 2.0))
232+
@test_broken prob_.u0 == [1.0, 2.0, 1.0] # TODO: needs a `remake(prob::NonlinearProblem, ...)` in SciMLBase
233+
@test_broken prob_.p == [2.0, 1.0, 1.0]
234+
end

test/optimizationsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ end
152152
constraints = [sys1.x + sys2.y ~ 2], checks = false)
153153
prob = OptimizationProblem(sys, [0.0, 0.0])
154154
@test isequal(constraints(sys), vcat(sys1.x + sys2.y ~ 2, sys1.x ~ 1, sys2.y ~ 1))
155-
@test isequal(equations(sys), (sys1.x - 1)^2 + (sys2.y - 1 / 2)^2)
155+
@test isequal(equations(sys), (sys1.x - sys1.a)^2 + (sys2.y - 1 / 2)^2)
156156
@test isequal(states(sys), [sys1.x, sys2.y])
157157

158158
prob_ = remake(prob, u0 = [1.0, 0.0], p = [2.0])

0 commit comments

Comments
 (0)