diff --git a/qiskit/pulse/channels.py b/qiskit/pulse/channels.py index 94adce9c53bc..c88fddadd77b 100644 --- a/qiskit/pulse/channels.py +++ b/qiskit/pulse/channels.py @@ -140,11 +140,6 @@ def name(self) -> str: """Return the shorthand alias for this channel, which is based on its type and index.""" return f"{self.__class__.prefix}{self._index}" - @property - def is_schedulable(self) -> bool: - """Return whether this channel can be independently scheduled""" - return True - def __repr__(self): return f"{self.__class__.__name__}({self._index})" @@ -170,6 +165,12 @@ class PulseChannel(Channel, metaclass=ABCMeta): pass +class ClassicalIOChannel(Channel, metaclass=ABCMeta): + """Base class of classical IO channels. These cannot have instructions scheduled on them.""" + + pass + + class DriveChannel(PulseChannel): """Drive channels transmit signals to qubits which enact gate operations.""" @@ -197,7 +198,7 @@ class AcquireChannel(Channel): prefix = "a" -class SnapshotChannel(Channel): +class SnapshotChannel(ClassicalIOChannel): """Snapshot channels are used to specify instructions for simulators.""" prefix = "s" @@ -207,25 +208,15 @@ def __init__(self): super().__init__(0) -class MemorySlot(Channel): +class MemorySlot(ClassicalIOChannel): """Memory slot channels represent classical memory storage.""" prefix = "m" - @property - def is_schedulable(self) -> bool: - """Return whether this channel can be independently scheduled""" - return False - -class RegisterSlot(Channel): +class RegisterSlot(ClassicalIOChannel): """Classical resister slot channels represent classical registers (low-latency classical memory). """ prefix = "c" - - @property - def is_schedulable(self) -> bool: - """Return whether this channel can be independently scheduled""" - return False diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index 9f663796bbc6..c68893a02d03 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -14,7 +14,7 @@ from typing import Optional, Union, Tuple from qiskit.circuit import ParameterExpression -from qiskit.pulse.channels import Channel +from qiskit.pulse.channels import Channel, ClassicalIOChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction @@ -51,11 +51,15 @@ def __init__( name: Name of the delay for display purposes. Raises: - PulseError: If `channel` cannot be delayed because it cannot be scheduled. + PulseError: If `channel` cannot be delayed because it is a classical IO channel. """ super().__init__(operands=(duration, channel), name=name) - if not channel.is_schedulable: - raise PulseError("Cannot delay chanel because it is not schedulable.") + if isinstance(channel, ClassicalIOChannel): + raise PulseError( + "Cannot delay channel {0} because it is a classical IO channel.".format( + channel.name + ) + ) @property def channel(self) -> Channel: diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index d09b69823332..9460af014394 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -16,6 +16,8 @@ from typing import Optional, Tuple from qiskit.pulse import channels as chans +from qiskit.pulse.channels import ClassicalIOChannel +from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions import instruction @@ -44,7 +46,17 @@ def __init__(self, *channels: chans.Channel, name: Optional[str] = None): Args: channels: The channel that the barrier applies to. name: Name of the directive for display purposes. + Raises: + PulseError: If one of the `channels` cannot be blocked because it is a classical IO channel. """ + for channel in channels: + if isinstance(channel, ClassicalIOChannel): + raise PulseError( + "Cannot block channel {0} because it is a classical IO channel.".format( + channel.name + ) + ) + super().__init__(operands=tuple(channels), name=name) @property diff --git a/qiskit/pulse/transforms/canonicalization.py b/qiskit/pulse/transforms/canonicalization.py index 12d8214962d5..4e2409ffa354 100644 --- a/qiskit/pulse/transforms/canonicalization.py +++ b/qiskit/pulse/transforms/canonicalization.py @@ -18,6 +18,7 @@ import numpy as np from qiskit.pulse import channels as chans, exceptions, instructions +from qiskit.pulse.channels import ClassicalIOChannel from qiskit.pulse.exceptions import PulseError from qiskit.pulse.exceptions import UnassignedDurationError from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap @@ -475,7 +476,7 @@ def pad( channels = channels or schedule.channels for channel in channels: - if not channel.is_schedulable: + if isinstance(channel, ClassicalIOChannel): continue if channel not in schedule.channels: schedule |= instructions.Delay(until, channel)