Skip to content

Commit

Permalink
test: test remaking of initialization problem
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Aug 21, 2024
1 parent 1fed2fd commit 86980c2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/initializationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,32 @@ end
prob = ODEProblem(sys, [], (0.0, 1.0), [spring.s_rel0 => missing])
test_parameter(prob, spring.s_rel0, -3.905)
end

@testset "Re-creating initialization problem on remake" begin
@variables x(t) y(t)
@parameters p
@mtkbuild sys = ODESystem(
[D(x) ~ x, p ~ x + y], t; defaults = [p => missing], guesses = [x => 0.0, p => 0.0])
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0))
@test init(prob, Tsit5()).ps[p] 2.0
# nonsensical value for y just to test that equations work
prob2 = remake(prob; u0 = [x => 1.0, y => 2x + exp(t)])
@test init(prob2, Tsit5()).ps[p] 4.0
# solve for `x` given `p` and `y`
prob3 = remake(prob; u0 = [y => 1.0], p = [p => 2x + exp(t)])
@test init(prob3, Tsit5())[x] 0.0
@test_logs (:warn, r"overdetermined") remake(
prob; u0 = [x => 1.0, y => 2.0], p = [p => 4.0])
prob4 = remake(prob; u0 = [x => 1.0, y => 2.0], p = [p => 4.0])
@test solve(prob4, Tsit5()).retcode == ReturnCode.InitialFailure
prob5 = remake(prob)
@test init(prob, Tsit5()).ps[p] 2.0

@mtkbuild sys = ODESystem([D(x) ~ x, p ~ x + y], t; guesses = [p => 0.0])
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0), [p => 2.0])
# No value for `p`, not `missing`
@test_throws ModelingToolkit.MissingParametersError remake(
prob; u0 = [x => 1.0, y => 3x])
prob2 = remake(prob; u0 = [x => 1.0, y => 2x + exp(t)], p = [p => missing])
@test init(prob2, Tsit5()).ps[p] 4.0
end

0 comments on commit 86980c2

Please sign in to comment.