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.43k stars 209 forks source link

Guess for parameter not reflected in `guesses` of system #3075

Closed hexaeder closed 1 week ago

hexaeder commented 1 month ago

Describe the bug 🐞

If you attach a guess to a parameter, it isn't reflected in the guesses of the system

Expected behavior

Have guesses contain all guesses.

Minimal Reproducible Example 👇 Example 1:

julia> begin
               @independent_variables t
               @parameters a [guess=2]
               @variables x(t) [guess=1]
               @named sys = ODESystem([x ~ a], t)
               guesses(sys)
           end
Dict{Any, Any} with 1 entry:
  x(t) => 1

Example 2:

  @mtkmodel MyMod begin
        @components begin
            a = RealInput(guess=1)
        end
        @parameters begin
            b, [guess=2]
        end
    end
    @named model = MyMod()
    guesses(model)       # knows only about a.u=1
    getguess(model.b)    # guess b=2 locally stored
    getguess(model.a.u)  # guess u=1 not locally stored

Environment (please complete the following information):

⌃ [13f3f980] CairoMakie v0.12.9
  [459566f4] DiffEqCallbacks v3.9.1
  [7d51a73a] ExplicitImports v1.9.0
  [86223c79] Graphs v1.11.2
⌅ [ee78f7c6] Makie v0.21.9
⌃ [961ee093] ModelingToolkit v9.39.0
⌃ [16a59e39] ModelingToolkitStandardLibrary v2.11.0
  [127b3ac7] OrdinaryDiffEqNonlinearSolve v1.2.1
  [43230ef6] OrdinaryDiffEqRosenbrock v1.2.0
  [b1df2697] OrdinaryDiffEqTsit5 v1.1.0
hersle commented 1 week ago

Was this fixed? On MTK v9.49:

using ModelingToolkit
@independent_variables t
@parameters a [guess=2]
@variables x(t) [guess=1]
@named sys = ODESystem([x ~ a], t)
guesses(sys)
Dict{Any, Any} with 2 entries:
  a    => 2
  x(t) => 1

using ModelingToolkitStandardLibrary.Blocks
@mtkmodel MyMod begin
    @components begin
        a = RealInput(guess=1)
    end
    @parameters begin
        b, [guess=2]
    end
end
@named model = MyMod()
guesses(model)
Dict{Any, Any} with 2 entries:
  a₊u(t) => 1
  b      => 2
hexaeder commented 1 week ago

Yep, seems fixed. I tried to find the corresponding PR, but no luck.