-
Notifications
You must be signed in to change notification settings - Fork 27
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
Comments
To add a bit of context here: I chose to use |
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? |
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 |
**Context:** Objects with rich ipython displays do not render properly in interactive IPython **Description of the Change:** - Default to the plain repr in interactive IPython - sneak in a workflow fix to avoid code injection via branch name. check the ultralytics issue shared in #software-learning if you're curious **Benefits:** - No more funny HTML-like output for objects in interactive IPython **Possible Drawbacks:** - Perhaps there's a way to show graphics nicely within IPython? this should suffice, and you can open a notebook if you want plotly **Related GitHub Issues:** Fixes #509 ___ Enhancement, Tests ___ - Enhanced `_ipython_display_` methods across multiple modules to check for interactive IPython shell and default to `print(self)` for better display. - Added tests to verify the new behavior of `_ipython_display_` methods in interactive IPython environments. - Updated changelog to reflect the changes made for IPython display enhancements. - Modified GitHub workflows to use environment variables for S3 path handling. ___ <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>6 files</summary><table> <tr> <td> <details> <summary><strong>circuit_components.py</strong><dd><code>Improve IPython display handling for circuit components</code> </dd></summary> <hr> mrmustard/lab_dev/circuit_components.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-05cc8f1f470b3eab23b8a8b1b1a628a97c87852722ea6b5408e1bb70efd4ab72">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>dm.py</strong><dd><code>Enhance IPython display for density matrix class</code> </dd></summary> <hr> mrmustard/lab_dev/states/dm.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-17d0cf9d48cb14fcbaadec367030d4f41d5c782c2a069d5d9342569588e2ba38">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>ket.py</strong><dd><code>Improve IPython display handling for ket class</code> </dd></summary> <hr> mrmustard/lab_dev/states/ket.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-065ae49c98ca8757bb66ef7763a81070e7b0eab2e0899ffebc2b4f2491d6df4e">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>array_ansatz.py</strong><dd><code>Enhance IPython display for array ansatz</code> </dd></summary> <hr> mrmustard/physics/ansatz/array_ansatz.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-0ee29c8e80f195e801b8151282f2373ac1d6e3596bfe63d94391e642b6cb3365">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>polyexp_ansatz.py</strong><dd><code>Improve IPython display handling for polyexp ansatz</code> </dd></summary> <hr> mrmustard/physics/ansatz/polyexp_ansatz.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-7c01e9c60d2d4a82b42f83c1e79989674c8a3a4a215091a23cfbfb7b4feca1c9">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>wires.py</strong><dd><code>Enhance IPython display for wires class</code> </dd></summary> <hr> mrmustard/physics/wires.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-d2f4eccc13a81234643db11e5fd75e4eaabda4485c3276cdd67e94d5dd8109ea">+4/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>4 files</summary><table> <tr> <td> <details> <summary><strong>test_circuit_components.py</strong><dd><code>Add tests for interactive IPython display in circuit components</code></dd></summary> <hr> tests/test_lab_dev/test_circuit_components.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-cf594d34002781ecbd6f00d55be035f5d6821af5cfde94038830e0e3ea5f5bc3">+10/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>test_array_ansatz.py</strong><dd><code>Add tests for interactive IPython display in array ansatz</code></dd></summary> <hr> tests/test_physics/test_ansatz/test_array_ansatz.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-d926ceee5a48b97d221e5d1498e5f0537206cdb274ea677293c3f9317adc1563">+10/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>test_polyexp_ansatz.py</strong><dd><code>Add tests for interactive IPython display in polyexp ansatz</code></dd></summary> <hr> tests/test_physics/test_ansatz/test_polyexp_ansatz.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-921ac6091261c146640c3b3df644134e8872df68078997207977cb7f4231f158">+10/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>test_wires.py</strong><dd><code>Add tests for interactive IPython display in wires class</code> </dd></summary> <hr> tests/test_physics/test_wires.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-0cb3b43d3b87f32a5224ac21fcc523336e77bf7ebc8d76fba4663846c3ac8175">+14/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Documentation</strong></td><td><details><summary>1 files</summary><table> <tr> <td> <details> <summary><strong>CHANGELOG.md</strong><dd><code>Update changelog for IPython display enhancements</code> </dd></summary> <hr> .github/CHANGELOG.md <li>Updated changelog to include changes for interactive IPython display.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-2a22f598a15a364508bc9a475e6ec9df31958a753e9401fabaac8df4db5bd853">+3/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>2 files</summary><table> <tr> <td> <details> <summary><strong>tests_numpy.yml</strong><dd><code>Update S3 path handling in numpy tests workflow</code> </dd></summary> <hr> .github/workflows/tests_numpy.yml - Added environment variable for reference name in S3 path. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-d01653471e6afa1d9bb01bcfdc93e6cb34fc4d45c6143faa64089be7bd816943">+3/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>tests_tensorflow.yml</strong><dd><code>Update S3 path handling in tensorflow tests workflow</code> </dd></summary> <hr> .github/workflows/tests_tensorflow.yml - Added environment variable for reference name in S3 path. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-5c93d09eab7d2e9e949ef7ad1fc187e89c23f1837f29f822cd5676aaf1e45fc8">+3/-1</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information
### **User description** **Context:** Objects with rich ipython displays do not render properly in interactive IPython **Description of the Change:** - Default to the plain repr in interactive IPython - sneak in a workflow fix to avoid code injection via branch name. check the ultralytics issue shared in #software-learning if you're curious **Benefits:** - No more funny HTML-like output for objects in interactive IPython **Possible Drawbacks:** - Perhaps there's a way to show graphics nicely within IPython? this should suffice, and you can open a notebook if you want plotly **Related GitHub Issues:** Fixes #509 ___ ### **PR Type** Enhancement, Tests ___ ### **Description** - Enhanced `_ipython_display_` methods across multiple modules to check for interactive IPython shell and default to `print(self)` for better display. - Added tests to verify the new behavior of `_ipython_display_` methods in interactive IPython environments. - Updated changelog to reflect the changes made for IPython display enhancements. - Modified GitHub workflows to use environment variables for S3 path handling. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>6 files</summary><table> <tr> <td> <details> <summary><strong>circuit_components.py</strong><dd><code>Improve IPython display handling for circuit components</code> </dd></summary> <hr> mrmustard/lab_dev/circuit_components.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-05cc8f1f470b3eab23b8a8b1b1a628a97c87852722ea6b5408e1bb70efd4ab72">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>dm.py</strong><dd><code>Enhance IPython display for density matrix class</code> </dd></summary> <hr> mrmustard/lab_dev/states/dm.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-17d0cf9d48cb14fcbaadec367030d4f41d5c782c2a069d5d9342569588e2ba38">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>ket.py</strong><dd><code>Improve IPython display handling for ket class</code> </dd></summary> <hr> mrmustard/lab_dev/states/ket.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-065ae49c98ca8757bb66ef7763a81070e7b0eab2e0899ffebc2b4f2491d6df4e">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>array_ansatz.py</strong><dd><code>Enhance IPython display for array ansatz</code> </dd></summary> <hr> mrmustard/physics/ansatz/array_ansatz.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-0ee29c8e80f195e801b8151282f2373ac1d6e3596bfe63d94391e642b6cb3365">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>polyexp_ansatz.py</strong><dd><code>Improve IPython display handling for polyexp ansatz</code> </dd></summary> <hr> mrmustard/physics/ansatz/polyexp_ansatz.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-7c01e9c60d2d4a82b42f83c1e79989674c8a3a4a215091a23cfbfb7b4feca1c9">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>wires.py</strong><dd><code>Enhance IPython display for wires class</code> </dd></summary> <hr> mrmustard/physics/wires.py <li>Added check for interactive IPython shell in <code>_ipython_display_</code> method.<br> <li> Default to <code>print(self)</code> for interactive shell.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-d2f4eccc13a81234643db11e5fd75e4eaabda4485c3276cdd67e94d5dd8109ea">+4/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>4 files</summary><table> <tr> <td> <details> <summary><strong>test_circuit_components.py</strong><dd><code>Add tests for interactive IPython display in circuit components</code></dd></summary> <hr> tests/test_lab_dev/test_circuit_components.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-cf594d34002781ecbd6f00d55be035f5d6821af5cfde94038830e0e3ea5f5bc3">+10/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>test_array_ansatz.py</strong><dd><code>Add tests for interactive IPython display in array ansatz</code></dd></summary> <hr> tests/test_physics/test_ansatz/test_array_ansatz.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-d926ceee5a48b97d221e5d1498e5f0537206cdb274ea677293c3f9317adc1563">+10/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>test_polyexp_ansatz.py</strong><dd><code>Add tests for interactive IPython display in polyexp ansatz</code></dd></summary> <hr> tests/test_physics/test_ansatz/test_polyexp_ansatz.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-921ac6091261c146640c3b3df644134e8872df68078997207977cb7f4231f158">+10/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>test_wires.py</strong><dd><code>Add tests for interactive IPython display in wires class</code> </dd></summary> <hr> tests/test_physics/test_wires.py - Added test for interactive IPython shell display. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-0cb3b43d3b87f32a5224ac21fcc523336e77bf7ebc8d76fba4663846c3ac8175">+14/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Documentation</strong></td><td><details><summary>1 files</summary><table> <tr> <td> <details> <summary><strong>CHANGELOG.md</strong><dd><code>Update changelog for IPython display enhancements</code> </dd></summary> <hr> .github/CHANGELOG.md <li>Updated changelog to include changes for interactive IPython display.<br> </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-2a22f598a15a364508bc9a475e6ec9df31958a753e9401fabaac8df4db5bd853">+3/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>2 files</summary><table> <tr> <td> <details> <summary><strong>tests_numpy.yml</strong><dd><code>Update S3 path handling in numpy tests workflow</code> </dd></summary> <hr> .github/workflows/tests_numpy.yml - Added environment variable for reference name in S3 path. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-d01653471e6afa1d9bb01bcfdc93e6cb34fc4d45c6143faa64089be7bd816943">+3/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>tests_tensorflow.yml</strong><dd><code>Update S3 path handling in tensorflow tests workflow</code> </dd></summary> <hr> .github/workflows/tests_tensorflow.yml - Added environment variable for reference name in S3 path. </details> </td> <td><a href="https://github.com/XanaduAI/MrMustard/pull/531/files#diff-5c93d09eab7d2e9e949ef7ad1fc187e89c23f1837f29f822cd5676aaf1e45fc8">+3/-1</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information
Before posting a feature request
Feature details
Currently in
ipython
, lab_dev objects do not display any useful information in the output. I need to manually callrepr
to see something useful.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
The text was updated successfully, but these errors were encountered: