oscar-system / Polymake.jl

Interface to Polymake using CxxWrap
Other
28 stars 19 forks source link

IJulia in a multi user environment trying to write in global kernel resource_dir #430

Closed LukasMueller187 closed 1 year ago

LukasMueller187 commented 1 year ago

Hi,

I'm trying to make OSCAR available precompiled in a multi user environment (JupyterHub). The kernel is living in /usr/local/share/jupyter/kernels/julia-1.8, therefore global (state of the art).

Calling using Oscar throws:

InitError: IOError: mkdir("/usr/local/share/jupyter/kernels/julia-1.8/polymake"; mode=0o777): permission denied (EACCES)
during initialization of module Polymake

Stacktrace:
  [1] uv_error
    @ ./libuv.jl:97 [inlined]
  [2] mkdir(path::String; mode::UInt16)
    @ Base.Filesystem ./file.jl:185
  [3] mkpath(path::String; mode::UInt16)
    @ Base.Filesystem ./file.jl:241
  [4] mkpath
    @ ./file.jl:235 [inlined]
  [5] copy_javascript_files(target_dir::String)
    @ Polymake /usr/share/julia/packages/Polymake/A0Z5B/src/ijulia.jl:7
  [6] prepare_jupyter_kernel_for_visualization()
    @ Polymake /usr/share/julia/packages/Polymake/A0Z5B/src/ijulia.jl:31
  [7] __init__()
    @ Polymake /usr/share/julia/packages/Polymake/A0Z5B/src/Polymake.jl:161
  [8] _include_from_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})
    @ Base ./loading.jl:831
  [9] _tryrequire_from_serialized(modkey::Base.PkgId, path::String, sourcepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:938
 [10] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt64)
    @ Base ./loading.jl:1028
 [11] _require(pkg::Base.PkgId)
    @ Base ./loading.jl:1315
 [12] _require_prelocked(uuidkey::Base.PkgId)
    @ Base ./loading.jl:1200
 [13] macro expansion
    @ ./loading.jl:1180 [inlined]
 [14] macro expansion
    @ ./lock.jl:223 [inlined]
 [15] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1144

As stated in the stacktrace, ijulia.jl is trying to write in the global kernel directory (or called resource_dir by kernelspec, see line 31). This is of course not possible for the user. I didn't find any environments variables to set in order to direct the IJulia part of Polymake to write into the home directory.

Any ideas?

Best regards

benlorenz commented 1 year ago

Thanks for the report, we will make that kernel installation more robust very soon, there is an open ticket about it here: https://github.com/oscar-system/Polymake.jl/issues/427 With these changes an error during the initialization will not be fatal anymore.

But these files (unfortunately) need to be in the resource_dir of the ijulia kernel, so unless these are put there manually, threejs visualization will not work in a notebook.

benlorenz commented 1 year ago

I have just created a PR for this, https://github.com/oscar-system/Polymake.jl/pull/431 This will still print a warning if only such a global (read-only) resource directory exists and the files are not there. We need:

close.svg
menu.svg
OrbitControls.js
Projector.js
SVGRenderer.js
three.js
TrackballControls.js
WebGL.js

from

const _jupyter_resources = joinpath(polymake_jll.artifact_dir, "share",
                                 "polymake", "resources", "jupyter-polymake",
                                 "jupyter_kernel_polymake", "resources")
LukasMueller187 commented 1 year ago

Thanks for the response and the changes!

Yep I did manage to fix it after your message that there is no e. g. env variable to force another directory. I was sceptical due to not knowing whether the files are suitable for read-only global files. But it seems that they are suitable and need not to be written to by the user. I simply copied the files to:

/usr/local/share/jupyter/kernels/julia-1.8
├── kernel.json
├── logo-32x32.png
├── logo-64x64.png
├── logo-svg.svg
└── polymake
    ├── close.svg
    ├── menu.svg
    ├── OrbitControls.js
    ├── Projector.js
    ├── SVGRenderer.js
    ├── three.js
    ├── TrackballControls.js
    └── WebGL.js

Maybe Polymake should behave somehow like the matplotlib backend ipympl (which is an nbextension?) and or the IJulia kernel should behave similar to ipython which does write locally in ~/.ipython. But that's just an idea and for sure a lot of work (and more of an IJulia topic).

Note: this will likely break again as soon as there are new versions of the files that are needed for an updated version.

benlorenz commented 1 year ago

Thanks for the hint, converting our threejs stuff into an nbextension might indeed work and improve this setup. I wasn't really aware what those do, the documentation seems a bit sparse.

The IJulia kernel is by default installed into $HOME/.local/share/jupyter which is why this usually doesn't cause problems.