Skip to content

Initialization System fails to remove an equation #3312

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

Closed
bradcarman opened this issue Jan 11, 2025 · 3 comments
Closed

Initialization System fails to remove an equation #3312

bradcarman opened this issue Jan 11, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@bradcarman
Copy link
Contributor

Take the following. The equation left in the initialization system is already an observable.

using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkit: t_nounits as t, D_nounits as D

vars = @variables y(t) dy(t) ddy(t)
systems = @named begin
    src = SampledData(Float64)
    int = Integrator()
end 
eqs = [
    y ~ src.output.u
    D(y) ~ dy
    D(dy) ~ ddy
    connect(src.output, int.input)
]

@mtkbuild sys = ODESystem(eqs, t; systems)
initprob = ModelingToolkit.InitializationProblem(sys, 0.0) # Warning: Initialization system is overdetermined. 1 equations for 0 unknowns.

As can be seen we have an overdetermined system, which I believe is a bug.

If we look at the equations we see...

julia> initprob.f.sys |> equations
1-element Vector{Equation}:
 0 ~ -src₊output₊u(t) + ModelingToolkitStandardLibrary.Blocks.get_sampled_data(t, src₊buffer)

But if we look at the observed, we can see that src₊output₊u(t) is already known and shouldn't be an equation.

julia> ModelingToolkit.observed(initprob.f.sys)[2]
src₊output₊u(t) ~ ModelingToolkitStandardLibrary.Blocks.get_sampled_data(0.0, src₊buffer)

Versions...

Status `C:\Users\bradl\AppData\Local\Temp\jl_uvgnDL\Project.toml`

  [961ee093] ModelingToolkit v9.60.0
  [16a59e39] ModelingToolkitStandardLibrary v2.19.0 `C:\Work\ModelingToolkitStandardLibrary.jl`
@bradcarman bradcarman added the bug Something isn't working label Jan 11, 2025
@AayushSabharwal
Copy link
Member

MTK is not always able to identify identical equations. This is a problem with the model which has both an observed equation and identical default: https://github.com/SciML/ModelingToolkitStandardLibrary.jl/blob/7197b13f1413a70b498eccdddfae54e11974c14e/src/Blocks/sources.jl#L672-L678

@ChrisRackauckas
Copy link
Member

Oh that's a clear user error, yes.

@bradcarman
Copy link
Contributor Author

Fixed with PR SciML/ModelingToolkitStandardLibrary.jl#355

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