Kitware / trame

Trame lets you weave various components and technologies into a Web Application solely written in Python.
https://kitware.github.io/trame/
Other
426 stars 56 forks source link

vscode remote support on NERSC? #468

Closed swelborn closed 7 months ago

swelborn commented 8 months ago

Describe the bug

The example from https://kitware.github.io/trame/guide/deployment/jupyter.html does work in jupyter on my local machine (mac), both in jupyter and vscode.

image

I am trying to test this out on NERSC through both NERSC's jupyterhub and vscode. It doesn't render in either.

It is understandable that NERSC's jupyterhub -- I have had issues rendering widgets from third parties (e.g., bqplot widgets are not registered with the jupyterlab instance they are running on the hub, and so they can't render there). Ideally it would work there, though.

However, I'm unsure why it wouldn't work through vscode. I have tried two routes:

  1. Select python from conda env binary as kernel: Screenshot 2024-03-03 at 12 24 09 PM

  2. Select existing jupyterlab instance after registering test-trame-py312 in available kernels:

    conda activate test-trame-py312
    python -m ipykernel install --user --name test-trame-312 --display-name trame-312
    jupyter lab --ip=$(hostname -i) --no-browser

Connect to this jupyterlab server: Screenshot 2024-03-03 at 12 33 03 PM

Select "Existing jupyter server" Screenshot 2024-03-03 at 12 33 39 PM

When I connect to the server through vscode, I see that it is starting the kernel[I 2024-03-03 09:30:49.879 ServerApp] Kernel started:

and I can import trame, etc. When I run the example (cone) I don't get a render. You can see that it shows the first output line ('new resolution 6'), but no cone: image

even though --log-level=DEBUG on the jupyterlab instance shows that display_data is executing in the UI output cell.

[D 2024-03-03 09:57:05.401 ServerApp] activity on ce38639c-6f47-4945-989a-a0155fc68859: status (busy)
[D 2024-03-03 09:57:05.402 ServerApp] activity on ce38639c-6f47-4945-989a-a0155fc68859: execute_input
[D 2024-03-03 09:57:05.498 ServerApp] activity on ce38639c-6f47-4945-989a-a0155fc68859: stream
[D 2024-03-03 09:57:05.498 ServerApp] activity on ce38639c-6f47-4945-989a-a0155fc68859: display_data
[D 2024-03-03 09:57:05.501 ServerApp] activity on ce38639c-6f47-4945-989a-a0155fc68859: status (idle)

I also tried this with python=3.10 to no avail.

Unsure how to further debug. Let me know if you can reproduce, would be good to know if it is something with NERSC environment that is causing this.

Install commands

ssh perlmutter
conda create -n test-trame-py312 python=3.12
conda activate test-trame-py312
pip install trame
pip install trame-vuetify trame-vtk
pip install vtk
pip install jupyterlab
pip install ipykernel

Expected behavior

To be able to run on a remote host through vscode's jupyter support.

Platform:

OS:

jourdain commented 8 months ago

The issue is related that on a remote setup not all the port might be open (as opposed to locally) so you need to either use trame-jupyter-extension or the server proxy of jupyter.

When the extension is available, it will be automatically detected and use the existing JupyterComm instead of its own WebSocket endpoint.

But if you are using JupyterHub and you have the server-proxy installed you can let trame know to use it instead of relying on its own direct server URL.

So the idea will be to do the following

app = Cone()
await app.ui.ready
app.ui.iframe_builder = "jupyter-hub" # Available options: serverproxy, jupyter-extension, jupyter-hub
app.ui

If that does not work, you have other controls to fine-tune the iframe URL, but that will depend on your setup and it might not be easy to explain what you should do without seeing the runtime environment.

swelborn commented 8 months ago

I am not having any luck using any of the available options in your list, and I cannot add a labextension to the shared jupyterhub at nersc.

When I do "jupyter-hub", I get a 404 that takes me back to our entrypoint to the hub if I click control panel: image

I can make recursive jupyterlab logins but that is not very helpful.

"serverproxy" yields nothing: image

This is the URL I am connected to when I log into jupyterhub, maybe this helps?

https://jupyter.nersc.gov/user/swelborn/perlmutter-login-node-base/lab/tree/global/homes/s/swelborn/gits/trame-test-py312/examples/jupyter/show.ipynb

I did get this to work on vscode remote by asking what the port was and adding it to my list of forwarded ports. I'm assuming you could pass in a trame_server.Server instance into the MyTrameApp constructor to set up preconfigured ports, etc.

image

jourdain commented 8 months ago

So it seems that jupyter-server-proxy is not available. Unless I know more about what's available and how trame can leverage the existing infrastructure, I won't be of much help.

swelborn commented 8 months ago

ok! i will ask someone who knows the answer and get back to you.

swelborn commented 8 months ago

We have jupyter server proxy installed/enabled, but we have named servers. Thus we have a prefix to make my server run at: https://jupyter.nersc.gov/user/swelborn/perlmutter-login-node-base

For our dask dashboard, we have to do something like this "{JUPYTERHUB_SERVICE_PREFIX}proxy/{host}:{port}/status"

Does this help?

jourdain commented 8 months ago

Yes it does, thank you. We'll try to get back to you with the proper way to configure trame so it can work at NERSC.

FYI @alesgenova

jourdain commented 8 months ago

Do you know how you can get {host}?

jourdain commented 8 months ago

You might be able to do something like

def nersc_iframe(layout):
    host = os.environ['HOSTNAME']
    server = layout.server
    template_name = layout._template_name
    src = f"{os.environ['JUPYTERHUB_SERVICE_PREFIX']}proxy/{host}:{server.port}/index.html?ui={template_name[16:]}&reconnect=auto"
    elem_id = f"{server.name}_{template_name}"

    return {
        "id": elem_id,
        "src": src,
        "style": layout.iframe_style,
        **layout.iframe_attrs,
    }
app.ui.iframe_builder = nersc_iframe
app.ui

You can find the current jupyter-hub implementation

jourdain commented 7 months ago

We finally got a chance to test it on NERSC and the issue was with our "jupyter-hub" implementation, we were generating 2 slash in a row. The latest version of "trame-client>=2.17.1" is now fixing it.

On top of that, it should automatically detect the jupyter-hub environment so you should not need to set the __iframe_builder__ at all.

And in case I've also added a jupyter-hub-host option.