Skip to content

Commit

Permalink
Fixes Qiskit#7078: Put checks in SetPhase, ShiftPhase and SetPhase. R…
Browse files Browse the repository at this point in the history
…emove check from Delay.
  • Loading branch information
pollyshaw committed Jul 19, 2022
1 parent a217879 commit cfd81c7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
9 changes: 1 addition & 8 deletions qiskit/pulse/instructions/delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from typing import Optional, Union, Tuple

from qiskit.circuit import ParameterExpression
from qiskit.pulse.channels import Channel, ClassicalIOChannel
from qiskit.pulse.exceptions import PulseError
from qiskit.pulse.channels import Channel
from qiskit.pulse.instructions.instruction import Instruction


Expand Down Expand Up @@ -54,12 +53,6 @@ def __init__(
PulseError: If `channel` cannot be delayed because it is a classical IO channel.
"""
super().__init__(operands=(duration, channel), name=name)
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:
Expand Down
12 changes: 0 additions & 12 deletions qiskit/pulse/instructions/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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


Expand Down Expand Up @@ -46,17 +44,7 @@ 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
Expand Down
8 changes: 7 additions & 1 deletion qiskit/pulse/instructions/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Optional, Union, Tuple

from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.pulse.channels import PulseChannel
from qiskit.pulse.channels import PulseChannel, PulseError
from qiskit.pulse.instructions.instruction import Instruction


Expand Down Expand Up @@ -46,7 +46,13 @@ def __init__(
frequency: New frequency of the channel in Hz.
channel: The channel this instruction operates on.
name: Name of this set channel frequency instruction.
Raises:
PulseError: If channel is not a PulseChannel.
"""
if not isinstance(channel, PulseChannel):
raise PulseError(
"The `channel` argument to `SetFrequency` must be of type `channels.PulseChannel`."
)
if not isinstance(frequency, ParameterExpression):
frequency = float(frequency)
super().__init__(operands=(frequency, channel), name=name)
Expand Down
15 changes: 14 additions & 1 deletion qiskit/pulse/instructions/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Optional, Union, Tuple

from qiskit.circuit import ParameterExpression
from qiskit.pulse.channels import PulseChannel
from qiskit.pulse.channels import PulseChannel, PulseError
from qiskit.pulse.instructions.instruction import Instruction


Expand Down Expand Up @@ -52,7 +52,14 @@ def __init__(
phase: The rotation angle in radians.
channel: The channel this instruction operates on.
name: Display name for this instruction.
Raises:
PulseError: If channel is not a PulseChannel.
"""
if not isinstance(channel, PulseChannel):
raise PulseError(
"The `channel` argument to `ShiftPhase` must be of type `channels.PulseChannel`."
)
super().__init__(operands=(phase, channel), name=name)

@property
Expand Down Expand Up @@ -108,7 +115,13 @@ def __init__(
phase: The rotation angle in radians.
channel: The channel this instruction operates on.
name: Display name for this instruction.
Raises:
PulseError: If channel is not a PulseChannel.
"""
if not isinstance(channel, PulseChannel):
raise PulseError(
"The `channel` argument to `SetPhase` must be of type `channels.PulseChannel`."
)
super().__init__(operands=(phase, channel), name=name)

@property
Expand Down
2 changes: 1 addition & 1 deletion qiskit/pulse/instructions/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, pulse: Pulse, channel: PulseChannel, name: Optional[str] = No
name: Name of the instruction for display purposes. Defaults to ``pulse.name``.
Raises:
PulseError: If pulse is not a Pulse type.
PulseError: If pulse is not a Pulse type, or channel is not a PulseChannel.
"""
if not isinstance(pulse, Pulse):
raise PulseError("The `pulse` argument to `Play` must be of type `library.Pulse`.")
Expand Down

0 comments on commit cfd81c7

Please sign in to comment.