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.41k stars 204 forks source link

Cannot (re)make problems with defaults involving the independent parameter #2799

Closed hersle closed 1 month ago

hersle commented 3 months ago

Currently, it seems to me that remake cannot reinitialize a system using defaults that involve the independent parameter (often t). It would be nice if this worked:

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations

@variables x(t) y(t)
@mtkbuild sys = ODESystem([D(x) ~ 0, D(y) ~ 0], t; defaults = [y => t])
prob = ODEProblem(sys, unknowns(sys) .=> NaN, (1.0, 2.0), []) # uninitialized problem

# I expect one or more (preferably all) of these to initialize y = t = 1.0 from the default
prob1 = remake(prob, use_defaults = true, u0 = [x => 0.0])
prob2 = remake(prob, use_defaults = true, u0 = [x => 0.0], tspan = (1.0, 2.0))
prob3 = remake(prob, use_defaults = true, u0 = [x => 0.0], tspan = (1.0, 2.0), p = [t => 1.0])

All three fail with slightly different error messages.

hersle commented 3 months ago

More fundamentally, it is not possible to make (not remake) an ODEProblem with defaults involving the independent parameter:

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations

@variables x(t)
@mtkbuild sys = ODESystem([D(x) ~ 0], t; defaults = [x => t])
prob = ODEProblem(structural_simplify(sys), [], (1.0, 2.0), [])

I should probably have reported this first. I add it here since it is very related.

ChrisRackauckas commented 3 months ago

Yeah that shouldn't be too hard to solve.