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

Julia + VSCode produces import error from ModelingToolkit #1444

Closed
koustav-pal opened this issue Feb 3, 2022 · 12 comments
Closed

Julia + VSCode produces import error from ModelingToolkit #1444

koustav-pal opened this issue Feb 3, 2022 · 12 comments

Comments

@koustav-pal
Copy link

Hi,

I’m trying to get started with ModelingToolKit. I’m using Julia through a jupyter notebook in VSCode. The environment is different from the default environment used by the command line julia executable. Julia itself is installed under a conda environment.

I’m running into an import error from ModelingToolKit

ERROR: LoadError: MethodError: no method matching static_loop(::Symbol, ::Int64, ::Int64, ::Missing)
Closest candidates are:
  static_loop(::Symbol, ::Int64, ::Int64, ::Int64) at ~/anaconda3/envs/julia-1.7.1/share/julia/packages/LoopVectorization/ndGJi/src/reconstruct_loopset.jl:64

ModelingToolkit was installed using Pkg.add("ModelingToolkit", preserve = PRESERVE_ALL) which should preserve all dependencies from ModelingToolkit.

How can I rectify this? Should I just set the JuliaEnvironmentpath to the manifest.toml used by the commandline julia executable?

@ChrisRackauckas
Copy link
Member

@chriselrod I thought you said versioning should prevent this?

@chriselrod
Copy link
Contributor

chriselrod commented Feb 3, 2022

@chriselrod I thought you said versioning should prevent this?

It should.
It seems to be using ArrayInterface 4 + LoopVectorization.jl, even though no version of LoopVectorization.jl is compatible with ArrayInterface 4.
@Tokazama, any idea why?
Could this be a package resolver bug?
Or did some older version already start returning missing ?

@koustav-pal, could you give me your ArrayInterface.jl and LoopVectorization.jl versions?

@koustav-pal
Copy link
Author

koustav-pal commented Feb 3, 2022

Hi @chriselrod ,

For LoopVectorization version is v0.12.101

julia> using LoopVectorization
 │ Package LoopVectorization not found, but a package named LoopVectorization is available from a registry. 
 │ Install package?
 │   (@julia-1.7.1) pkg> add LoopVectorization 
 └ (y/n) [y]: y
   Resolving package versions...
    Updating `~/anaconda3/envs/julia-1.7.1/share/julia/environments/julia-1.7.1/Project.toml`
  [bdcacae8] + LoopVectorization v0.12.101
  No Changes to `~/anaconda3/envs/julia-1.7.1/share/julia/environments/julia-1.7.1/Manifest.toml`

However, ArrayInterface version is v3.2.2. Edited because the package had not been imported from the registry

julia> using ArrayInterface
 │ Package ArrayInterface not found, but a package named ArrayInterface is available from a registry. 
 │ Install package?
 │   (@julia-1.7.1) pkg> add ArrayInterface 
 └ (y/n) [y]: y
   Resolving package versions...
    Updating `~/anaconda3/envs/julia-1.7.1/share/julia/environments/julia-1.7.1/Project.toml`
  [4fba245c] + ArrayInterface v3.2.2
  No Changes to `~/anaconda3/envs/julia-1.7.1/share/julia/environments/julia-1.7.1/Manifest.toml`

Running Julia conda build

julia 1.7.1 h132cb31_3 conda-forge

Full conda environment listed below

appnope                   0.1.2                    pypi_0    pypi
arpack                    3.7.0                hefb7bc6_2    conda-forge
asttokens                 2.0.5                    pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
black                     22.1.0                   pypi_0    pypi
bzip2                     1.0.8                h1de35cc_0
c-ares                    1.18.1               h0d85af4_0    conda-forge
ca-certificates           2021.10.8            h033912b_0    conda-forge
certifi                   2021.10.8       py310h2ec42d9_1    conda-forge
click                     8.0.3                    pypi_0    pypi
curl                      7.81.0               hf45b732_0    conda-forge
decorator                 5.1.1                    pypi_0    pypi
executing                 0.8.2                    pypi_0    pypi
expat                     2.4.4                he49afe7_0    conda-forge
gettext                   0.19.8.1          h7937167_1005    conda-forge
git                       2.35.0          pl5321h9a53687_0    conda-forge
gmp                       6.2.1                h2e338ed_0    conda-forge
ipython                   8.0.1                    pypi_0    pypi
jedi                      0.18.1                   pypi_0    pypi
julia                     1.7.1                h132cb31_3    conda-forge
krb5                      1.19.2               hcfbf3a7_3    conda-forge
libblas                   3.9.0           13_osx64_openblas    conda-forge
libcblas                  3.9.0           13_osx64_openblas    conda-forge
libcurl                   7.81.0               hf45b732_0    conda-forge
libcxx                    12.0.0               h2f01273_0
libedit                   3.1.20191231         h0678c8f_2    conda-forge
libev                     4.33                 haf1e3a3_1    conda-forge
libffi                    3.3                  hb1e8313_2
libgfortran               5.0.0           9_3_0_h6c81a4c_23    conda-forge
libgfortran5              9.3.0               h6c81a4c_23    conda-forge
libiconv                  1.16                 haf1e3a3_0    conda-forge
liblapack                 3.9.0           13_osx64_openblas    conda-forge
libnghttp2                1.46.0               h6f36284_0    conda-forge
libopenblas               0.3.18          openmp_h3351f45_0    conda-forge
libopenblas-ilp64         0.3.18          openmp_h470725b_0    conda-forge
libosxunwind              0.0.6                h940c156_0    conda-forge
libssh2                   1.10.0               h52ee1ee_2    conda-forge
libutf8proc               2.7.0                h0d85af4_0    conda-forge
libzlib                   1.2.11            h9173be1_1013    conda-forge
llvm-openmp               12.0.1               hda6cdc1_1    conda-forge
matplotlib-inline         0.1.3                    pypi_0    pypi
metis                     5.1.0             h2e338ed_1006    conda-forge
mpfr                      4.1.0                h0f52abe_1    conda-forge
mypy-extensions           0.4.3                    pypi_0    pypi
ncurses                   6.3                  hca72f7f_2
openblas-ilp64            0.3.18          openmp_ha601604_0    conda-forge
openlibm                  0.7.5                h0d85af4_0    conda-forge
openssl                   1.1.1l               h0d85af4_0    conda-forge
p7zip                     16.02             he49afe7_1000    conda-forge
parso                     0.8.3                    pypi_0    pypi
pathspec                  0.9.0                    pypi_0    pypi
pcre2                     10.37                ha16e1b2_0    conda-forge
perl                      5.32.1          1_h0d85af4_perl5    conda-forge
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pip                       21.2.4          py310hecd8cb5_0
platformdirs              2.4.1                    pypi_0    pypi
prompt-toolkit            3.0.26                   pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pygments                  2.11.2                   pypi_0    pypi
python                    3.10.0               hdfd78df_3
python_abi                3.10                    2_cp310    conda-forge
readline                  8.1.2                hca72f7f_1
setuptools                58.0.4          py310hecd8cb5_0
six                       1.16.0                   pypi_0    pypi
sqlite                    3.37.0               h707629a_0
stack-data                0.1.4                    pypi_0    pypi
suitesparse               5.10.1               h7aff33d_1    conda-forge
tbb                       2021.5.0             h940c156_0    conda-forge
tk                        8.6.11               h7bc2e8c_0
tomli                     2.0.0                    pypi_0    pypi
traitlets                 5.1.1                    pypi_0    pypi
tzdata                    2021e                hda174b7_0
wcwidth                   0.2.5                    pypi_0    pypi
wheel                     0.37.1             pyhd3eb1b0_0
xz                        5.2.5                h1de35cc_0
zlib                      1.2.11            h9173be1_1013    conda-forge

@chriselrod
Copy link
Contributor

chriselrod commented Feb 3, 2022

Could you dev LoopVectorization and show me the full stacktrace?

function Loop(ls::LoopSet, ex::Expr, sym::Symbol, ::Type{R}) where {R<:AbstractRange}
  f = ArrayInterface.known_first(R)
  s = ArrayInterface.known_step(R)
  l = ArrayInterface.known_last(R)
  ub = upper_bound(R)
  Loop(ls, ex, sym, f, s, l, ub)
end

I want to know the type of R here. If the stacktrace does not show it, could you dev LoopVectorization, using LoopVectorization, Revise, and then edit this function (src/reconstruct_loopset.jl line 56), writing:

function Loop(ls::LoopSet, ex::Expr, sym::Symbol, ::Type{R}) where {R<:AbstractRange}
  f = ArrayInterface.known_first(R)
  s = ArrayInterface.known_step(R)
  l = ArrayInterface.known_last(R)
  ub = upper_bound(R)
  @show f, s, l
  @show Main.@which ArrayInterface.known_first(R)
  @show Main.@which ArrayInterface.known_step(R)
  @show Main.@which ArrayInterface.known_last(R)
  Loop(ls, ex, sym, f, s, l, ub)
end

Then run the code to get this error again, and show me what it says.
Printing might give a task-switching error after you edit these, as this code will be called from inside a generated function. Normally, it'll work/print the second time you run the code.

Also, the package versions of the packages that show up in the @which.

@Tokazama
Copy link

Tokazama commented Feb 3, 2022

Or did some older version already start returning missing ?

I'm fairly certain that if other versions of ArrayInterface return missing it is bug. I was very strict about versioning on that change.

@chriselrod
Copy link
Contributor

chriselrod commented Feb 3, 2022

Or did some older version already start returning missing ?

I'm fairly certain that if other versions of ArrayInterface return missing it is bug. I was very strict about versioning on that change.

If it really is a Pkg bug, it'd be great if we can get a reproducible example of it choosing incompatible versions so that we can file an issue.

I'd also like to see the array types, because maybe they're defined in some other package that saw ArrayInterface changed to missing and updated without actually setting package bounds correctly.

@koustav-pal
Copy link
Author

koustav-pal commented Feb 3, 2022

Hi @chriselrod ,

I did a few tests.

  • I added the default julia.environmentPath to my Julia settings.json in Visual Studio Code.

  • This fixed the issue. I was able to import ModelingToolkit in the jupyter notebook.

  • Next, I remove the julia.environmentPath from the julia settings.json in Visual Studio Code.

  • I was still able to import ModelingToolkit in the jupyter notebook.

  • Next, I changed the project directory to a test directory under ${HOME} but outside the ~/.julia folder at the same location.

  • I was still able to import ModelingToolkit in the jupyter notebook.

  • Last, as a last resort just to try and reproduce the error I tried to reinstall the entire conda julia stack under a new environment and reinitialised the new kernel under a new environment.

  • I was still able to import ModelingToolkit in the jupyter notebook successfully.

So, I guess whatever error occured, it occurred before julia.environmentPath was set. Unfortunately, I am unable to reproduce the error. I can try and remove the entire .julia cache under $HOME. But, would prefer not to do so as it takes a while for julia set itself up inside my vscode jupyter instance.

Do you think we can close this issue for now?

@chriselrod
Copy link
Contributor

chriselrod commented Feb 3, 2022

Do you think we can close this issue for now?

No one can reproduce it (AFAIK?), but it keeps coming up.
Even though it should not be able to.

@ValentinKaisermayer
Copy link
Member

Experienced this on v8.5.2 too. I updated everything, tried adding LoopVectorization explicitly and precompiling it on its own. Nothing worked.
However, if I start Julia in a powershell (not the VSCode REPL), and activate the same environment, precompile works fine and I am able to import ModelingToolkit.

@ChrisRackauckas
Copy link
Member

This should be solved by now? All of the ArrayInterface stuff received its bump? Can you try ]add ArrayInterface@5 and see what happens?

@ValentinKaisermayer
Copy link
Member

Seems to work, or at least I can not reproduce the issue anymore.

@YingboMa
Copy link
Member

Seems safe to close it now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants