SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.38k stars 196 forks source link

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

Open hersle opened 5 days ago

hersle commented 5 days ago

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 commented 5 days ago

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.

ChrisRackauckas commented 5 days ago

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.

AayushSabharwal commented 5 days ago

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