diff --git a/test/initializationsystem.jl b/test/initializationsystem.jl index 098d950a19..8b4901a19c 100644 --- a/test/initializationsystem.jl +++ b/test/initializationsystem.jl @@ -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