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

Define multiple output methods for lab_dev #509

Open
1 task done
aplund opened this issue Oct 17, 2024 · 3 comments
Open
1 task done

Define multiple output methods for lab_dev #509

aplund opened this issue Oct 17, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@aplund
Copy link
Contributor

aplund commented Oct 17, 2024

Before posting a feature request

  • I have searched exisisting GitHub issues to make sure the feature request does not already exist.

Feature details

Currently in ipython, lab_dev objects do not display any useful information in the output. I need to manually call repr to see something useful.

Python 3.11.9 (main, Jul 24 2024, 15:03:44) [GCC 14.1.1 20240522]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.28.0 -- An enhanced Interactive Python. Type '?' for help.

[ins] In [1]: %load playground/display.py

[ins] In [2]: # %load playground/display.py
         ...: import mrmustard as mm
         ...: import mrmustard.lab_dev
         ...:
         ...: c = mm.lab_dev.Coherent([0], 1)
         ...:

[ins] In [3]: c
Out[3]: HBox(children=(VBox(children=(HTML(value='\n<style>\ntd {\n  border: 1px solid;\n}\nth {\n  border: 1px solid;…

Implementation

It would appear that this occurs because there is the _ipython_display_ method defined on the objects. This is described in the ipython code as an "escape-hatch" formatter. After IPython 6.1 the _repr_*_ methods are described as the way to get formatted representations of objects. Perhaps this is the way to do this.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

@aplund aplund added the enhancement New feature or request label Oct 17, 2024
@timmysilv
Copy link
Collaborator

To add a bit of context here: I chose to use _ipython_display_ because _repr_*_ requires that you return the required data (eg. raw javascript/html) as opposed to using your own side effect (eg. IPython.display like we use) as described in the ipython docs. I remember that plotly was having trouble when I tried using _repr_html_ and returning the HTML from the widget, likely because it needed some javascript stuff that wasn't installed/supported. I didn't dig too deep, so it might be doable, but Plotly definitely added pain.

@aplund
Copy link
Contributor Author

aplund commented Oct 18, 2024

Hmm... this would seem to be more complex than it seems due to the way plotly works. Does plotly give equally weird results when used interactively in the terminal interface?

@timmysilv
Copy link
Collaborator

i can't use much from the terminal because i do all my work on a remote machine so i'm not sure. but probably

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants