oscar-system / Polymake.jl

Interface to Polymake using CxxWrap
Other
25 stars 18 forks source link

visual() / threejs issue with Jupyter Lab #338

Open vukk opened 3 years ago

vukk commented 3 years ago

The following bug seems to be present when using Jupyter Lab notebooks: Writing

using Polymake;
p2 = @pm polytope.Polytope{}(POINTS=[1 -1 -1; 1 1 -1; 1 -1 1; 1 1 1; 1 0 0], INPUT_LINEALITY=[0 1 0])
visual(p2)

results in Uncaught ReferenceError: requirejs is not defined in the web console.

Similar issues in other packages, reported elsewhere:

Version information: JupyterLab Version 3.0.5 Julia 1.5.3 Polymake.jl 0.5.5 Polymake.version() -> v"4.3.0"

Workaround: ThreeJS works in a classic notebook. Open your notebook as a classic notebook in Jupyter Lab via Help -> Launch Classic Notebook.

kalmarek commented 3 years ago

@vukk thanks for reporting, but reading the discourse thread I couldn't understand what is the underlying problem and if there is something we could do about. Will the issue be resolved in jupyterlab (i.e. upstream?)


As a sidenote you can use

using Polymake
p2 = polytope.Polytope(POINTS=[1 -1 -1; 1 1 -1; 1 -1 1; 1 1 1; 1 0 0], INPUT_LINEALITY=[0 1 0])
visual(p2)

without macro magic ;)

benlorenz commented 3 years ago

The underlying problem is that the normal jupyter interface has RequireJS loaded and we use that to load three.js from within the notebook. But jupyterlab does not have requirejs active and I don't think this will change, it seems to be a different design that we are not compatible with right now. There does seem to be a pythreejs package that can also be installed for jupyterlab, but that seems rather complicated from a user-perspective in comparison to just running the visual command ....

Maybe you could try installing jupyter-require ? But I don't know if this needs any extra stuff in the notebook to make it work. Edit: or maybe jupyterlab_requirejs since the jupyter-require repo is archived ...

vukk commented 3 years ago

The underlying problem is that the normal jupyter interface has RequireJS loaded and we use that to load three.js from within the notebook. But jupyterlab does not have requirejs active and I don't think this will change, it seems to be a different design that we are not compatible with right now.

This is correct. I'd add that the JupyterLab documentation states:

JupyterLab will eventually replace the classic Jupyter Notebook. Throughout this transition, the same notebook document format will be supported by both the classic Notebook and JupyterLab.

The pythreejs package seems to be more for writing custom javascript into your notebook for visualization.

I'm not sure if it is possible right now for you, and how they work within jupyter, but in the long run I'd look into trying to use native ES6 imports

If I was working in frontend/fullstack right now, I'd try to fix this myself. However, I'm unfortunately a bit out of practice and currently deep in the thesis swamp :)

benlorenz commented 3 years ago

Thanks a lot for the input, we will try look into this but it might take a bit.

If I remember correctly we had plenty of problems getting this to work at all when we started this (and then never really touched it because it was working), but probably things are somewhat better now. At least it looks like the threejs examples that we need are available as modules now.