-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: Jupyter comms server #145
Conversation
Notebooks test code with a widget to collect the Tilesets. A collection of tilesets (should be weakrefable), that handles fulfilling requests from the front end. See |
Relevant PR that benefits from a similar kind of architecture (and ability to drop jupyter-server-proxy): |
5bb8393
to
4c8689b
Compare
@nvictus I added a notebook which should be a good starting point for trying this stuff out: uv run --with=clodius jupyter lab examples/JupyterServer.ipynb
# make sure to wget the test data |
@@ -0,0 +1,76 @@ | |||
// HiGlass's plugin system goes through globals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HiGlass doesn't provide any types. I've tried to type out the interfaces that we require so we can appropriately type-check the file and also help with autocomplete, etc.
/** | ||
* Transforms the original view config into tracks recognized by the custom data fetcher. | ||
* | ||
* Finds tracks with `server: 'jupyter'`, removes the key, and adds a `data` object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still true?
I don't see this in the example notebook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namely I don't see the track's server being set to Jupyter in https://github.com/higlass/higlass-python/blob/manzt/jupyter-comms/examples/JupyterServer.ipynb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The viewconf I see that's produced contains the following data section.
"data": {
"type": "IPY_MODEL_d3b1fccd786440b8a1b9b47bda3cd168",
"tilesetUid": "abf80f79ec3e9e899d168f869f624aaf"
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nvm. Ignore that internal monologue. The track does indeed have jupyter
as the server:
HeatmapTrack(tilesetUid='abf80f79ec3e9e899d168f869f624aaf', server='jupyter', type='heatmap', uid='8c8c58d9', width=None, height=None, options=None, data=None, position=None, transforms=None)
src/higlass/widget.js
Outdated
* @param {{ timeout?: number }} [options] | ||
* @returns {Promise<{ data: T, buffers: DataView[] }>} | ||
*/ | ||
function send(model, payload, { timeout = 3000 } = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully grok what this function does or why it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways to send data between JS and Python: traitlets & custom messages.
Custom messages are normally "fire and forget", so we need some kind of mechanism to fire and "await" a response back from Python. I've implemented an experimental API for this in anywidget, trying to make this pattern easier... but the implementation is pretty straigtht forward and included it here to avoid relying on an experimental API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I documented the function further to explain this behavior.
src/higlass/_widget.py
Outdated
|
||
# readonly properties | ||
location = t.List(t.Union([t.Float(), t.Tuple()]), read_only=True).tag(sync=True) | ||
|
||
def __init__(self, viewconf: dict, **viewer_options): | ||
super().__init__(_viewconf=viewconf, _options=viewer_options) | ||
def __init__(self, viewconf: dict, ts, **viewer_options): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the ts
param supposed to be here?
I get that it's the Tilesets
object from the example notebook but I'm having a bit of trouble wrapping my head around what it's meant to be conceptually.
examples/JupyterServer.ipynb
Outdated
" self.ts[ts.tileset.uid] = ts.tileset\n", | ||
" return self\n", | ||
"\n", | ||
" def _handle_custom_msg(self, data, buffers):\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is _handle_custom_msg
a standard DomWidget method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. We need to add a handler to receive messages from the frontend. It could be named anything. I extracted into a separate function that we now bind in the constructor.
cd897ab
to
4e3238e
Compare
This is in a good state now. I refactored the Python code out of the notebook into the codebase. The top-level tileset functions (e.g., A single The main open question is handling the old server implementation. I'd prefer to drop |
790080b
to
a409b60
Compare
* Remove servir and HiGlassServer * Replace custom display with widget * update uv.lock * update examples * Make singleton `JupyterTilesetClient` with typed messages
c30cf95
to
265a19c
Compare
Depends on:now merged