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

structural_simplify messes with hasproperty for parameters #3016

Closed
hexaeder opened this issue Sep 4, 2024 · 1 comment · Fixed by #3149
Closed

structural_simplify messes with hasproperty for parameters #3016

hexaeder opened this issue Sep 4, 2024 · 1 comment · Fixed by #3149
Assignees
Labels
bug Something isn't working

Comments

@hexaeder
Copy link
Contributor

hexaeder commented Sep 4, 2024

Describe the bug 🐞
I'm really sorry for spamming your issue tracker, but I'll provide MWEs at least...

A simplified system has weird behaviour for hasproperty and getproperty: namely it might lie about properties being present or not present!

Expected behavior

hasproperty true  => getproperty does not error
hasproperty false => getproperty errors

Minimal Reproducible Example 👇

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as Dt
@mtkmodel Inner begin
    @parameters begin
        p
    end
end
@mtkmodel Outer begin
    @components begin
        inner = Inner()
    end
    @variables begin
        x(t)
    end
    @equations begin
        x ~ inner.p
    end
end
@named outer = Outer()
simp = structural_simplify(outer)

hasproperty(outer, :inner)   # true
outer.inner # works
hasproperty(outer, :inner₊p) # false
outer.inner₊p # errors as expected

hasproperty(simp, :inner)   # false
simp.inner # still works
hasproperty(simp, :inner₊p) # true
inner.inner₊p # errors despite hasproperty true

Error & Stacktrace ⚠️

julia> outer.inner₊p # errors despite hasproperty
ERROR: ArgumentError: System outer: variable inner₊p does not exist
Stacktrace:
 [1] getvar(sys::ODESystem, name::Symbol; namespace::Bool)
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/yfT8s/src/systems/abstractsystem.jl:1066
 [2] getproperty(sys::ODESystem, name::Symbol; namespace::Bool)
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/yfT8s/src/systems/abstractsystem.jl:1009
 [3] getproperty(sys::ODESystem, name::Symbol)
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/yfT8s/src/systems/abstractsystem.jl:1005
 [4] top-level scope
   @ none:1

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
Status `/tmp/jl_QTt44V/Project.toml`
  [961ee093] ModelingToolkit v9.36.0
  • Output of versioninfo()
julia> versioninfo()
Julia Version 1.11.0-rc3
Commit 616e45539db (2024-08-26 15:46 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 9 8945HS w/ Radeon 780M Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
Environment:
  JULIA_NUM_THREADS = auto
@hexaeder hexaeder added the bug Something isn't working label Sep 4, 2024
@ChrisRackauckas
Copy link
Member

Hmm seems like a bug with the naming / hierarchical handling.

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
3 participants