sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.4k stars 474 forks source link

Jupyter textual interact input does not wait to be evaluated #27752

Open kcrisman opened 5 years ago

kcrisman commented 5 years ago

In #27735 it was discovered that, unlike sagenb or Sage cell, text input in @interacts in Jupyter apparently immediately re-evaluate even before 'enter' is pressed. jdemeyer explains:

It's a general "problem" (arguable, since one could call it a feature) with all interacts that have some kind of textual input which is evaluated.

However, because this is different from the behavior of other interact implementations (does anyone know about .sagews CoCalc sheets?), probably this should be fixed. Among other things, if the interact involves significant computation time (> 1 ms, especially a problem with anything involving graphics), it can slow down usage of interacts dramatically, which sort of defeats the purpose of @interacts.

CC: @jdemeyer @slel @vinklein @zerline

Component: notebook

Keywords: jupyter

Issue created by migration from https://trac.sagemath.org/ticket/27752

kcrisman commented 5 years ago

Description changed:

jdemeyer commented 5 years ago

I should note that the implementation of @interact itself is really done by upstream. Three packages (all under the Jupyter umbrella) play an important role:

  1. ipywidgets: Python package dealing with widgets and where the actual interact object is defined.
  2. widgetsnbextension: JavaScript code for working with widgets in the browser.
  3. traitlets: low-level Python library dealing with the callback mechanism (changing the value of a widget triggers evaluation of the interact function).

There are Sage customizations to the standard @interact (see src/sage/repl/ipython_kernel/interact.py), but those do not fundamentally change the way how interacts work.

So either we need to fix something upstream, or we add a workaround in Sage, or we become happy with the status-quo.

kcrisman commented 5 years ago
comment:3
  1. ipywidgets: Python package dealing with widgets and where the actual interact object is defined.
  2. widgetsnbextension: JavaScript code for working with widgets in the browser.
  3. traitlets: low-level Python library dealing with the callback mechanism (changing the value of a widget triggers evaluation of the interact function).

Which of these is the one that is most likely to be causing the immediate change with regard to the text boxes? I think the real problem is that different implementations work differently, and it surprises me that there is such immediate response in Jupyter - you'd think it would be "easier" not to poll the Sage kernel with more computation so often, but of course I don't know much about the specific technicalities.

jdemeyer commented 5 years ago
comment:4

Replying to @kcrisman:

Which of these is the one that is most likely to be causing the immediate change with regard to the text boxes?

It's really a combination, that's why I mentioned the various packages: whenever the user types something in a text box, widgetsnbextension sends an event to the Jupyter kernel. ipywidgets then changes the .value attribute of the text box. traitlets notices that this attribute has changed and calls a callback function for the interact (implemented by ipywidgets). This callback then updates the interact.

slel commented 5 years ago

Changed keywords from none to jupyter

embray commented 5 years ago
comment:6

Moving open critical and blocker issues to the next release milestone (optimistically).

embray commented 4 years ago
comment:7

Ticket retargeted after milestone closed

mkoeppe commented 3 years ago
comment:10

Moving to 9.4, as 9.3 has been released.