Skip to content
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

Re-evaluate Bokeh in documentation Jupyter notebooks and compare with Plotly #3054

Open
matz-e opened this issue Aug 22, 2024 · 3 comments
Open

Comments

@matz-e
Copy link
Collaborator

matz-e commented Aug 22, 2024

@kbvw noticed that bokeh<3 is present in the documentation build and that newer versions of Bokeh serialize Neuron objects differently (i.e. fail to do so).

We should see how much work would be involved to switch to plotly, and sort-of ensure that serialization works.

@matz-e matz-e changed the title Replace Bokeh with Plotly Replace Bokeh with Plotly in documentation Jupyter notebooks Aug 22, 2024
@kbvw kbvw changed the title Replace Bokeh with Plotly in documentation Jupyter notebooks Re-evaluate Bokeh in documentation Jupyter notebooks and compare with Plotly Aug 29, 2024
@kbvw
Copy link
Contributor

kbvw commented Aug 29, 2024

In Bokeh 3, the serialization to JSON has been reworked: if you want to plot your own container types (such as our hoc.Vector) directly, you need to explicitly add code to serialize them. The documentation on this is not extensive, but from the source, it appears that there are two APIs for this: a Serializable mixin class to explicitly subclass along with a to_serializable method to implement, or a register class method on the Serializer class to add your own encoder function.

We currently only call Bokeh from the notebooks in the documentation, but we advertise there to use it for interactive plotting in the Neuron python workflow. It is currently pinned to bokeh<3, in the main and documentation requirements, as it breaks the notebooks otherwise. This pin is also keeping the numpy<2 pin in place, currently only remaining in the documentation requirements.

I got the feedback that interactive plotting is crucial to demonstrate in the notebooks, be it with Bokeh or with Plotly. That gives the following options:

  1. Maintain code with our hoc.Vector to allow Bokeh serialization.
  2. Tell users (with the notebooks) to register a simple serialization function when importing Bokeh.
  3. Tell users (with the notebooks) to convert hoc.Vectors to lists or np.arrays before plotting.
  4. Consider switching to, for example, Plotly for interactive plotting.

I added option 2 in #3061, which removes the pin, and also the remaining Numpy pin. I'd say we can merge that for now, and come back to this if it turns out that registering a serialization function trips up the user too much.

@ramcdougal
Copy link
Member

This isn't just a notebook issue.

We give Bokeh code in the example for RangeVarPlot.plot and who knows where else.

The following ought to just work:

import bokeh.plotting as b
bg = b.Figure()
r.plot(bg, line_width=10)
b.show(bg)

So instead of modifying the notebook to tell people to do extra things, is there any reason not to just have __init__.py add the serialization code inside a try/catch block (in case bokeh isn't installed) so that everything continues to just work as in older versions of bokeh?

@kbvw
Copy link
Contributor

kbvw commented Aug 29, 2024

I thought about that, and I think that should work and indeed be cleaner, unless the user ends up reloading Bokeh somehow afterwards (or who knows how it gets reloaded), which would lead to a puzzling error.

Not realizing what you said about RangeVarPlot.plot, I thought it would be better to be explicit. But I guess we can import Bokeh upon importing Neuron in case it's installed (and register the function): I suppose it is unlikely to get reloaded after.

EDIT: Changed "implicit" to "explicit"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants