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

Make figures loaded from experiment db viewable in notebook #1321

Merged
merged 13 commits into from
Dec 21, 2023

Conversation

ItamarGoldman
Copy link
Contributor

@ItamarGoldman ItamarGoldman commented Nov 16, 2023

Summary

Make figures loaded from experiment db viewable in jupyter notebook as suggested in #436 .

Details and comments

Some details that should be in this section include:

  • Why this change was necessary
    To make it more comfortable to use figures in jupyter notebook.
  • What do users and developers need to know about this change
    To display figures of experiment data that were loaded from experiment db don't need to convert to SVG.

@ItamarGoldman ItamarGoldman changed the title [WIP] Make figures loaded from experiment db viewable in notebook Make figures loaded from experiment db viewable in notebook Nov 23, 2023
@wshanks
Copy link
Collaborator

wshanks commented Nov 27, 2023

Figures were already made viewable in the notebook by #814 which made .figure() return a FigureData object with special repr methods for Jupyter. I am not sure there is a benefit to modifying the figure attribute like this.

@ItamarGoldman
Copy link
Contributor Author

Figures were already made viewable in the notebook by #814 which made .figure() return a FigureData object with special repr methods for Jupyter. I am not sure there is a benefit to modifying the figure attribute like this.

I thought that we would like the same behavior for loaded experiment and executed one on Jupyter Notebook.

From what I can see the .figure() method is working as you says, but its output isn't ideal (but maybe its only in my environment) :
figure format

while with SVG converter it looks better:
SVG format

@wshanks
Copy link
Collaborator

wshanks commented Nov 28, 2023

Oh, you're right. I was testing the initial figure, not the one loaded from the db. For me, loading from the db actually gives no image. For the problem is that in _repr_svg_ here: https://github.com/Qiskit-Extensions/qiskit-experiments/blob/2cc444ac33783ce896662e39cd731b4874f9a0ae/qiskit_experiments/framework/experiment_data.py#L191-L196
self.figure is bytes but then str(self.figure) is just a string starting with b with the Python string representation of the bytes content, not the bytes content decoded as a string. For me, changing str(self.figure) to self.figure.decode("utf-8") resolves the problem. Can you check if that works for you as well? It would be better to fix the repr method than to make the return type variable based on the environment.

@ItamarGoldman
Copy link
Contributor Author

Oh, you're right. I was testing the initial figure, not the one loaded from the db. For me, loading from the db actually gives no image. For the problem is that in _repr_svg_ here:

https://github.com/Qiskit-Extensions/qiskit-experiments/blob/2cc444ac33783ce896662e39cd731b4874f9a0ae/qiskit_experiments/framework/experiment_data.py#L191-L196

self.figure is bytes but then str(self.figure) is just a string starting with b with the Python string representation of the bytes content, not the bytes content decoded as a string. For me, changing str(self.figure) to self.figure.decode("utf-8") resolves the problem. Can you check if that works for you as well? It would be better to fix the repr method than to make the return type variable based on the environment.

I updated as you suggested and it works 😄 ready for review

Copy link
Collaborator

@wshanks wshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work getting this fixed @ItamarGoldman!

I am approving now, but I left two small suggestions to address before merging.

docs/howtos/cloud_service.rst Outdated Show resolved Hide resolved
releasenotes/notes/figure_return_SVG-4ad72fc8a3bee3cb.yaml Outdated Show resolved Hide resolved
@wshanks wshanks added this to the Release 0.6 milestone Dec 20, 2023
@ItamarGoldman ItamarGoldman added this pull request to the merge queue Dec 21, 2023
Merged via the queue into qiskit-community:main with commit 726f422 Dec 21, 2023
11 checks passed
@ItamarGoldman ItamarGoldman deleted the IS-436 branch December 21, 2023 08:02
nkanazawa1989 pushed a commit to nkanazawa1989/qiskit-experiments that referenced this pull request Jan 17, 2024
…ommunity#1321)

### Summary

Make figures loaded from experiment db viewable in jupyter notebook as
suggested in qiskit-community#436 .
### Details and comments

Some details that should be in this section include:

- Why this change was necessary
  To  make it more comfortable to use figures in jupyter notebook.
- What do users and developers need to know about this change
To display figures of experiment data that were loaded from experiment
db don't need to convert to SVG.

---------

Co-authored-by: Will Shanks <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants