ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
Remake does not respect initial conditions of unknowns determined by initialization equations
This example fails (but passes with the commented line uncommented):
using Test
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
@variables x(t)
@named sys = ODESystem([D(x) ~ 0], t; initialization_eqs = [x ~ 1.0]) # test fails with this uncommented
#@named sys = ODESystem([D(x) ~ 0], t; defaults = [x => 1.0]) # test passes with this uncommented
ssys = structural_simplify(sys)
prob1 = ODEProblem(ssys, [], (0.0, 1.0), [])
prob2 = remake(prob1, u0 = [x => 2.0])
sol2 = solve(prob2)
@test sol2[x][begin] == 2.0
I can kind of understand why. If I say that x ~ 1.0 during initialization, it would be inconsistent to override that with x => 2.0 in remake. But then I think remake could throw an error to avoid ambiguity.
This should fail with an initialization failure. @AayushSabharwal I think we discussed this one, the initialization problem needs to be rebuilt if the choices for the initial conditions change.
Right, I'll think of a way to build that infrastructure