I have Julia installed on two different computers and the code executes differently on each one despite having the same versions of VSCode, Julia, and installed packages (everything is the most recent release version).
The basic example from the Package Readme should work like this:
julia> @variables x[1:3];
julia> x
3-element Array{Operation,1}:
x₁()
x₂()
x₃()
However, using one of the computers, it returns:
julia> @variables x[1:3];
julia> x
x[1:3]
where x is a 1-element Vector{Symbolics.Arr{Num, 1}}. Both are using Windows 10 and I’m using VS Code to run the script. The same thing happens for the @variables macro.
I understand that this is quite a vague question, I’m just not sure where I should be looking to find out what the problem is? Any pointers would be appreciated.
julia> using Symbolics
julia> @macroexpand @variables x[1:3]
quote
x = (identity)((Symbolics.wrap)((SymbolicUtils.setmetadata)((SymbolicUtils.setmetadata)((Sym){Array{Real, (length)((1:3,))}}(:x), Symbolics.ArrayShapeCtx, (1:3,)), Symbolics.VariableSource, (:variables, :x))))
[x]
end
julia> x
ERROR: UndefVarError: x not defined
Your second option is expected. If you see the first, it’s because you installed an old version. If you’re getting different things on different computers, it’s because you’ve installed different versions of the packages.
Check which version you installed using import Pkg; Pkg.status()
julia> using Symbolics
julia> @macroexpand @variables x[1:3]
quote
x = (identity)(map(Iterators.product(1:3)) do ind
#= C:\Users\mholmes\.julia\packages\Symbolics\sITWZ\src\variable.jl:227 =#
(Num)((SymbolicUtils.Sym){Real}(:x, ind...))
end)
[x]
end
I see two possibilities: either your packages are different (see @odow’s remark regarding Pkg.status()) or something external is influencing the behavior of @variables. I tried to look into the source of Symbolics.jl but that is way over my head.
I also see
quote
x = (identity)((Symbolics.wrap)((SymbolicUtils.setmetadata)((SymbolicUtils.setmetadata)((SymbolicUtils.Sym){Array{Real, (length)((1:3,))}}(:x), Symbolics.ArrayShapeCtx, (1:3,)), Symbolics.VariableSource, (:variables, :x))))
[x]
end
so the first seems to be the better version. Question to others: is there a way to find out where a macro is defined (similar to methods)?
Edit: one more hint that your second system uses an outdated version of Symbolics
which, indeed, are outdated: current github versions seem to be v8.6.0, v0.19.7, and v4.4.1 respectively. However, using Pkg.update() doesn’t update anything - it seems to think that it’s up to date.
Is there a way that I can force it? Maybe an uninstall and reinstall? I don’t think it is a Julia version issue as I am using the most recent release:
julia> VERSION
v"1.7.2"
Finally, do you have an idea why this newer version is this way? I rather liked having subscripts next to the state variables, differentiating between x₁, x₂, etc. The current version seems to be less featureful.
This did the trick! I now get the same result on both systems and I have Symbolics v4.4.1 when I run Pkg.status() in this new environment.
So, to prevent this happening again, I should try and find other installed package(s) to see what’s holding this system back? Or is it standard practice to use different environments for different projects to ensure that installed packages don’t cause problems with each other?