Opened 2 years ago

Closed 2 years ago

#27735 closed defect (fixed)

Support matrix input in @interact

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-8.8
Component: notebook Keywords: interact, grid widget, jupyter
Cc: slelievre, was, zerline Merged in:
Authors: Jeroen Demeyer Reviewers: Vincent Klein
Report Upstream: N/A Work issues:
Branch: 335f0a7 (Commits, GitHub, GitLab) Commit: 335f0a764f4c19cc75af112bf4388e09baac46d2
Dependencies: Stopgaps:

Status badges

Description (last modified by vklein)

This should create a grid widget in the Jupyter notebook (it already works this way in the Sage notebook):

@interact
def f(A = matrix([[1,1],[-1,1]])):
    print(A)
    print(type(A))

Change History (24)

comment:1 follow-up: Changed 2 years ago by kcrisman

I feel like this used to work, at least in sagenb ... interesting. It does work in Sage cell.


For anyone coming to this - see this sage-support discussion for an example of background.

comment:2 Changed 2 years ago by jdemeyer

  • Authors set to Jeroen Demeyer

comment:3 in reply to: ↑ 1 Changed 2 years ago by jdemeyer

  • Description modified (diff)

Replying to kcrisman:

I feel like this used to work, at least in sagenb ...

I should have mentioned: this is about Jupyter.

comment:4 Changed 2 years ago by jdemeyer

  • Branch set to u/jdemeyer/support_matrix_input_in__interact

comment:5 follow-up: Changed 2 years ago by kcrisman

  • Commit set to 50129c75b7ebe359d070dccd995cbd4a79a6ade2

This is why we really need to get the interact documentation OUT of (or copied elsewhere) the sagenb docs. Nobody even knows how t use interact any more. Do you think it might fit in one of the files you modified here?


New commits:

50129c7Support matrix in interact

comment:6 Changed 2 years ago by git

  • Commit changed from 50129c75b7ebe359d070dccd995cbd4a79a6ade2 to 335f0a764f4c19cc75af112bf4388e09baac46d2

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

335f0a7Support matrix in interact

comment:7 Changed 2 years ago by jdemeyer

  • Status changed from new to needs_review

comment:8 in reply to: ↑ 5 Changed 2 years ago by jdemeyer

See #27747 for docs.

comment:9 Changed 2 years ago by vklein

Currently using the widget may generate SyntaxError when you modifiy an input field. Let's say you have value 1 in one of your input fields and you want to input -23 instead, you get one syntax error when delelting 1 on a second when you type -.

  File "<string>", line 1
    -
    ^
SyntaxError: unexpected EOF while parsing

Maybe there is a way of filtering these cases or evaluating the input only after the focus leave the input field instead of evaluating after each modification/keystroke.

Last edited 2 years ago by vklein (previous) (diff)

comment:10 Changed 2 years ago by jdemeyer

Vincent, you may be right but that's certainly outside the scope of this ticket.

comment:11 Changed 2 years ago by vklein

I would not say "certainly" the ticket description say

This should work as expected ...

and one can expect not generating SyntaxError when modifying an input field value as it is the reason of using interact.

comment:12 follow-up: Changed 2 years ago by jdemeyer

But that's an issue with interacts in general, not specific with matrix.

comment:13 Changed 2 years ago by vklein

I wanted just to make sure that you are aware of that behaviour, and indeed this ticket fix a defect as it is.

comment:14 Changed 2 years ago by jdemeyer

  • Description modified (diff)

comment:15 in reply to: ↑ 12 ; follow-up: Changed 2 years ago by vklein

  • Description modified (diff)

Replying to jdemeyer:

But that's an issue with interacts in general, not specific with matrix.

Ok

comment:16 Changed 2 years ago by vklein

  • Description modified (diff)

comment:17 Changed 2 years ago by vklein

  • Reviewers set to Vincent Klein
  • Status changed from needs_review to positive_review

The python3 patchbot plugin says "from .widgets_sagenb import input_grid" is incompatible with python3 which isn't true.

Looks good to me.

comment:18 in reply to: ↑ 15 Changed 2 years ago by kcrisman

  • Status changed from positive_review to needs_info

But that's an issue with interacts in general, not specific with matrix.

Ok

On the Sage cell server, there is a "submit" button with matrices, which is why it isn't an issue. In sagenb there is no submit button, but this focus issue does not arise; until one presses enter, one can modify an input entry to heart's content. So I would indeed call this a bug.

The question is whether it is unique to this new matrix input functionality in Jupyter (in which case it should be fixed here), or whether all Jupyter input grids etc. suffer from this (in which case a new ticket is needed, and it's yet another place where sagenb still is better than Jupyter). What happens with input_grid currently in Jupyter?

comment:19 follow-up: Changed 2 years ago by jdemeyer

  • Status changed from needs_info to positive_review

Please open a new ticket for that.

comment:20 in reply to: ↑ 19 Changed 2 years ago by kcrisman

Please open a new ticket for that.

Since I haven't observed it, I don't know if it is limited to input_grid or not, and I don't have time to fire up a Jupyter right now and do testing. @vklein, since you originally observed this, can you test what does/doesn't work in Jupyter and open a new ticket? Thank you!

comment:21 Changed 2 years ago by jdemeyer

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.

comment:22 Changed 2 years ago by kcrisman

On Jupyter only, then? See #27752.

comment:23 Changed 2 years ago by slelievre

  • Cc slelievre zerline added
  • Keywords interact grid widget jupyter added

comment:24 Changed 2 years ago by vbraun

  • Branch changed from u/jdemeyer/support_matrix_input_in__interact to 335f0a764f4c19cc75af112bf4388e09baac46d2
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.