Skip to content

Commit 86980c2

Browse files
test: test remaking of initialization problem
1 parent 1fed2fd commit 86980c2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/initializationsystem.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,32 @@ end
544544
prob = ODEProblem(sys, [], (0.0, 1.0), [spring.s_rel0 => missing])
545545
test_parameter(prob, spring.s_rel0, -3.905)
546546
end
547+
548+
@testset "Re-creating initialization problem on remake" begin
549+
@variables x(t) y(t)
550+
@parameters p
551+
@mtkbuild sys = ODESystem(
552+
[D(x) ~ x, p ~ x + y], t; defaults = [p => missing], guesses = [x => 0.0, p => 0.0])
553+
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0))
554+
@test init(prob, Tsit5()).ps[p] 2.0
555+
# nonsensical value for y just to test that equations work
556+
prob2 = remake(prob; u0 = [x => 1.0, y => 2x + exp(t)])
557+
@test init(prob2, Tsit5()).ps[p] 4.0
558+
# solve for `x` given `p` and `y`
559+
prob3 = remake(prob; u0 = [y => 1.0], p = [p => 2x + exp(t)])
560+
@test init(prob3, Tsit5())[x] 0.0
561+
@test_logs (:warn, r"overdetermined") remake(
562+
prob; u0 = [x => 1.0, y => 2.0], p = [p => 4.0])
563+
prob4 = remake(prob; u0 = [x => 1.0, y => 2.0], p = [p => 4.0])
564+
@test solve(prob4, Tsit5()).retcode == ReturnCode.InitialFailure
565+
prob5 = remake(prob)
566+
@test init(prob, Tsit5()).ps[p] 2.0
567+
568+
@mtkbuild sys = ODESystem([D(x) ~ x, p ~ x + y], t; guesses = [p => 0.0])
569+
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0), [p => 2.0])
570+
# No value for `p`, not `missing`
571+
@test_throws ModelingToolkit.MissingParametersError remake(
572+
prob; u0 = [x => 1.0, y => 3x])
573+
prob2 = remake(prob; u0 = [x => 1.0, y => 2x + exp(t)], p = [p => missing])
574+
@test init(prob2, Tsit5()).ps[p] 4.0
575+
end

0 commit comments

Comments
 (0)