Reinstate `pulse.Instruction.draw` (#9144)

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>
This commit is contained in:
Jake Lishman 2022-11-16 20:12:43 +00:00 committed by GitHub
parent a1cdb70847
commit da1a7e3093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -27,6 +27,7 @@ from typing import Callable, Iterable, List, Optional, Set, Tuple
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
@ -220,6 +221,7 @@ class Instruction(ABC):
"""Return True iff the instruction is parameterized."""
return any(self.parameters)
@_optionals.HAS_MATPLOTLIB.require_in_call
def draw(
self,
dt: float = 1,
@ -256,23 +258,29 @@ class Instruction(ABC):
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.

View File

@ -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.