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

Reinstate pulse.Instruction.draw #9144

Merged
merged 2 commits into from
Nov 16, 2022
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
20 changes: 14 additions & 6 deletions qiskit/pulse/instructions/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from qiskit.circuit import Parameter
from qiskit.pulse.channels import Channel
from qiskit.pulse.exceptions import PulseError
from qiskit.utils import optionals as _optionals


# pylint: disable=missing-return-doc
Expand Down Expand Up @@ -220,6 +221,7 @@ def is_parameterized(self) -> bool:
"""Return True iff the instruction is parameterized."""
return any(self.parameters)

@_optionals.HAS_MATPLOTLIB.require_in_call
def draw(
self,
dt: float = 1,
Expand Down Expand Up @@ -256,23 +258,29 @@ def draw(
matplotlib.figure: A matplotlib figure object of the pulse schedule
"""
# pylint: disable=cyclic-import
from qiskit import visualization
from qiskit.visualization.pulse.matplotlib import ScheduleDrawer
from qiskit.visualization.utils import matplotlib_close_if_inline

return visualization.pulse_drawer(
drawer = ScheduleDrawer(style=style)
image = drawer.draw(
self,
dt=dt,
style=style,
filename=filename,
interp_method=interp_method,
scale=scale,
plot_all=plot_all,
plot_range=plot_range,
interactive=interactive,
plot_all=plot_all,
table=table,
label=label,
framechange=framechange,
channels=channels,
)
if filename:
image.savefig(filename, dpi=drawer.style.dpi, bbox_inches="tight")

matplotlib_close_if_inline(image)
if image and interactive:
image.show()
return image

def __eq__(self, other: "Instruction") -> bool:
"""Check if this Instruction is equal to the `other` instruction.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
The :meth:`.pulse.Instruction.draw` will now succeed, as before.
This method is deprecated with no replacement planned, but it should
still work for the period of deprecation.