vpython / vpython-jupyter

3D visualization made easy
MIT License
141 stars 64 forks source link

Websocket hang on JupyterLab + JupyterHub while classic Notebook + JupyterHub is OK #137

Closed gwtaylor closed 3 years ago

gwtaylor commented 3 years ago

Hello,

For a third year undergraduate course we are running JupyterHub 1.3.0 which is configured to serve up JupyterLab 3.0.9 by default. The Python version is 3.8.8 and VPython is at 7.6.1. Everything has been installed via conda.

Starting a new notebook in JupyterLab and running the MWE of:

from vpython import *
scene = canvas()
sphere()

results in the first cell executing fine and the second cell hung on [*] with no output. When I interrupt the kernel I see

/opt/conda/lib/python3.8/site-packages/vpython/with_notebook.py in <module>
    151 baseObj.glow = GlowWidget(wsport=__SOCKET_PORT, wsuri='/ws')
    152 while (not wsConnected):
--> 153     time.sleep(0.1)          # wait for websocket to connect
    154 
    155 baseObj.trigger()  # start the trigger ping-pong process

which is similar to what is described in this thread: https://groups.google.com/g/vpython-users/c/yd1aO79mdV0?pli=1 We tried the fix in the last post of that thread to no avail.

I understand that this issue was supposed to be resolved for non-localhost type setups (like JupyterHub or Binder) as per #28.

Interestingly, if we start in Classic notebook by replacing /lab in the URL with /tree, or using the “Launch Classic Notebook” item in JupyterLab’s Help menu, the MWE works perfectly fine.

So it seems to be the combination of JupyterLab and JupyterHub that's preventing the opening of the websocket.

mwcraig commented 3 years ago

Thanks for reporting this -- we are long overdue for an update to our jupyterlab extension. Likely will be a couple of weeks before I can get to it, but we need a new release for the last jlab 2 and for the new extension mechanism in jlab 3.

gwtaylor commented 3 years ago

Thanks! Yes, I saw #95 open as well. We're happy to test it out when it's ready.

jcoady commented 3 years ago

There is now a prebuilt extension for VPython 7.6.1 that works with JupyterLab 3. You can install it with the command.

pip install jupyterlab-vpython

You can go ahead and test it out on your system.

John

gwtaylor commented 3 years ago

Super! I'm in touch with my team and we'll try it out and report back.

jcoady commented 3 years ago

I updated jupyterlab-vpython to work on JupyterHub and MyBinder with VPython version 7.6.1 . The updated version of jupyterlab-vpython that works with VPython 7.6.1 is version 3.0.4 and can be installed using

pip install jupyterlab-vpython

https://pypi.org/project/jupyterlab-vpython/

gwtaylor commented 3 years ago

Thanks! The first extension update 4 days ago did not work for us (still hung in JupyterHub), but the most recent change did the trick. We were able to run the MWE with no problems. We're running JupyterLab 3.0.15 on top of JupyterHub 1.3.0. Here are the other packages FWIW:

jupyter --version
jupyter core     : 4.7.0
jupyter-notebook : 6.1.6
qtconsole        : 5.1.0
ipython          : 7.23.1
ipykernel        : 5.4.2
jupyter client   : 6.1.7
jupyter lab      : 3.0.15
nbconvert        : 6.0.7
ipywidgets       : 7.6.3
nbformat         : 5.0.8
traitlets        : 5.0.5

The term just ended for us, but we're really happy to be going into the summer with no lingering issues. Thanks again for your work on the package.

jcoady commented 3 years ago

I'm glad you got it working on your JupyterHub. The fix from last week only seemed to work on a local machine so after further investigation I managed to get it working on MyBinder as well as JupyterHub. Does MWE stand for Managed Working Environment? May I ask what you are using vpython for? After googling your name it looks like you do work related to Artificial Intelligence and Machine Learning. Are you combining AI or ML with vpython? I previously created this notebook that combined the AI CartPole demo program using google Muzero algorithm and visualized with vpthon.

https://mybinder.org/v2/gh/jcoady/notebook/master?filepath=MuZero%2FCart-Pole%2FMuZeroCartPoleVPython.ipynb

gwtaylor commented 3 years ago

Hi John, Thanks for your interest! By MWE I just meant the minimal working example (the Sphere example in my initial post in this thread). You are correct, I am an AI/ML researcher. However, we're not using vpython in my research group but in an undergraduate engineering course: ENGG*3130 Modelling Complex Systems: https://uoguelph-engg3130.github.io/engg3130/

In that course, we're using Allen B. Downey's wonderful book Think Complexity. He made a series of Jupyter Notebooks which we're using for the labs. He also wrote code to implement the famous "Boids" algorithm, which uses vpython as a dependency: https://github.com/AllenDowney/ThinkComplexity2/blob/master/code/Boids7.py

I adapted that for the notebook, which is what brought me to vpython-jupyter.

On the research front, we do have some recent work which mixes 3D modelling and machine learning (a generative model of 3d worlds), but no vpython involved there: https://github.com/apple/ml-gsn

I wish I knew about your MuZero CartPole demo before the class ended; I would have demoed it! Well there's always the future offering.

jcoady commented 3 years ago

Thanks for sharing. I like the Boids7.py example program that makes use of vpython. If you haven't seen these yet here are more vpython demo programs you can try out if you want to see what vpython can do. https://glowscript.org/#/user/GlowScriptDemos/folder/Examples/ Just click on any of the images to run that vpython program in your browser. Since JupyterLab3 is now working on your JupyterHub I am going to go ahead and close this issue.

jcoady commented 3 years ago

Closing this issue since VPython 7.6.1 now works in JupyterLab 3 with JupyterHub by installing jupyterlab-vpython version 3.0.4 with the command.

pip install jupyterlab-vpython