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

Incorrect results using Complex variable in @mtkmodel #3014

Open
hexaeder opened this issue Sep 4, 2024 · 1 comment
Open

Incorrect results using Complex variable in @mtkmodel #3014

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

Comments

@hexaeder
Copy link
Contributor

hexaeder commented Sep 4, 2024

Describe the bug 🐞
followup on #2895

The recently introduced handling of complex variables in @mtkmodel #2935 leads to incorrect results. See MWE with different results within and without @mtkmodel

Expected behavior

Expansion of complex equations should yield the same result regardless of construction method...

Minimal Reproducible Example 👇

# wrong results in @mtkmodel
@independent_variables t
@mtkmodel ComplexModel begin
    @variables begin
        x(t)
        y(t)
        z(t)::Complex
    end
    @equations begin
        z ~ x + im*y
    end
end
@named mixed = ComplexModel()
full_equations(mixed)
# 2-element Vector{Equation}:
#  z(t) ~ x(t)
#  0 ~ y(t)

# correct results in ode system
@independent_variables t
@variables x(t) y(t) z(t)::Complex
eqs = z ~ x + im*y # notice how complex equation returns Vector{Equation}
sys = ODESystem(eqs, t; name=:ComplexModel)
full_equations(sys)
# 2-element Vector{Equation}:
#  real(z(t)) ~ x(t)
#  imag(z(t)) ~ y(t)

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
(jl_QTt44V) pkg> st
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

@ven-k can we make sure this at least errors if not fixed?

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