Skip to content

Commit

Permalink
Reinstate pulse.Instruction.draw (#9144)
Browse files Browse the repository at this point in the history
This was erroneously broken by gh-8306 and not detected by lint because
of the existence of `qiskit.visualization.__getattr__`.  This reinstates
the functionality using the deprecated old instruction drawers.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jakelishman and mergify[bot] authored Nov 16, 2022
1 parent a1cdb70 commit da1a7e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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.

0 comments on commit da1a7e3

Please sign in to comment.