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

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

Open hersle opened this issue 1 year ago • 2 comments

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 avatar Jun 12 '24 14:06 hersle

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.

hersle avatar Jun 25 '24 12:06 hersle

Yeah that shouldn't be too hard to solve.

ChrisRackauckas avatar Jun 26 '24 02:06 ChrisRackauckas