You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This seems to be a difficulty in pointing parse_expr_to_symbolic to the right scope. In the below MWE, parse_expr_to_symbolic() silently "misses" the @variables declared in the function test(). I believe it creates new, non-time-dependent variables in Main scope as well.
I guess this make sense if one understands the difference between module scope and function scope, but is a potential source for errors and is probably not the desired behavior for most users. The documentation has a nice warning about this, so thanks for that.
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
#GLOBAL SCOPE
@variables x(t) y(t) a b
str_one = "a + b*b + x + y*y"
println(Symbolics.parse_expr_to_symbolic(Meta.parse(str_one), @__MODULE__))
#function scope
function test()
@variables u(t) v(t) c d
str_two = "c + d*d + u + v*v"
println(Symbolics.parse_expr_to_symbolic(Meta.parse(str_two), @__MODULE__))
println(Symbolics.parse_expr_to_symbolic(Meta.parse(str_one), @__MODULE__))
end
test()
OUTPUT:
a + x(t) + b^2 + y(t)^2
c + u + d^2 + v^2
a + x(t) + b^2 + y(t)^2
The text was updated successfully, but these errors were encountered:
This seems to be a difficulty in pointing parse_expr_to_symbolic to the right scope. In the below MWE, parse_expr_to_symbolic() silently "misses" the @variables declared in the function test(). I believe it creates new, non-time-dependent variables in Main scope as well.
I guess this make sense if one understands the difference between module scope and function scope, but is a potential source for errors and is probably not the desired behavior for most users. The documentation has a nice warning about this, so thanks for that.
OUTPUT:
The text was updated successfully, but these errors were encountered: