ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

Remake does not respect initial conditions of unknowns determined by initialization equations

Open hersle opened this issue 1 year ago • 3 comments

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

hersle avatar Jul 03 '24 13:07 hersle

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.

hersle avatar Jul 03 '24 13:07 hersle

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.

ChrisRackauckas avatar Jul 03 '24 14:07 ChrisRackauckas

Right, I'll think of a way to build that infrastructure

AayushSabharwal avatar Jul 03 '24 14:07 AayushSabharwal