Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reinit! now ignores given state (2nd argument) for an MTK-derived ODEIntegrator. #3451

Open
Datseris opened this issue Mar 10, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@Datseris
Copy link

Minimal Reproducible Example 👇

using ModelingToolkit, OrdinaryDiffEqDefault

@independent_variables t
D = Differential(t)
@mtkmodel Roessler begin
    @parameters begin
        a = 0.2
        b = 0.2
        c = 5.7
    end
    @variables begin
        x(t) = 1.0
        y(t) = 0.0
        z(t) = 0.0
        nlt(t) # nonlinear term
    end
    @equations begin
        D(x) ~ -y -z
        D(y) ~ x + a*y
        D(z) ~ b + nlt
        nlt ~ z*(x - c)
    end
end

@mtkbuild roessler_model = Roessler()

prob = ODEProblem(roessler_model)
integ = OrdinaryDiffEqDefault.init(prob)
reinit!(integ, SVector(5, 5, 0.0))
integ

julia> integ
t: 0.0
u: 3-element SVector{3, Float64} with indices SOneTo(3):
 1.0
 0.0
 0.0

There are no error messages. The reinit! function simply now ignores the second argument and does not re-initialize the integrator at the given state. This is breaking for DynamicalSystems.jl, so I hope there is an easy fix!

Disclaimer: I have not checked whether this problem persists even for normally created ODEProblems.

  • Output of using Pkg; Pkg.status()
 pkg> st -m ModelingToolkit OrdinaryDiffEqDefault
Status `C:\Users\datse\.julia\environments\NLD\Manifest.toml`
  [961ee093] ModelingToolkit v9.65.0
  [50262376] OrdinaryDiffEqDefault v1.3.0
  • Output of versioninfo()

1.10.8.

Add any other context about the problem here.

@Datseris Datseris added the bug Something isn't working label Mar 10, 2025
@AayushSabharwal
Copy link
Member

reinit! reruns initialization as well, thus overriding the state. Passing reinit_dae = false will disable this behavior and respect the provided u0.

@ChrisRackauckas
Copy link
Member

We should at least warn if someone does a numerical reinitialization on a problem with a symbolic reinit function.

@Datseris
Copy link
Author

reinit! reruns initialization as well, thus overriding the state. Passing reinit_dae = false will disable this behavior and respect the provided u0.

Why isn't the reinit_dae = false the default? If it was, this wouldn't be a breaking change, as this behavior did not occur in other MTK v9 versions. Please do add the warning, yes.

@Datseris
Copy link
Author

Furthermore the docstring of reinit! should be changed to reflect that in fact the 2nd position argument will not be the new state.

Datseris added a commit to JuliaDynamics/DynamicalSystemsBase.jl that referenced this issue Mar 14, 2025
@AayushSabharwal
Copy link
Member

I agree with the warning. Initialization is there because the user might be solving for some parameters from unknowns, or the provided u may not be consistent.

@ChrisRackauckas
Copy link
Member

Why isn't the reinit_dae = false the default?

Because then it's almost guaranteed to not work. It has always been true because you can't solve a DAE without it?

@Datseris
Copy link
Author

"It has always been like that" is not my experience here. Can you acknowledge that this is breaking? I am not creating a DAE above, I am creating an ODE. The same code that used to work does not.

@ChrisRackauckas
Copy link
Member

It has always done that? It was using BrownBasicInit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants