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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/howtos/cloud_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ experiment <https://quantum.ibm.com/experiments/9640736e-d797-4321-b063-d503f8e9
service = ExperimentData.get_service_from_backend(backend)
load_expdata = ExperimentData.load("9640736e-d797-4321-b063-d503f8e98571", service)

To display the figure, which is serialized into a string, we need the
``SVG`` library:
Now we can display the figure from the loaded experiment data:

.. jupyter-input::

from IPython.display import SVG
SVG(load_expdata.figure(0).figure)
load_expdata.figure(0)

.. image:: ./experiment_cloud_service/t1_loaded.png

Expand Down
3 changes: 2 additions & 1 deletion qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
ExperimentDataSaveFailed,
)


if TYPE_CHECKING:
# There is a cyclical dependency here, but the name needs to exist for
# Sphinx on Python 3.9+ to link type hints correctly. The gating on
Expand Down Expand Up @@ -192,7 +193,7 @@ def _repr_svg_(self):
if isinstance(self.figure, str):
return self.figure
if isinstance(self.figure, bytes):
return str(self.figure)
return self.figure.decode("utf-8")
return None


Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/figure_return_SVG-4ad72fc8a3bee3cb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Figures loaded from the experiment service are now rendered correctly in Jupyter Notebook.