From 8fb185b3af8fae6ce96170c4586875e663947f17 Mon Sep 17 00:00:00 2001 From: TsafrirA <113579969+TsafrirA@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:45:23 +0200 Subject: [PATCH] Update pulse instruction interface to the new pulse model (#11726) * Update instruction interface * Some more test updates * Qubit ref fix * Hopefully avoid circular references. * Corrections after review * Change FrameInstruction to FrameUpdate * update to reflect qiskit.test removal * Test update --- qiskit/assembler/assemble_schedules.py | 4 +- qiskit/pulse/builder.py | 16 +- qiskit/pulse/instructions/acquire.py | 66 ++- qiskit/pulse/instructions/delay.py | 51 +- qiskit/pulse/instructions/directives.py | 24 +- qiskit/pulse/instructions/frequency.py | 145 +++--- qiskit/pulse/instructions/instruction.py | 88 +++- qiskit/pulse/instructions/phase.py | 140 +++-- qiskit/pulse/instructions/play.py | 72 ++- qiskit/pulse/instructions/reference.py | 17 +- qiskit/pulse/instructions/snapshot.py | 14 +- qiskit/pulse/macros.py | 4 +- qiskit/pulse/model/mixed_frames.py | 14 +- qiskit/pulse/transforms/canonicalization.py | 10 +- qiskit/qobj/converters/pulse_instruction.py | 16 +- qiskit/visualization/pulse_v2/core.py | 2 +- .../python/circuit/test_circuit_operations.py | 2 +- test/python/circuit/test_parameters.py | 8 +- test/python/compiler/test_assembler.py | 128 +++-- test/python/compiler/test_disassembler.py | 6 +- test/python/primitives/test_primitive.py | 4 +- test/python/pulse/test_block.py | 340 ++++++------ test/python/pulse/test_builder.py | 134 ++--- test/python/pulse/test_builder_v2.py | 46 +- test/python/pulse/test_calibration_entries.py | 41 +- test/python/pulse/test_frames.py | 2 +- .../pulse/test_instruction_schedule_map.py | 70 +-- test/python/pulse/test_instructions.py | 489 ++++++++++++++++-- test/python/pulse/test_macros.py | 18 +- test/python/pulse/test_mixed_frames.py | 12 +- test/python/pulse/test_parameter_manager.py | 94 ++-- test/python/pulse/test_pulse_targets.py | 2 +- test/python/pulse/test_schedule.py | 329 ++++++------ test/python/pulse/test_transforms.py | 488 ++++++++++------- test/python/qobj/test_pulse_converter.py | 56 +- test/python/qpy/test_block_load_from_qpy.py | 4 +- test/python/scheduler/test_basic_scheduler.py | 86 +-- .../test_instruction_alignments.py | 10 +- .../transpiler/test_calibrationbuilder.py | 14 +- .../transpiler/test_instruction_alignments.py | 10 +- .../test_scheduling_padding_pass.py | 2 +- .../visualization/pulse_v2/test_core.py | 12 +- .../visualization/pulse_v2/test_events.py | 48 +- .../visualization/pulse_v2/test_generators.py | 40 +- .../visualization/pulse_v2/test_layouts.py | 2 +- 45 files changed, 1976 insertions(+), 1204 deletions(-) diff --git a/qiskit/assembler/assemble_schedules.py b/qiskit/assembler/assemble_schedules.py index c60c28ff9a5..b71d093e2de 100644 --- a/qiskit/assembler/assemble_schedules.py +++ b/qiskit/assembler/assemble_schedules.py @@ -236,7 +236,9 @@ def _assemble_instructions( if not is_backend_supported: instruction = instructions.Play( - instruction.pulse.get_waveform(), instruction.channel, name=instruction.name + instruction.pulse.get_waveform(), + channel=instruction.channel, + name=instruction.name, ) if isinstance(instruction.pulse, library.Waveform): diff --git a/qiskit/pulse/builder.py b/qiskit/pulse/builder.py index 6d57c2e3cc7..41986c4bc08 100644 --- a/qiskit/pulse/builder.py +++ b/qiskit/pulse/builder.py @@ -1498,7 +1498,7 @@ def delay(duration: int, channel: chans.Channel, name: str | None = None): channel: Channel to delay on. name: Name of the instruction. """ - append_instruction(instructions.Delay(duration, channel, name=name)) + append_instruction(instructions.Delay(duration, channel=channel, name=name)) def play(pulse: library.Pulse | np.ndarray, channel: chans.PulseChannel, name: str | None = None): @@ -1523,7 +1523,7 @@ def play(pulse: library.Pulse | np.ndarray, channel: chans.PulseChannel, name: s if not isinstance(pulse, library.Pulse): pulse = library.Waveform(pulse) - append_instruction(instructions.Play(pulse, channel, name=name)) + append_instruction(instructions.Play(pulse, channel=channel, name=name)) class _MetaDataType(TypedDict, total=False): @@ -1577,11 +1577,11 @@ def acquire( if isinstance(register, chans.MemorySlot): append_instruction( - instructions.Acquire(duration, qubit_or_channel, mem_slot=register, **metadata) + instructions.Acquire(duration, channel=qubit_or_channel, mem_slot=register, **metadata) ) elif isinstance(register, chans.RegisterSlot): append_instruction( - instructions.Acquire(duration, qubit_or_channel, reg_slot=register, **metadata) + instructions.Acquire(duration, channel=qubit_or_channel, reg_slot=register, **metadata) ) else: raise exceptions.PulseError(f'Register of type: "{type(register)}" is not supported') @@ -1606,7 +1606,7 @@ def set_frequency(frequency: float, channel: chans.PulseChannel, name: str | Non channel: Channel to set frequency of. name: Name of the instruction. """ - append_instruction(instructions.SetFrequency(frequency, channel, name=name)) + append_instruction(instructions.SetFrequency(frequency, channel=channel, name=name)) def shift_frequency(frequency: float, channel: chans.PulseChannel, name: str | None = None): @@ -1629,7 +1629,7 @@ def shift_frequency(frequency: float, channel: chans.PulseChannel, name: str | N channel: Channel to shift frequency of. name: Name of the instruction. """ - append_instruction(instructions.ShiftFrequency(frequency, channel, name=name)) + append_instruction(instructions.ShiftFrequency(frequency, channel=channel, name=name)) def set_phase(phase: float, channel: chans.PulseChannel, name: str | None = None): @@ -1654,7 +1654,7 @@ def set_phase(phase: float, channel: chans.PulseChannel, name: str | None = None channel: Channel to set phase of. name: Name of the instruction. """ - append_instruction(instructions.SetPhase(phase, channel, name=name)) + append_instruction(instructions.SetPhase(phase, channel=channel, name=name)) def shift_phase(phase: float, channel: chans.PulseChannel, name: str | None = None): @@ -1678,7 +1678,7 @@ def shift_phase(phase: float, channel: chans.PulseChannel, name: str | None = No channel: Channel to shift phase of. name: Name of the instruction. """ - append_instruction(instructions.ShiftPhase(phase, channel, name)) + append_instruction(instructions.ShiftPhase(phase, channel=channel, name=name)) def snapshot(label: str, snapshot_type: str = "statevector"): diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index 066163a79b0..3914da58295 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -19,13 +19,13 @@ from qiskit.pulse.configuration import Kernel, Discriminator from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.model import Qubit +from qiskit.pulse import model class Acquire(Instruction): - """The Acquire instruction is used to trigger the ADC associated with a particular qubit; - e.g. instantiated with AcquireChannel(0), the Acquire command will trigger data collection - for the channel associated with qubit 0 readout. This instruction also provides acquisition - metadata: + """The Acquire instruction is used to trigger the ADC associated with a particular qubit. + This instruction also provides acquisition metadata: * the number of cycles during which to acquire (in terms of dt), @@ -41,7 +41,9 @@ class Acquire(Instruction): def __init__( self, duration: int | ParameterExpression, - channel: AcquireChannel, + *, + qubit: model.Qubit | None = None, + channel: AcquireChannel | None = None, mem_slot: MemorySlot | None = None, reg_slot: RegisterSlot | None = None, kernel: Kernel | None = None, @@ -50,8 +52,12 @@ def __init__( ): """Create a new Acquire instruction. + The instruction can be instantiated either with respect to :class:`~.qiskit.pulse.Qubit` + logical element, or :class:`AcquireChannel`. + Args: duration: Length of time to acquire data in terms of dt. + qubit: The qubit that will be acquired. channel: The channel that will acquire data. mem_slot: The classical memory slot in which to store the classified readout result. reg_slot: The fast-access register slot in which to store the classified readout @@ -60,38 +66,50 @@ def __init__( discriminator: A ``Discriminator`` for discriminating kerneled IQ data into 0/1 results. name: Name of the instruction for display purposes. - """ - super().__init__( - operands=(duration, channel, mem_slot, reg_slot, kernel, discriminator), - name=name, - ) - - def _validate(self): - """Called after initialization to validate instruction data. Raises: + PulseError: If the input ``qubit`` is not type :class:`~.qiskit.pulse.Qubit`. PulseError: If the input ``channel`` is not type :class:`AcquireChannel`. PulseError: If the input ``mem_slot`` is not type :class:`MemorySlot`. PulseError: If the input ``reg_slot`` is not type :class:`RegisterSlot`. PulseError: When memory slot and register slot are both empty. + PulseError: When both or none of ``qubit`` and ``channel`` are provided. """ - if not isinstance(self.channel, AcquireChannel): - raise PulseError(f"Expected an acquire channel, got {self.channel} instead.") + if qubit is not None and not isinstance(qubit, Qubit): + raise PulseError(f"Expected a qubit, got {qubit} instead.") + + if channel is not None and not isinstance(channel, AcquireChannel): + raise PulseError(f"Expected an acquire channel, got {channel} instead.") + + if (qubit is not None) + (channel is not None) != 1: + raise PulseError("Expected exactly one of qubit and channel.") - if self.mem_slot and not isinstance(self.mem_slot, MemorySlot): - raise PulseError(f"Expected a memory slot, got {self.mem_slot} instead.") + if mem_slot and not isinstance(mem_slot, MemorySlot): + raise PulseError(f"Expected a memory slot, got {mem_slot} instead.") - if self.reg_slot and not isinstance(self.reg_slot, RegisterSlot): - raise PulseError(f"Expected a register slot, got {self.reg_slot} instead.") + if reg_slot and not isinstance(reg_slot, RegisterSlot): + raise PulseError(f"Expected a register slot, got {reg_slot} instead.") - if self.mem_slot is None and self.reg_slot is None: + if mem_slot is None and reg_slot is None: raise PulseError("Neither MemorySlots nor RegisterSlots were supplied.") + super().__init__( + operands=(duration, channel or qubit, mem_slot, reg_slot, kernel, discriminator), + name=name, + ) + @property - def channel(self) -> AcquireChannel: + def channel(self) -> AcquireChannel | None: """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is scheduled on. """ + if isinstance(self.operands[1], AcquireChannel): + return self.operands[1] + return None + + @property + def qubit(self) -> AcquireChannel | model.Qubit: + """Return the element acquired by this instruction.""" return self.operands[1] @property @@ -115,11 +133,11 @@ def discriminator(self) -> Discriminator: return self._operands[5] @property - def acquire(self) -> AcquireChannel: + def acquire(self) -> AcquireChannel | model.Qubit: """Acquire channel to acquire data. The ``AcquireChannel`` index maps trivially to qubit index. """ - return self.channel + return self.operands[1] @property def mem_slot(self) -> MemorySlot: @@ -141,7 +159,7 @@ def __repr__(self) -> str: return "{}({}{}{}{}{}{})".format( self.__class__.__name__, self.duration, - ", " + str(self.channel), + ", " + str(self.qubit), ", " + str(self.mem_slot) if self.mem_slot else "", ", " + str(self.reg_slot) if self.reg_slot else "", ", " + str(self.kernel) if self.kernel else "", diff --git a/qiskit/pulse/instructions/delay.py b/qiskit/pulse/instructions/delay.py index 13f36d3b7d9..f97bf5c63d6 100644 --- a/qiskit/pulse/instructions/delay.py +++ b/qiskit/pulse/instructions/delay.py @@ -16,6 +16,8 @@ from qiskit.circuit import ParameterExpression from qiskit.pulse.channels import Channel from qiskit.pulse.instructions.instruction import Instruction +from qiskit.pulse.model import Frame, PulseTarget, MixedFrame +from qiskit.pulse.exceptions import PulseError class Delay(Instruction): @@ -37,26 +39,67 @@ class Delay(Instruction): def __init__( self, duration: int | ParameterExpression, - channel: Channel, + *, + target: PulseTarget | None = None, + frame: Frame | None = None, + mixed_frame: MixedFrame | None = None, + channel: Channel | None = None, name: str | None = None, ): """Create a new delay instruction. No other instruction may be scheduled within a ``Delay``. + The delay can be set on a ``MixedFrame`` (=``Channel``) or a ``PulseTarget``. For the latter, + provide only the ``target`` argument, and the delay will be broadcasted to all ``MixedFrame``s + involving the ``PulseTarget``. For the former, provide exactly one of ``mixed_frame``, + ``channel`` or the duo ``target`` and ``frame``, and the delay will apply only to the + specified ``MixedFrame``. + Args: duration: Length of time of the delay in terms of dt. + target: The target that will have the delay. + frame: The frame which in conjunction with ``target`` defines the mixed frame that will + have the delay. + mixed_frame: The mixed_frame that will have the delay. channel: The channel that will have the delay. name: Name of the delay for display purposes. + Raises: + PulseError: If the combination of ``target``, ``frame``, ``mixed_frame`` and ``channel`` + doesn't specify a unique ``MixedFrame`` or ``PulseTarget``. + PulseError: If the inputs to ``target``, ``frame``, ``mixed_frame`` and ``channel`` + are not of the appropriate type. """ - super().__init__(operands=(duration, channel), name=name) + if (channel is not None) + (mixed_frame is not None) + (target is not None) != 1: + raise PulseError("Exactly one of mixed_frame, channel or target must be provided") + + if frame is not None: + if target is None: + raise PulseError("frame must be provided with target") + inst_target = MixedFrame(target, frame) + else: + inst_target = mixed_frame or channel or target + + if not isinstance(inst_target, (Channel, MixedFrame, PulseTarget)): + raise PulseError( + f"Expected a MixedFrame, Channel or PulseTarget, got {inst_target} instead." + ) + + super().__init__(operands=(duration, inst_target), name=name) @property - def channel(self) -> Channel: + def inst_target(self) -> MixedFrame | PulseTarget | Channel: + """Return the object targeted by this delay instruction.""" + return self.operands[1] + + @property + def channel(self) -> Channel | None: """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is scheduled on. """ - return self.operands[1] + if isinstance(self.operands[1], Channel): + return self.operands[1] + return None @property def channels(self) -> tuple[Channel]: diff --git a/qiskit/pulse/instructions/directives.py b/qiskit/pulse/instructions/directives.py index f1e7f9b2456..6575a287f57 100644 --- a/qiskit/pulse/instructions/directives.py +++ b/qiskit/pulse/instructions/directives.py @@ -18,6 +18,7 @@ from qiskit.pulse import channels as chans from qiskit.pulse.instructions import instruction from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.channels import Channel class Directive(instruction.Instruction, ABC): @@ -45,7 +46,15 @@ def __init__(self, *channels: chans.Channel, name: str | None = None): Args: channels: The channel that the barrier applies to. name: Name of the directive for display purposes. + + Raises: + PulseError: If any of channels is not a Channel. """ + + for channel in channels: + if not isinstance(channel, Channel): + raise PulseError(f"Expected a channel, got {channel} instead.") + super().__init__(operands=tuple(channels), name=name) @property @@ -114,20 +123,19 @@ def __init__( duration: Length of time of the occupation in terms of dt. channel: The channel that will be the occupied. name: Name of the time blockade for display purposes. - """ - super().__init__(operands=(duration, channel), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. Raises: - PulseError: If the input ``duration`` is not integer value. + PulseError: If ``duration`` is not a positive integer value. """ - if not isinstance(self.duration, int): + + if not isinstance(duration, int) or duration < 0: raise PulseError( - "TimeBlockade duration cannot be parameterized. Specify an integer duration value." + "TimeBlockade duration cannot be parameterized. Specify a positive integer" + "duration value." ) + super().__init__(operands=(duration, channel), name=name) + @property def channel(self) -> chans.Channel: """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is diff --git a/qiskit/pulse/instructions/frequency.py b/qiskit/pulse/instructions/frequency.py index a14e60ee1a3..67ce58d4a69 100644 --- a/qiskit/pulse/instructions/frequency.py +++ b/qiskit/pulse/instructions/frequency.py @@ -13,120 +13,111 @@ """Frequency instructions module. These instructions allow the user to manipulate the frequency of a channel. """ -from typing import Optional, Union, Tuple +from __future__ import annotations -from qiskit.circuit.parameterexpression import ParameterExpression +from qiskit.circuit.parameterexpression import ParameterValueType from qiskit.pulse.channels import PulseChannel -from qiskit.pulse.instructions.instruction import Instruction -from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.instructions.instruction import FrameUpdate +from qiskit.pulse.model import Frame, MixedFrame, PulseTarget -class SetFrequency(Instruction): - r"""Set the channel frequency. This instruction operates on ``PulseChannel`` s. - A ``PulseChannel`` creates pulses of the form +class SetFrequency(FrameUpdate): + r"""The set frequency instruction sets the modulation frequency of proceeding pulses + associated with the frame the instruction is acting upon. + + In particular, played pulses take the form: .. math:: Re[\exp(i 2\pi f jdt + \phi) d_j]. - Here, :math:`f` is the frequency of the channel. The instruction ``SetFrequency`` allows - the user to set the value of :math:`f`. All pulses that are played on a channel - after SetFrequency has been called will have the corresponding frequency. + Here, :math:`f` is the frequency of the modulation. The instruction ``SetFrequency`` allows + the user to set the value of :math:`f`. - The duration of SetFrequency is 0. + The duration of ``SetFrequency`` is 0. """ def __init__( self, - frequency: Union[float, ParameterExpression], - channel: PulseChannel, - name: Optional[str] = None, + frequency: ParameterValueType, + *, + frame: Frame | None = None, + target: PulseTarget | None = None, + mixed_frame: MixedFrame | None = None, + channel: PulseChannel | None = None, + name: str | None = None, ): - """Creates a new set channel frequency instruction. + """Creates a new set frequency instruction. + + The instruction can be set on a ``MixedFrame`` (=``Channel``) or a ``Frame``. For the latter, + provide only the ``frame`` argument, and the instruction will be broadcasted to all + ``MixedFrame``s involving the ``Frame``. For the former, provide exactly one of + ``mixed_frame``, ``channel`` or the duo ``target`` and ``frame``, and the instruction + will apply only to the specified ``MixedFrame``. Args: frequency: New frequency of the channel in Hz. - channel: The channel this instruction operates on. - name: Name of this set channel frequency instruction. - """ - super().__init__(operands=(frequency, channel), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. - - Raises: - PulseError: If the input ``channel`` is not type :class:`PulseChannel`. + frame: The frame the instruction will apply to. + target: The target which in conjunction with ``frame`` defines the mixed frame that + instruction will apply to. + mixed_frame: The mixed_frame the instruction will apply to. + channel: The channel the instruction will apply to. + name: Name of this set frequency instruction. """ - if not isinstance(self.channel, PulseChannel): - raise PulseError(f"Expected a pulse channel, got {self.channel} instead.") + inst_target = self._validate_and_format_frame(target, frame, mixed_frame, channel) + super().__init__(operands=(frequency, inst_target), name=name) @property - def frequency(self) -> Union[float, ParameterExpression]: + def frequency(self) -> ParameterValueType: """New frequency.""" return self.operands[0] - @property - def channel(self) -> PulseChannel: - """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is - scheduled on. - """ - return self.operands[1] - @property - def channels(self) -> Tuple[PulseChannel]: - """Returns the channels that this schedule uses.""" - return (self.channel,) +class ShiftFrequency(FrameUpdate): + r"""The shift frequency instruction updates the modulation frequency of proceeding pulses + associated with the frame the instruction is acting upon. - @property - def duration(self) -> int: - """Duration of this instruction.""" - return 0 + In particular, played pulses take the form: + + .. math:: + Re[\exp(i 2\pi f jdt + \phi) d_j]. + Here, :math:`f` is the frequency of the modulation. The instruction ``shiftFrequency`` allows + the user to shift the value of :math:`f` by the value specified by the instructions. -class ShiftFrequency(Instruction): - """Shift the channel frequency away from the current frequency.""" + The duration of ``ShiftFrequency`` is 0. + """ def __init__( self, - frequency: Union[float, ParameterExpression], - channel: PulseChannel, - name: Optional[str] = None, + frequency: ParameterValueType, + *, + frame: Frame | None = None, + target: PulseTarget | None = None, + mixed_frame: MixedFrame | None = None, + channel: PulseChannel | None = None, + name: str | None = None, ): """Creates a new shift frequency instruction. + The instruction can be set on a ``MixedFrame`` (=``Channel``) or a ``Frame``. For the latter, + provide only the ``frame`` argument, and the instruction will be broadcasted to all + ``MixedFrame``s involving the ``Frame``. For the former, provide exactly one of + ``mixed_frame``, ``channel`` or the duo ``target`` and ``frame``, and the instruction + will apply only to the specified ``MixedFrame``. + Args: frequency: Frequency shift of the channel in Hz. - channel: The channel this instruction operates on. - name: Name of this set channel frequency instruction. - """ - super().__init__(operands=(frequency, channel), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. - - Raises: - PulseError: If the input ``channel`` is not type :class:`PulseChannel`. + frame: The frame the instruction will apply to. + target: The target which in conjunction with ``frame`` defines the mixed frame that + instruction will apply to. + mixed_frame: The mixed_frame the instruction will apply to. + channel: The channel the instruction will apply to. + name: Name of this set frequency instruction. """ - if not isinstance(self.channel, PulseChannel): - raise PulseError(f"Expected a pulse channel, got {self.channel} instead.") + inst_target = self._validate_and_format_frame(target, frame, mixed_frame, channel) + super().__init__(operands=(frequency, inst_target), name=name) @property - def frequency(self) -> Union[float, ParameterExpression]: + def frequency(self) -> ParameterValueType: """Frequency shift from the set frequency.""" return self.operands[0] - - @property - def channel(self) -> PulseChannel: - """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is - scheduled on. - """ - return self.operands[1] - - @property - def channels(self) -> Tuple[PulseChannel]: - """Returns the channels that this schedule uses.""" - return (self.channel,) - - @property - def duration(self) -> int: - """Duration of this instruction.""" - return 0 diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index ece20545b50..777ad30109b 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -23,11 +23,12 @@ """ from __future__ import annotations from abc import ABC, abstractmethod -from collections.abc import Iterable +from typing import Iterable, Tuple from qiskit.circuit import Parameter, ParameterExpression -from qiskit.pulse.channels import Channel +from qiskit.pulse.channels import Channel, PulseChannel from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.model import PulseTarget, Frame, MixedFrame # pylint: disable=bad-docstring-quotes @@ -51,17 +52,6 @@ def __init__( """ self._operands = operands self._name = name - self._validate() - - def _validate(self): - """Called after initialization to validate instruction data. - - Raises: - PulseError: If the input ``channels`` are not all of type :class:`Channel`. - """ - for channel in self.channels: - if not isinstance(channel, Channel): - raise PulseError(f"Expected a channel, got {channel} instead.") @property def name(self) -> str: @@ -267,3 +257,75 @@ def __repr__(self) -> str: return "{}({}{})".format( self.__class__.__name__, operands, f", name='{self.name}'" if self.name else "" ) + + +class FrameUpdate(Instruction, ABC): + """Instructions updating a ``Frame`` (or ``MixedFrame``). + + + ``FrameUpdate``s can be defined on either a ``MixedFrame`` (=``Channel``) or a ``Frame``. + For a ``MixedFrame`` the instruction applies only to the specific ``MixedFrame``. However, for + a ``Frame`` the instruction will be broadcasted to all ``MixedFrame``s associated with that + ``Frame``. + + ``FrameUpdate`` should be considered abstract, and should not be instantiated as is. + """ + + def _validate_and_format_frame( + self, target: PulseTarget, frame: Frame, mixed_frame: MixedFrame, channel: Channel + ) -> Frame | MixedFrame | PulseChannel: + """Called after initialization to validate instruction data. + + Arguments: + target: The pulse target used in conjunction with ``frame`` to define the mixed frame + the instruction applies to. + frame: The frame the instruction applies to. + mixed_frame: The mixed_frame the instruction applies to. + channel: The channel the instruction applies to. + + Returns: + Union[Frame, MixedFrame, PulseChannel]: The frame or mixed frame the instruction applies to. + + Raises: + PulseError: If the combination of ``target``, ``frame``, ``mixed_frame`` and + ``channel`` doesn't specify a unique ``MixedFrame`` or ``Frame``. + """ + + if (channel is not None) + (mixed_frame is not None) + (frame is not None) != 1: + raise PulseError("Exactly one of mixed_frame, channel or frame must be provided") + + if target is not None: + if frame is None: + raise PulseError("target can not be provided without frame") + inst_target = MixedFrame(target, frame) + else: + inst_target = mixed_frame or channel or frame + + if not isinstance(inst_target, (PulseChannel, MixedFrame, Frame)): + raise PulseError(f"Expected a MixedFrame, Channel or Frame, got {inst_target} instead.") + + return inst_target + + @property + def channel(self) -> PulseChannel | None: + """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is + scheduled on. + """ + if isinstance(self.operands[1], PulseChannel): + return self.operands[1] + return None + + @property + def inst_target(self) -> MixedFrame | Frame | PulseChannel: + """Return the frame or mixed frame targeted by this instruction.""" + return self.operands[1] + + @property + def channels(self) -> Tuple[Channel]: + """Returns the channels that this frame instruction uses.""" + return (self.channel,) + + @property + def duration(self) -> int: + """Duration of this instruction.""" + return 0 diff --git a/qiskit/pulse/instructions/phase.py b/qiskit/pulse/instructions/phase.py index 21f46dfb5f7..e8ced4a6d6c 100644 --- a/qiskit/pulse/instructions/phase.py +++ b/qiskit/pulse/instructions/phase.py @@ -15,26 +15,26 @@ at that moment, and ``ShiftPhase`` instructions which increase the existing phase by a relative amount. """ -from typing import Optional, Union, Tuple +from __future__ import annotations -from qiskit.circuit import ParameterExpression +from qiskit.circuit.parameterexpression import ParameterValueType from qiskit.pulse.channels import PulseChannel -from qiskit.pulse.instructions.instruction import Instruction -from qiskit.pulse.exceptions import PulseError +from qiskit.pulse.instructions.instruction import FrameUpdate +from qiskit.pulse.model import Frame, MixedFrame, PulseTarget -class ShiftPhase(Instruction): - r"""The shift phase instruction updates the modulation phase of proceeding pulses played on the - same :py:class:`~qiskit.pulse.channels.Channel`. It is a relative increase in phase determined +class ShiftPhase(FrameUpdate): + r"""The shift phase instruction updates the modulation phase of proceeding pulses associated with + the frame the instruction is acting upon. It is a relative increase in phase determined by the ``phase`` operand. - In particular, a PulseChannel creates pulses of the form + In particular, played pulses take the form: .. math:: Re[\exp(i 2\pi f jdt + \phi) d_j]. The ``ShiftPhase`` instruction causes :math:`\phi` to be increased by the instruction's - ``phase`` operand. This will affect all pulses following on the same channel. + ``phase`` operand. This will affect all pulses following on the same frame. The qubit phase is tracked in software, enabling instantaneous, nearly error-free Z-rotations by using a ShiftPhase to update the frame tracking the qubit state. @@ -42,57 +42,46 @@ class ShiftPhase(Instruction): def __init__( self, - phase: Union[complex, ParameterExpression], - channel: PulseChannel, - name: Optional[str] = None, + phase: ParameterValueType, + *, + frame: Frame | None = None, + target: PulseTarget | None = None, + mixed_frame: MixedFrame | None = None, + channel: PulseChannel | None = None, + name: str | None = None, ): - """Instantiate a shift phase instruction, increasing the output signal phase on ``channel`` - by ``phase`` [radians]. + """Instantiate a shift phase instruction, increasing the output signal phase on a given + mixed frame (=channel) or frame by ``phase`` [radians]. + + The instruction can be set on a ``MixedFrame`` (=``Channel``) or a ``Frame``. For the latter, + provide only the ``frame`` argument, and the instruction will be broadcasted to all + ``MixedFrame``s involving the ``Frame``. For the former, provide exactly one of + ``mixed_frame``, ``channel`` or the duo ``target`` and ``frame``, and the instruction + will apply only to the specified ``MixedFrame``. Args: phase: The rotation angle in radians. - channel: The channel this instruction operates on. + frame: The frame the instruction will apply to. + target: The target which in conjunction with ``frame`` defines the mixed frame that + instruction will apply to. + mixed_frame: The mixed_frame the instruction will apply to. + channel: The channel the instruction will apply to. name: Display name for this instruction. """ - super().__init__(operands=(phase, channel), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. - - Raises: - PulseError: If the input ``channel`` is not type :class:`PulseChannel`. - """ - if not isinstance(self.channel, PulseChannel): - raise PulseError(f"Expected a pulse channel, got {self.channel} instead.") + inst_target = self._validate_and_format_frame(target, frame, mixed_frame, channel) + super().__init__(operands=(phase, inst_target), name=name) @property - def phase(self) -> Union[complex, ParameterExpression]: + def phase(self) -> ParameterValueType: """Return the rotation angle enacted by this instruction in radians.""" return self.operands[0] - @property - def channel(self) -> PulseChannel: - """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is - scheduled on. - """ - return self.operands[1] - - @property - def channels(self) -> Tuple[PulseChannel]: - """Returns the channels that this schedule uses.""" - return (self.channel,) - - @property - def duration(self) -> int: - """Duration of this instruction.""" - return 0 - -class SetPhase(Instruction): - r"""The set phase instruction sets the phase of the proceeding pulses on that channel - to ``phase`` radians. +class SetPhase(FrameUpdate): + r"""The set phase instruction updates the modulation phase of proceeding pulses associated with + the frame the instruction is acting upon. It sets the phase to the ``phase`` operand. - In particular, a PulseChannel creates pulses of the form + In particular, played pulses take the form: .. math:: @@ -103,47 +92,36 @@ class SetPhase(Instruction): def __init__( self, - phase: Union[complex, ParameterExpression], - channel: PulseChannel, - name: Optional[str] = None, + phase: ParameterValueType, + *, + frame: Frame | None = None, + target: PulseTarget | None = None, + mixed_frame: MixedFrame | None = None, + channel: PulseChannel | None = None, + name: str = None, ): - """Instantiate a set phase instruction, setting the output signal phase on ``channel`` - to ``phase`` [radians]. + """Instantiate a set phase instruction, setting the output signal phase on a given + mixed frame (=channel) or frame to ``phase`` [radians].. + + The instruction can be set on a ``MixedFrame`` (=``Channel``) or a ``Frame``. For the latter, + provide only the ``frame`` argument, and the instruction will be broadcasted to all + ``MixedFrame``s involving the ``Frame``. For the former, provide exactly one of + ``mixed_frame``, ``channel`` or the duo ``target`` and ``frame``, and the instruction + will apply only to the specified ``MixedFrame``. Args: phase: The rotation angle in radians. - channel: The channel this instruction operates on. + frame: The frame the instruction will apply to. + target: The target which in conjunction with ``frame`` defines the mixed frame that + instruction will apply to. + mixed_frame: The mixed_frame the instruction will apply to. + channel: The channel the instruction will apply to. name: Display name for this instruction. """ - super().__init__(operands=(phase, channel), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. - - Raises: - PulseError: If the input ``channel`` is not type :class:`PulseChannel`. - """ - if not isinstance(self.channel, PulseChannel): - raise PulseError(f"Expected a pulse channel, got {self.channel} instead.") + inst_target = self._validate_and_format_frame(target, frame, mixed_frame, channel) + super().__init__(operands=(phase, inst_target), name=name) @property - def phase(self) -> Union[complex, ParameterExpression]: + def phase(self) -> ParameterValueType: """Return the rotation angle enacted by this instruction in radians.""" return self.operands[0] - - @property - def channel(self) -> PulseChannel: - """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is - scheduled on. - """ - return self.operands[1] - - @property - def channels(self) -> Tuple[PulseChannel]: - """Returns the channels that this schedule uses.""" - return (self.channel,) - - @property - def duration(self) -> int: - """Duration of this instruction.""" - return 0 diff --git a/qiskit/pulse/instructions/play.py b/qiskit/pulse/instructions/play.py index 1f42b8e3a08..44c9737a071 100644 --- a/qiskit/pulse/instructions/play.py +++ b/qiskit/pulse/instructions/play.py @@ -14,6 +14,7 @@ transmitted pulses, such as ``DriveChannel``). """ from __future__ import annotations +from typing import Tuple from qiskit.circuit import Parameter from qiskit.circuit.parameterexpression import ParameterExpression @@ -21,42 +22,70 @@ from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instructions.instruction import Instruction from qiskit.pulse.library.pulse import Pulse +from qiskit.pulse.model import PulseTarget, Frame, MixedFrame class Play(Instruction): - """This instruction is responsible for applying a pulse on a channel. + """This instruction is responsible for playing a pulse on relevant hardware. The pulse specifies the exact time dynamics of the output signal envelope for a limited - time. The output is modulated by a phase and frequency which are controlled by separate + time. The output is modulated by a phase and frequency (frame) which are controlled by separate instructions. The pulse duration must be fixed, and is implicitly given in terms of the cycle time, dt, of the backend. """ - def __init__(self, pulse: Pulse, channel: PulseChannel, name: str | None = None): - """Create a new pulse instruction. + def __init__( + self, + pulse: Pulse, + *, + target: PulseTarget | None = None, + frame: Frame | None = None, + mixed_frame: MixedFrame | None = None, + channel: PulseChannel | None = None, + name: str | None = None, + ): + """Create a new pulse play instruction. + + To uniquely identify the mixed frame to which the pulse is applied, the arguments must include + exactly one of ``mixed_frame``, ``channel`` or the duo ``target`` and ``frame``. Args: pulse: A pulse waveform description, such as :py:class:`~qiskit.pulse.library.Waveform`. + target: The target to which the pulse is applied (must be provided with ``frame``). + frame: The frame characterizing the pulse carrier (must be provided with ``target``). + mixed_frame: The mixed frame to which the pulse is applied. channel: The channel to which the pulse is applied. name: Name of the instruction for display purposes. Defaults to ``pulse.name``. - """ - if name is None: - name = pulse.name - super().__init__(operands=(pulse, channel), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. Raises: + PulseError: If the combination of ``target``, ``frame``, ``mixed_frame`` and ``channel`` + doesn't specify a unique mixed frame. + PulseError: If the inputs to ``target``, ``frame``, ``mixed_frame`` and ``channel`` + are not of the appropriate type. PulseError: If pulse is not a Pulse type. - PulseError: If the input ``channel`` is not type :class:`PulseChannel`. """ - if not isinstance(self.pulse, Pulse): + if not isinstance(pulse, Pulse): raise PulseError("The `pulse` argument to `Play` must be of type `library.Pulse`.") - if not isinstance(self.channel, PulseChannel): - raise PulseError(f"Expected a pulse channel, got {self.channel} instead.") + if (target is not None) != (frame is not None): + raise PulseError("target and frame must be provided simultaneously") + if (channel is not None) + (mixed_frame is not None) + (target is not None) != 1: + raise PulseError( + "Exactly one of mixed_frame, channel or the duo target and frame has to be provided" + ) + + if target is not None: + mixed_frame = MixedFrame(target, frame) + else: + mixed_frame = mixed_frame or channel + + if not isinstance(mixed_frame, (PulseChannel, MixedFrame)): + raise PulseError(f"Expected a mixed frame or pulse channel, got {mixed_frame} instead.") + + if name is None: + name = pulse.name + super().__init__(operands=(pulse, mixed_frame), name=name) @property def pulse(self) -> Pulse: @@ -64,14 +93,21 @@ def pulse(self) -> Pulse: return self.operands[0] @property - def channel(self) -> PulseChannel: + def channel(self) -> PulseChannel | None: """Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is scheduled on. """ + if isinstance(self.operands[1], PulseChannel): + return self.operands[1] + return None + + @property + def inst_target(self) -> PulseChannel | MixedFrame: + """Return the mixed frame targeted by this pulse play instruction.""" return self.operands[1] @property - def channels(self) -> tuple[PulseChannel]: + def channels(self) -> Tuple[PulseChannel | None]: """Returns the channels that this schedule uses.""" return (self.channel,) @@ -91,7 +127,7 @@ def parameters(self) -> set[Parameter]: if isinstance(pulse_param_expr, ParameterExpression): parameters = parameters | pulse_param_expr.parameters - if self.channel.is_parameterized(): + if self.channel is not None and self.channel.is_parameterized(): parameters = parameters | self.channel.parameters return parameters diff --git a/qiskit/pulse/instructions/reference.py b/qiskit/pulse/instructions/reference.py index cf3e01f8ea6..c776154a5fb 100644 --- a/qiskit/pulse/instructions/reference.py +++ b/qiskit/pulse/instructions/reference.py @@ -53,19 +53,14 @@ def __init__(self, name: str, *extra_keys: str): to distinguish the sx schedule for qubit 0 from others. The user can use an arbitrary number of extra string keys to uniquely determine the subroutine. - """ - # Run validation - ref_keys = (name,) + tuple(extra_keys) - super().__init__(operands=ref_keys, name=name) - - def _validate(self): - """Called after initialization to validate instruction data. Raises: - PulseError: When a key is not a string. - PulseError: When a key in ``ref_keys`` contains the scope delimiter. + PulseError: When ``name`` or an ``extra_key`` is not a string. + PulseError: When ``name`` or an ``extra_key`` contains the scope delimiter. """ - for key in self.ref_keys: + ref_keys = (name,) + tuple(extra_keys) + + for key in ref_keys: if not isinstance(key, str): raise PulseError(f"Keys must be strings. '{repr(key)}' is not a valid object.") if self.scope_delimiter in key or self.key_delimiter in key: @@ -74,6 +69,8 @@ def _validate(self): f"'{key}' is not a valid key string." ) + super().__init__(operands=ref_keys, name=name) + @property def ref_keys(self) -> tuple[str, ...]: """Returns unique key of the subroutine.""" diff --git a/qiskit/pulse/instructions/snapshot.py b/qiskit/pulse/instructions/snapshot.py index b78858b5d2c..c7877b1db95 100644 --- a/qiskit/pulse/instructions/snapshot.py +++ b/qiskit/pulse/instructions/snapshot.py @@ -32,22 +32,20 @@ def __init__(self, label: str, snapshot_type: str = "statevector", name: Optiona The types of snapshots offered are defined by the simulator used. name: Snapshot name which defaults to ``label``. This parameter is only for display purposes and is not taken into account during comparison. + + Raises: + PulseError: If snapshot label is invalid. """ self._channel = SnapshotChannel() if name is None: name = label - super().__init__(operands=(label, snapshot_type), name=name) - - def _validate(self): - """Called after initialization to validate instruction data. - Raises: - PulseError: If snapshot label is invalid. - """ - if not isinstance(self.label, str): + if not isinstance(label, str): raise PulseError("Snapshot label must be a string.") + super().__init__(operands=(label, snapshot_type), name=name) + @property def label(self) -> str: """Label of snapshot.""" diff --git a/qiskit/pulse/macros.py b/qiskit/pulse/macros.py index 1995d6d20c4..53e5eefa59c 100644 --- a/qiskit/pulse/macros.py +++ b/qiskit/pulse/macros.py @@ -143,7 +143,7 @@ def _measure_v1( mem_slot = channels.MemorySlot(qubit_mem_slots[inst.channel.index]) else: mem_slot = channels.MemorySlot(unused_mem_slots.pop()) - inst = instructions.Acquire(inst.duration, inst.channel, mem_slot=mem_slot) + inst = instructions.Acquire(inst.duration, channel=inst.channel, mem_slot=mem_slot) # Measurement pulses should only be added if its qubit was measured by the user schedule = schedule.insert(time, inst) @@ -247,7 +247,7 @@ def _schedule_remapping_memory_slot( t0, instructions.Acquire( inst.duration, - channels.AcquireChannel(qubit_index), + channel=channels.AcquireChannel(qubit_index), mem_slot=channels.MemorySlot(reg_index), ), inplace=True, diff --git a/qiskit/pulse/model/mixed_frames.py b/qiskit/pulse/model/mixed_frames.py index 454cdbf0d2c..9598b0bfa3b 100644 --- a/qiskit/pulse/model/mixed_frames.py +++ b/qiskit/pulse/model/mixed_frames.py @@ -13,6 +13,7 @@ """ Mixed Frames """ +from qiskit.pulse.exceptions import PulseError from .frames import Frame from .pulse_target import PulseTarget @@ -44,7 +45,14 @@ def __init__(self, pulse_target: PulseTarget, frame: Frame): Args: pulse_target: The ``PulseTarget`` associated with the mixed frame. frame: The frame associated with the mixed frame. + + Raises: + PulseError: If ``pulse_target`` or ``frame`` are not of the appropriate type. """ + if (not isinstance(pulse_target, PulseTarget)) or (not isinstance(frame, Frame)): + raise PulseError( + f"Expected PulseTarget and Frame got {pulse_target} and {frame} instead." + ) self._pulse_target = pulse_target self._frame = frame @@ -71,7 +79,11 @@ def __eq__(self, other: "MixedFrame") -> bool: Returns: True iff equal. """ - return self._pulse_target == other._pulse_target and self._frame == other._frame + return ( + isinstance(other, type(self)) + and self._pulse_target == other._pulse_target + and self._frame == other._frame + ) def __hash__(self) -> int: return hash((self._pulse_target, self._frame, type(self))) diff --git a/qiskit/pulse/transforms/canonicalization.py b/qiskit/pulse/transforms/canonicalization.py index 9bda5907c2f..ead780d1b1c 100644 --- a/qiskit/pulse/transforms/canonicalization.py +++ b/qiskit/pulse/transforms/canonicalization.py @@ -104,7 +104,7 @@ def compress_pulses(schedules: list[Schedule]) -> list[Schedule]: identical_pulse = existing_pulses[idx] new_schedule.insert( time, - instructions.Play(identical_pulse, inst.channel, inst.name), + instructions.Play(identical_pulse, channel=inst.channel, name=inst.name), inplace=True, ) else: @@ -416,7 +416,7 @@ def add_implicit_acquires(schedule: ScheduleComponent, meas_map: list[list[int]] for i in all_qubits: explicit_inst = instructions.Acquire( inst.duration, - chans.AcquireChannel(i), + channel=chans.AcquireChannel(i), mem_slot=chans.MemorySlot(i), kernel=inst.kernel, discriminator=inst.discriminator, @@ -477,7 +477,9 @@ def pad( continue if channel not in schedule.channels: - schedule = schedule.insert(0, instructions.Delay(until, channel), inplace=inplace) + schedule = schedule.insert( + 0, instructions.Delay(until, channel=channel), inplace=inplace + ) continue prev_time = 0 @@ -493,6 +495,6 @@ def pad( to_pad.append((prev_time, min(t0, until) - prev_time)) prev_time = t1 for t0, duration in to_pad: - schedule = schedule.insert(t0, pad_cls(duration, channel), inplace=inplace) + schedule = schedule.insert(t0, pad_cls(duration, channel=channel), inplace=inplace) return schedule diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index b8b96e7dc4b..eb5bd4c95fd 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -696,7 +696,7 @@ def _convert_acquire( for acquire_channel, mem_slot, reg_slot in zip(acquire_channels, mem_slots, register_slots): yield instructions.Acquire( duration, - acquire_channel, + channel=acquire_channel, mem_slot=mem_slot, reg_slot=reg_slot, kernel=kernel, @@ -718,7 +718,7 @@ def _convert_setp( channel = self.get_channel(instruction.ch) phase = self.disassemble_value(instruction.phase) - yield instructions.SetPhase(phase, channel) + yield instructions.SetPhase(phase, channel=channel) def _convert_fc( self, @@ -735,7 +735,7 @@ def _convert_fc( channel = self.get_channel(instruction.ch) phase = self.disassemble_value(instruction.phase) - yield instructions.ShiftPhase(phase, channel) + yield instructions.ShiftPhase(phase, channel=channel) def _convert_setf( self, @@ -757,7 +757,7 @@ def _convert_setf( channel = self.get_channel(instruction.ch) frequency = self.disassemble_value(instruction.frequency) * 1e9 - yield instructions.SetFrequency(frequency, channel) + yield instructions.SetFrequency(frequency, channel=channel) def _convert_shiftf( self, @@ -779,7 +779,7 @@ def _convert_shiftf( channel = self.get_channel(instruction.ch) frequency = self.disassemble_value(instruction.frequency) * 1e9 - yield instructions.ShiftFrequency(frequency, channel) + yield instructions.ShiftFrequency(frequency, channel=channel) def _convert_delay( self, @@ -796,7 +796,7 @@ def _convert_delay( channel = self.get_channel(instruction.ch) duration = instruction.duration - yield instructions.Delay(duration, channel) + yield instructions.Delay(duration, channel=channel) def _convert_parametric_pulse( self, @@ -838,7 +838,7 @@ def _convert_parametric_pulse( params["amp"] = np.abs(params["amp"]) pulse = ParametricPulseShapes.to_type(instruction.pulse_shape)(**params, name=pulse_name) - yield instructions.Play(pulse, channel) + yield instructions.Play(pulse, channel=channel) def _convert_snapshot( self, @@ -876,7 +876,7 @@ def _convert_generic( ) channel = self.get_channel(instruction.ch) - yield instructions.Play(waveform, channel) + yield instructions.Play(waveform, channel=channel) else: if qubits := getattr(instruction, "qubits", None): msg = f"qubits {qubits}" diff --git a/qiskit/visualization/pulse_v2/core.py b/qiskit/visualization/pulse_v2/core.py index d60f2db030d..6f4b9985bb2 100644 --- a/qiskit/visualization/pulse_v2/core.py +++ b/qiskit/visualization/pulse_v2/core.py @@ -242,7 +242,7 @@ def _waveform_loader( chart = Chart(parent=self) # add waveform data - fake_inst = pulse.Play(program, types.WaveformChannel()) + fake_inst = pulse.Play(program, channel=types.WaveformChannel()) inst_data = types.PulseInstruction( t0=0, dt=self.device.dt, diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py index d94c935afa7..b69de2769db 100644 --- a/test/python/circuit/test_circuit_operations.py +++ b/test/python/circuit/test_circuit_operations.py @@ -399,7 +399,7 @@ def test_copy_empty_like_circuit(self): qc.h(qr[0]) qc.measure(qr[0], cr[0]) qc.measure(qr[1], cr[1]) - sched = Schedule(Play(Gaussian(160, 0.1, 40), DriveChannel(0))) + sched = Schedule(Play(Gaussian(160, 0.1, 40), channel=DriveChannel(0))) qc.add_calibration("h", [0, 1], sched) copied = qc.copy_empty_like() qc.clear() diff --git a/test/python/circuit/test_parameters.py b/test/python/circuit/test_parameters.py index 6494fcc463a..ad974036910 100644 --- a/test/python/circuit/test_parameters.py +++ b/test/python/circuit/test_parameters.py @@ -601,7 +601,7 @@ def test_calibration_assignment(self): rxt_q0 = pulse.Schedule( pulse.Play( pulse.library.Gaussian(duration=128, sigma=16, amp=0.2 * theta / 3.14), - pulse.DriveChannel(0), + channel=pulse.DriveChannel(0), ) ) @@ -629,7 +629,7 @@ def test_calibration_assignment_doesnt_mutate(self): rxt_q0 = pulse.Schedule( pulse.Play( pulse.library.Gaussian(duration=128, sigma=16, amp=0.2 * theta / 3.14), - pulse.DriveChannel(0), + channel=pulse.DriveChannel(0), ) ) @@ -651,7 +651,7 @@ def test_calibration_assignment_w_expressions(self): rxt_q0 = pulse.Schedule( pulse.Play( pulse.library.Gaussian(duration=128, sigma=4 * sigma, amp=0.2 * theta / 3.14), - pulse.DriveChannel(0), + channel=pulse.DriveChannel(0), ) ) @@ -674,7 +674,7 @@ def test_substitution(self): """Test Parameter substitution (vs bind).""" alpha = Parameter("⍺") beta = Parameter("beta") - schedule = pulse.Schedule(pulse.ShiftPhase(alpha, pulse.DriveChannel(0))) + schedule = pulse.Schedule(pulse.ShiftPhase(alpha, channel=pulse.DriveChannel(0))) circ = QuantumCircuit(3, 3) circ.append(Gate("my_rz", 1, [alpha]), [0]) diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index bb6aa6d47a9..f296242fc89 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -603,7 +603,9 @@ def test_pulse_gates_delay_only(self): """Test that a single delay gate is translated to an instruction.""" circ = QuantumCircuit(2) circ.append(Gate("test", 1, []), [0]) - test_sched = pulse.Delay(64, DriveChannel(0)) + pulse.Delay(160, DriveChannel(0)) + test_sched = pulse.Delay(64, channel=DriveChannel(0)) + pulse.Delay( + 160, channel=DriveChannel(0) + ) circ.add_calibration("test", [0], test_sched) qobj = assemble(circ, FakeOpenPulse2Q()) self.assertEqual(len(qobj.config.calibrations.gates[0].instructions), 2) @@ -908,10 +910,12 @@ def setUp(self): ) self.schedule = pulse.Schedule(name="fake_experiment") - self.schedule = self.schedule.insert(0, Play(test_pulse, self.backend_config.drive(0))) + self.schedule = self.schedule.insert( + 0, Play(test_pulse, channel=self.backend_config.drive(0)) + ) for i in range(self.backend_config.n_qubits): self.schedule = self.schedule.insert( - 5, Acquire(5, self.backend_config.acquire(i), MemorySlot(i)) + 5, Acquire(5, channel=self.backend_config.acquire(i), mem_slot=MemorySlot(i)) ) self.user_lo_config_dict = {self.backend_config.drive(0): 4.91e9} @@ -943,13 +947,13 @@ def test_assemble_sample_pulse(self): """Test that the pulse lib and qobj instruction can be paired up.""" schedule = pulse.Schedule() schedule += pulse.Play( - pulse.Waveform([0.1] * 16, name="test0"), pulse.DriveChannel(0), name="test1" + pulse.Waveform([0.1] * 16, name="test0"), channel=pulse.DriveChannel(0), name="test1" ) schedule += pulse.Play( - pulse.Waveform([0.1] * 16, name="test1"), pulse.DriveChannel(0), name="test2" + pulse.Waveform([0.1] * 16, name="test1"), channel=pulse.DriveChannel(0), name="test2" ) schedule += pulse.Play( - pulse.Waveform([0.5] * 16, name="test0"), pulse.DriveChannel(0), name="test1" + pulse.Waveform([0.5] * 16, name="test0"), channel=pulse.DriveChannel(0), name="test1" ) qobj = assemble( schedule, @@ -1086,8 +1090,8 @@ def test_assemble_multi_schedules_with_wrong_number_of_multi_lo_configs(self): def test_assemble_meas_map(self): """Test assembling a single schedule, no lo config.""" schedule = Schedule(name="fake_experiment") - schedule = schedule.insert(5, Acquire(5, AcquireChannel(0), MemorySlot(0))) - schedule = schedule.insert(5, Acquire(5, AcquireChannel(1), MemorySlot(1))) + schedule = schedule.insert(5, Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0))) + schedule = schedule.insert(5, Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1))) qobj = assemble( schedule, @@ -1111,7 +1115,7 @@ def test_assemble_memory_slots(self): # single acquisition schedule = Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) + 5, channel=self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) ) qobj = assemble( @@ -1127,12 +1131,14 @@ def test_assemble_memory_slots(self): # multiple acquisition schedule = Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) + 5, channel=self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) ) schedule = schedule.insert( 10, Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslots - 1) + 5, + channel=self.backend_config.acquire(0), + mem_slot=pulse.MemorySlot(n_memoryslots - 1), ), ) @@ -1154,7 +1160,9 @@ def test_assemble_memory_slots_for_schedules(self): schedules = [] for n_memoryslot in n_memoryslots: schedule = Acquire( - 5, self.backend_config.acquire(0), mem_slot=pulse.MemorySlot(n_memoryslot - 1) + 5, + channel=self.backend_config.acquire(0), + mem_slot=pulse.MemorySlot(n_memoryslot - 1), ) schedules.append(schedule) @@ -1177,7 +1185,7 @@ def test_pulse_name_conflicts(self): ) self.schedule = self.schedule.insert( - 1, Play(name_conflict_pulse, self.backend_config.drive(1)) + 1, Play(name_conflict_pulse, channel=self.backend_config.drive(1)) ) qobj = assemble( @@ -1200,7 +1208,9 @@ def test_pulse_name_conflicts_in_other_schedule(self): ch_d0 = pulse.DriveChannel(0) for amp in (0.1, 0.2): sched = Schedule() - sched += Play(pulse.Gaussian(duration=100, amp=amp, sigma=30, name="my_pulse"), ch_d0) + sched += Play( + pulse.Gaussian(duration=100, amp=amp, sigma=30, name="my_pulse"), channel=ch_d0 + ) sched += measure(qubits=[0], backend=backend) << 100 schedules.append(sched) @@ -1213,7 +1223,7 @@ def test_pulse_name_conflicts_in_other_schedule(self): def test_assemble_with_delay(self): """Test that delay instruction is not ignored in assembly.""" - delay_schedule = pulse.Delay(10, self.backend_config.drive(0)) + delay_schedule = pulse.Delay(10, channel=self.backend_config.drive(0)) delay_schedule += self.schedule delay_qobj = assemble(delay_schedule, self.backend) @@ -1225,8 +1235,8 @@ def test_delay_removed_on_acq_ch(self): """Test that delay instructions on acquire channels are skipped on assembly with times shifted properly. """ - delay0 = pulse.Delay(5, self.backend_config.acquire(0)) - delay1 = pulse.Delay(7, self.backend_config.acquire(1)) + delay0 = pulse.Delay(5, channel=self.backend_config.acquire(0)) + delay1 = pulse.Delay(7, channel=self.backend_config.acquire(1)) sched0 = delay0 sched0 += self.schedule # includes ``Acquire`` instr @@ -1281,16 +1291,20 @@ def test_assemble_parametric(self): angle = [np.pi / 2, 0.6, 0, 0] sched = pulse.Schedule(name="test_parametric") sched += Play( - pulse.Gaussian(duration=25, sigma=4, amp=amp[0], angle=angle[0]), DriveChannel(0) + pulse.Gaussian(duration=25, sigma=4, amp=amp[0], angle=angle[0]), + channel=DriveChannel(0), + ) + sched += Play( + pulse.Drag(duration=25, amp=amp[1], angle=angle[1], sigma=7.8, beta=4), + channel=DriveChannel(1), ) sched += Play( - pulse.Drag(duration=25, amp=amp[1], angle=angle[1], sigma=7.8, beta=4), DriveChannel(1) + pulse.Constant(duration=25, amp=amp[2], angle=angle[2]), channel=DriveChannel(2) ) - sched += Play(pulse.Constant(duration=25, amp=amp[2], angle=angle[2]), DriveChannel(2)) sched += ( Play( pulse.GaussianSquare(duration=150, amp=amp[3], angle=angle[3], sigma=8, width=140), - MeasureChannel(0), + channel=MeasureChannel(0), ) << sched.duration ) @@ -1336,9 +1350,9 @@ def test_assemble_parametric_unsupported(self): """ sched = pulse.Schedule(name="test_parametric_to_sample_pulse") sched += Play( - pulse.Drag(duration=25, amp=0.5, angle=-0.3, sigma=7.8, beta=4), DriveChannel(1) + pulse.Drag(duration=25, amp=0.5, angle=-0.3, sigma=7.8, beta=4), channel=DriveChannel(1) ) - sched += Play(pulse.Constant(duration=25, amp=1), DriveChannel(2)) + sched += Play(pulse.Constant(duration=25, amp=1), channel=DriveChannel(2)) backend = FakeOpenPulse3Q() backend.configuration().parametric_pulses = ["something_extra"] @@ -1470,10 +1484,10 @@ def test_assemble_with_individual_discriminators(self): schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0), discriminator=disc_one), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two), + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1), discriminator=disc_two), ) qobj = assemble( @@ -1496,10 +1510,10 @@ def test_assemble_with_single_discriminators(self): schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0), discriminator=disc_one), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)), + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)), ) qobj = assemble( @@ -1521,9 +1535,13 @@ def test_assemble_with_unequal_discriminators(self): disc_two = Discriminator("disc_two", test_params=False) schedule = Schedule() - schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one) - schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two) - schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) + schedule += Acquire( + 5, channel=AcquireChannel(0), mem_slot=MemorySlot(0), discriminator=disc_one + ) + schedule += Acquire( + 5, channel=AcquireChannel(1), mem_slot=MemorySlot(1), discriminator=disc_two + ) + schedule += Acquire(5, channel=AcquireChannel(2), mem_slot=MemorySlot(2)) with self.assertRaises(QiskitError): assemble( @@ -1540,10 +1558,10 @@ def test_assemble_with_individual_kernels(self): schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0), kernel=disc_one), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two), + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1), kernel=disc_two), ) qobj = assemble( @@ -1566,10 +1584,10 @@ def test_assemble_with_single_kernels(self): schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0), kernel=disc_one), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)), + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)), ) qobj = assemble( @@ -1591,9 +1609,9 @@ def test_assemble_with_unequal_kernels(self): disc_two = Kernel("disc_two", test_params=False) schedule = Schedule() - schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), kernel=disc_one) - schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), kernel=disc_two) - schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) + schedule += Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0), kernel=disc_one) + schedule += Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1), kernel=disc_two) + schedule += Acquire(5, channel=AcquireChannel(2), mem_slot=MemorySlot(2)) with self.assertRaises(QiskitError): assemble( @@ -1605,17 +1623,17 @@ def test_assemble_with_unequal_kernels(self): def test_assemble_single_instruction(self): """Test assembling schedules, no lo config.""" - inst = pulse.Play(pulse.Constant(100, 1.0), pulse.DriveChannel(0)) + inst = pulse.Play(pulse.Constant(100, 1.0), channel=pulse.DriveChannel(0)) self.assertIsInstance(assemble(inst, self.backend), PulseQobj) def test_assemble_overlapping_time(self): """Test that assembly errors when qubits are measured in overlapping time.""" schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0)), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0)), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)) << 1, ) with self.assertRaises(QiskitError): assemble( @@ -1629,10 +1647,10 @@ def test_assemble_meas_map_vs_insts(self): """Test that assembly errors when the qubits are measured in overlapping time and qubits are not in the first meas_map list.""" schedule = Schedule() - schedule += Acquire(5, AcquireChannel(0), MemorySlot(0)) - schedule += Acquire(5, AcquireChannel(1), MemorySlot(1)) - schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) << 2 - schedule += Acquire(5, AcquireChannel(3), MemorySlot(3)) << 2 + schedule += Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) + schedule += Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)) + schedule += Acquire(5, channel=AcquireChannel(2), mem_slot=MemorySlot(2)) << 2 + schedule += Acquire(5, channel=AcquireChannel(3), mem_slot=MemorySlot(3)) << 2 with self.assertRaises(QiskitError): assemble( @@ -1647,10 +1665,10 @@ def test_assemble_non_overlapping_time_single_meas_map(self): time within the same measurement map list.""" schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0)), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0)), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)) << 5, + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)) << 5, ) qobj = assemble( schedule, @@ -1664,10 +1682,10 @@ def test_assemble_disjoint_time(self): """Test that assembly works when qubits are in disjoint meas map sets.""" schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(0), MemorySlot(0)), + Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0)), ) schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)) << 1, + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)) << 1, ) qobj = assemble( schedule, @@ -1682,13 +1700,13 @@ def test_assemble_valid_qubits(self): is measured.""" schedule = Schedule() schedule = schedule.append( - Acquire(5, AcquireChannel(1), MemorySlot(1)), + Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1)), ) schedule = schedule.append( - Acquire(5, AcquireChannel(2), MemorySlot(2)), + Acquire(5, channel=AcquireChannel(2), mem_slot=MemorySlot(2)), ) schedule = schedule.append( - Acquire(5, AcquireChannel(3), MemorySlot(3)), + Acquire(5, channel=AcquireChannel(3), mem_slot=MemorySlot(3)), ) qobj = assemble( schedule, @@ -1865,11 +1883,15 @@ def test_single_and_deprecated_acquire_styles(self): new_style_schedule = Schedule() acq_dur = 1200 for i in range(2): - new_style_schedule += Acquire(acq_dur, AcquireChannel(i), MemorySlot(i)) + new_style_schedule += Acquire( + acq_dur, channel=AcquireChannel(i), mem_slot=MemorySlot(i) + ) deprecated_style_schedule = Schedule() for i in range(2): - deprecated_style_schedule += Acquire(1200, AcquireChannel(i), MemorySlot(i)) + deprecated_style_schedule += Acquire( + 1200, channel=AcquireChannel(i), mem_slot=MemorySlot(i) + ) # The Qobj IDs will be different n_qobj = assemble(new_style_schedule, backend) diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index e575c021adc..1cd00811f8b 100644 --- a/test/python/compiler/test_disassembler.py +++ b/test/python/compiler/test_disassembler.py @@ -36,7 +36,7 @@ def _parametric_to_waveforms(schedule): for i, time_instruction_tuple in enumerate(schedule.instructions): time, instruction = time_instruction_tuple if not isinstance(instruction.pulse, pulse.library.Waveform): - new_inst = pulse.Play(instruction.pulse.get_waveform(), instruction.channel) + new_inst = pulse.Play(instruction.pulse.get_waveform(), channel=instruction.channel) instructions[i] = (time, new_inst) return tuple(instructions) @@ -407,8 +407,8 @@ def test_single_circuit_delay_calibrations(self): """Test that disassembler parses delay instruction back to delay gate.""" qc = QuantumCircuit(2) qc.append(Gate("test", 1, []), [0]) - test_sched = pulse.Delay(64, pulse.DriveChannel(0)) + pulse.Delay( - 160, pulse.DriveChannel(0) + test_sched = pulse.Delay(64, channel=pulse.DriveChannel(0)) + pulse.Delay( + 160, channel=pulse.DriveChannel(0) ) qc.add_calibration("test", [0], test_sched) diff --git a/test/python/primitives/test_primitive.py b/test/python/primitives/test_primitive.py index f0401e77144..9ece0a62ed8 100644 --- a/test/python/primitives/test_primitive.py +++ b/test/python/primitives/test_primitive.py @@ -137,7 +137,9 @@ def test_func(n): def test_with_scheduling(n): custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(160 * n, 0.1), pulse.DriveChannel(0)), inplace=True + 0, + pulse.Play(pulse.Constant(160 * n, 0.1), channel=pulse.DriveChannel(0)), + inplace=True, ) qc = QuantumCircuit(1) qc.x(0) diff --git a/test/python/pulse/test_block.py b/test/python/pulse/test_block.py index 3af2d0b510d..f7f2fcaefd0 100644 --- a/test/python/pulse/test_block.py +++ b/test/python/pulse/test_block.py @@ -57,36 +57,36 @@ class TestTransformation(BaseTestBlock): def test_left_alignment(self): """Test left alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.left_context) - block = block.append(pulse.Play(self.test_waveform0, self.d0)) - block = block.append(pulse.Play(self.test_waveform1, self.d1)) + block = block.append(pulse.Play(self.test_waveform0, channel=self.d0)) + block = block.append(pulse.Play(self.test_waveform1, channel=self.d1)) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, self.d1)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, channel=self.d1)) self.assertScheduleEqual(block, ref_sched) def test_right_alignment(self): """Test right alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.right_context) - block = block.append(pulse.Play(self.test_waveform0, self.d0)) - block = block.append(pulse.Play(self.test_waveform1, self.d1)) + block = block.append(pulse.Play(self.test_waveform0, channel=self.d0)) + block = block.append(pulse.Play(self.test_waveform1, channel=self.d1)) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, self.d1)) + ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, channel=self.d1)) self.assertScheduleEqual(block, ref_sched) def test_sequential_alignment(self): """Test sequential alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block = block.append(pulse.Play(self.test_waveform0, self.d0)) - block = block.append(pulse.Play(self.test_waveform1, self.d1)) + block = block.append(pulse.Play(self.test_waveform0, channel=self.d0)) + block = block.append(pulse.Play(self.test_waveform1, channel=self.d1)) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform1, self.d1)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform1, channel=self.d1)) self.assertScheduleEqual(block, ref_sched) @@ -94,13 +94,13 @@ def test_equispace_alignment(self): """Test equispace alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.equispaced_context) for _ in range(4): - block = block.append(pulse.Play(self.test_waveform0, self.d0)) + block = block.append(pulse.Play(self.test_waveform0, channel=self.d0)) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(300, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(600, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(900, pulse.Play(self.test_waveform0, self.d0)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(300, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(600, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(900, pulse.Play(self.test_waveform0, channel=self.d0)) self.assertScheduleEqual(block, ref_sched) @@ -108,33 +108,33 @@ def test_func_alignment(self): """Test func alignment context.""" block = pulse.ScheduleBlock(alignment_context=self.func_context) for _ in range(4): - block = block.append(pulse.Play(self.test_waveform0, self.d0)) + block = block.append(pulse.Play(self.test_waveform0, channel=self.d0)) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(50, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(200, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(650, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(800, pulse.Play(self.test_waveform0, self.d0)) + ref_sched = ref_sched.insert(50, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(200, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(650, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(800, pulse.Play(self.test_waveform0, channel=self.d0)) self.assertScheduleEqual(block, ref_sched) def test_nested_alignment(self): """Test nested block scheduling.""" block_sub = pulse.ScheduleBlock(alignment_context=self.right_context) - block_sub = block_sub.append(pulse.Play(self.test_waveform0, self.d0)) - block_sub = block_sub.append(pulse.Play(self.test_waveform1, self.d1)) + block_sub = block_sub.append(pulse.Play(self.test_waveform0, channel=self.d0)) + block_sub = block_sub.append(pulse.Play(self.test_waveform1, channel=self.d1)) block_main = pulse.ScheduleBlock(alignment_context=self.sequential_context) block_main = block_main.append(block_sub) - block_main = block_main.append(pulse.Delay(10, self.d0)) + block_main = block_main.append(pulse.Delay(10, channel=self.d0)) block_main = block_main.append(block_sub) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, self.d1)) - ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(200, pulse.Delay(10, self.d0)) - ref_sched = ref_sched.insert(210, pulse.Play(self.test_waveform1, self.d1)) - ref_sched = ref_sched.insert(310, pulse.Play(self.test_waveform0, self.d0)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, channel=self.d1)) + ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(200, pulse.Delay(10, channel=self.d0)) + ref_sched = ref_sched.insert(210, pulse.Play(self.test_waveform1, channel=self.d1)) + ref_sched = ref_sched.insert(310, pulse.Play(self.test_waveform0, channel=self.d0)) self.assertScheduleEqual(block_main, ref_sched) @@ -153,37 +153,37 @@ def setUp(self): super().setUp() self.test_blocks = [ - pulse.Play(self.test_waveform0, self.d0), - pulse.Play(self.test_waveform1, self.d1), - pulse.Delay(50, self.d0), - pulse.Play(self.test_waveform1, self.d0), + pulse.Play(self.test_waveform0, channel=self.d0), + pulse.Play(self.test_waveform1, channel=self.d1), + pulse.Delay(50, channel=self.d0), + pulse.Play(self.test_waveform1, channel=self.d0), ] def test_append_an_instruction_to_empty_block(self): """Test append instructions to an empty block.""" block = pulse.ScheduleBlock() - block = block.append(pulse.Play(self.test_waveform0, self.d0)) + block = block.append(pulse.Play(self.test_waveform0, channel=self.d0)) - self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, self.d0)) + self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, channel=self.d0)) def test_append_an_instruction_to_empty_block_sugar(self): """Test append instructions to an empty block with syntax sugar.""" block = pulse.ScheduleBlock() - block += pulse.Play(self.test_waveform0, self.d0) + block += pulse.Play(self.test_waveform0, channel=self.d0) - self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, self.d0)) + self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, channel=self.d0)) def test_append_an_instruction_to_empty_block_inplace(self): """Test append instructions to an empty block with inplace.""" block = pulse.ScheduleBlock() - block.append(pulse.Play(self.test_waveform0, self.d0), inplace=True) + block.append(pulse.Play(self.test_waveform0, channel=self.d0), inplace=True) - self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, self.d0)) + self.assertEqual(block.blocks[0], pulse.Play(self.test_waveform0, channel=self.d0)) def test_append_a_block_to_empty_block(self): """Test append another ScheduleBlock to empty block.""" block = pulse.ScheduleBlock() - block.append(pulse.Play(self.test_waveform0, self.d0), inplace=True) + block.append(pulse.Play(self.test_waveform0, channel=self.d0), inplace=True) block_main = pulse.ScheduleBlock() block_main = block_main.append(block) @@ -193,18 +193,18 @@ def test_append_a_block_to_empty_block(self): def test_append_an_instruction_to_block(self): """Test append instructions to a non-empty block.""" block = pulse.ScheduleBlock() - block = block.append(pulse.Delay(100, self.d0)) + block = block.append(pulse.Delay(100, channel=self.d0)) - block = block.append(pulse.Delay(100, self.d0)) + block = block.append(pulse.Delay(100, channel=self.d0)) self.assertEqual(len(block.blocks), 2) def test_append_an_instruction_to_block_inplace(self): """Test append instructions to a non-empty block with inplace.""" block = pulse.ScheduleBlock() - block = block.append(pulse.Delay(100, self.d0)) + block = block.append(pulse.Delay(100, channel=self.d0)) - block.append(pulse.Delay(100, self.d0), inplace=True) + block.append(pulse.Delay(100, channel=self.d0), inplace=True) self.assertEqual(len(block.blocks), 2) @@ -246,7 +246,7 @@ def test_cannot_append_schedule(self): block = pulse.ScheduleBlock() sched = pulse.Schedule() - sched += pulse.Delay(10, self.d0) + sched += pulse.Delay(10, channel=self.d0) with self.assertRaises(PulseError): block.append(sched) @@ -257,8 +257,8 @@ def test_replace(self): for inst in self.test_blocks: block.append(inst) - replaced = pulse.Play(pulse.Constant(300, 0.1), self.d1) - target = pulse.Delay(50, self.d0) + replaced = pulse.Play(pulse.Constant(300, 0.1), channel=self.d1) + target = pulse.Delay(50, channel=self.d0) block_replaced = block.replace(target, replaced, inplace=False) @@ -266,10 +266,10 @@ def test_replace(self): self.assertListEqual(list(block.blocks), self.test_blocks) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, self.d1)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, channel=self.d1)) ref_sched = ref_sched.insert(200, replaced) - ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform1, self.d0)) + ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform1, channel=self.d0)) self.assertScheduleEqual(block_replaced, ref_sched) @@ -279,44 +279,44 @@ def test_replace_inplace(self): for inst in self.test_blocks: block.append(inst) - replaced = pulse.Play(pulse.Constant(300, 0.1), self.d1) - target = pulse.Delay(50, self.d0) + replaced = pulse.Play(pulse.Constant(300, 0.1), channel=self.d1) + target = pulse.Delay(50, channel=self.d0) block.replace(target, replaced, inplace=True) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, self.d0)) - ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, self.d1)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform0, channel=self.d0)) + ref_sched = ref_sched.insert(0, pulse.Play(self.test_waveform1, channel=self.d1)) ref_sched = ref_sched.insert(200, replaced) - ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform1, self.d0)) + ref_sched = ref_sched.insert(100, pulse.Play(self.test_waveform1, channel=self.d0)) self.assertScheduleEqual(block, ref_sched) def test_replace_block_by_instruction(self): """Test replacing block with instruction.""" sub_block1 = pulse.ScheduleBlock() - sub_block1 = sub_block1.append(pulse.Delay(50, self.d0)) - sub_block1 = sub_block1.append(pulse.Play(self.test_waveform0, self.d0)) + sub_block1 = sub_block1.append(pulse.Delay(50, channel=self.d0)) + sub_block1 = sub_block1.append(pulse.Play(self.test_waveform0, channel=self.d0)) sub_block2 = pulse.ScheduleBlock() - sub_block2 = sub_block2.append(pulse.Delay(50, self.d0)) - sub_block2 = sub_block2.append(pulse.Play(self.test_waveform1, self.d1)) + sub_block2 = sub_block2.append(pulse.Delay(50, channel=self.d0)) + sub_block2 = sub_block2.append(pulse.Play(self.test_waveform1, channel=self.d1)) main_block = pulse.ScheduleBlock() - main_block = main_block.append(pulse.Delay(50, self.d0)) - main_block = main_block.append(pulse.Play(self.test_waveform0, self.d0)) + main_block = main_block.append(pulse.Delay(50, channel=self.d0)) + main_block = main_block.append(pulse.Play(self.test_waveform0, channel=self.d0)) main_block = main_block.append(sub_block1) main_block = main_block.append(sub_block2) - main_block = main_block.append(pulse.Play(self.test_waveform0, self.d1)) + main_block = main_block.append(pulse.Play(self.test_waveform0, channel=self.d1)) - replaced = main_block.replace(sub_block1, pulse.Delay(100, self.d0)) + replaced = main_block.replace(sub_block1, pulse.Delay(100, channel=self.d0)) ref_blocks = [ - pulse.Delay(50, self.d0), - pulse.Play(self.test_waveform0, self.d0), - pulse.Delay(100, self.d0), + pulse.Delay(50, channel=self.d0), + pulse.Play(self.test_waveform0, channel=self.d0), + pulse.Delay(100, channel=self.d0), sub_block2, - pulse.Play(self.test_waveform0, self.d1), + pulse.Play(self.test_waveform0, channel=self.d1), ] self.assertListEqual(list(replaced.blocks), ref_blocks) @@ -324,28 +324,28 @@ def test_replace_block_by_instruction(self): def test_replace_instruction_by_block(self): """Test replacing instruction with block.""" sub_block1 = pulse.ScheduleBlock() - sub_block1 = sub_block1.append(pulse.Delay(50, self.d0)) - sub_block1 = sub_block1.append(pulse.Play(self.test_waveform0, self.d0)) + sub_block1 = sub_block1.append(pulse.Delay(50, channel=self.d0)) + sub_block1 = sub_block1.append(pulse.Play(self.test_waveform0, channel=self.d0)) sub_block2 = pulse.ScheduleBlock() - sub_block2 = sub_block2.append(pulse.Delay(50, self.d0)) - sub_block2 = sub_block2.append(pulse.Play(self.test_waveform1, self.d1)) + sub_block2 = sub_block2.append(pulse.Delay(50, channel=self.d0)) + sub_block2 = sub_block2.append(pulse.Play(self.test_waveform1, channel=self.d1)) main_block = pulse.ScheduleBlock() - main_block = main_block.append(pulse.Delay(50, self.d0)) - main_block = main_block.append(pulse.Play(self.test_waveform0, self.d0)) - main_block = main_block.append(pulse.Delay(100, self.d0)) + main_block = main_block.append(pulse.Delay(50, channel=self.d0)) + main_block = main_block.append(pulse.Play(self.test_waveform0, channel=self.d0)) + main_block = main_block.append(pulse.Delay(100, channel=self.d0)) main_block = main_block.append(sub_block2) - main_block = main_block.append(pulse.Play(self.test_waveform0, self.d1)) + main_block = main_block.append(pulse.Play(self.test_waveform0, channel=self.d1)) - replaced = main_block.replace(pulse.Delay(100, self.d0), sub_block1) + replaced = main_block.replace(pulse.Delay(100, channel=self.d0), sub_block1) ref_blocks = [ - pulse.Delay(50, self.d0), - pulse.Play(self.test_waveform0, self.d0), + pulse.Delay(50, channel=self.d0), + pulse.Play(self.test_waveform0, channel=self.d0), sub_block1, sub_block2, - pulse.Play(self.test_waveform0, self.d1), + pulse.Play(self.test_waveform0, channel=self.d1), ] self.assertListEqual(list(replaced.blocks), ref_blocks) @@ -356,7 +356,7 @@ def test_len(self): self.assertEqual(len(block), 0) for j in range(1, 10): - block = block.append(pulse.Delay(10, self.d0)) + block = block.append(pulse.Delay(10, channel=self.d0)) self.assertEqual(len(block), j) def test_inherit_from(self): @@ -381,20 +381,20 @@ class TestBlockEquality(BaseTestBlock): def test_different_channels(self): """Test equality is False if different channels.""" block1 = pulse.ScheduleBlock() - block1 += pulse.Delay(10, self.d0) + block1 += pulse.Delay(10, channel=self.d0) block2 = pulse.ScheduleBlock() - block2 += pulse.Delay(10, self.d1) + block2 += pulse.Delay(10, channel=self.d1) self.assertNotEqual(block1, block2) def test_different_transform(self): """Test equality is False if different transforms.""" block1 = pulse.ScheduleBlock(alignment_context=self.left_context) - block1 += pulse.Delay(10, self.d0) + block1 += pulse.Delay(10, channel=self.d0) block2 = pulse.ScheduleBlock(alignment_context=self.right_context) - block2 += pulse.Delay(10, self.d0) + block2 += pulse.Delay(10, channel=self.d0) self.assertNotEqual(block1, block2) @@ -404,70 +404,70 @@ def test_different_transform_opts(self): context2 = transforms.AlignEquispaced(duration=500) block1 = pulse.ScheduleBlock(alignment_context=context1) - block1 += pulse.Delay(10, self.d0) + block1 += pulse.Delay(10, channel=self.d0) block2 = pulse.ScheduleBlock(alignment_context=context2) - block2 += pulse.Delay(10, self.d0) + block2 += pulse.Delay(10, channel=self.d0) self.assertNotEqual(block1, block2) def test_instruction_out_of_order_left(self): """Test equality is True if two blocks have instructions in different order.""" block1 = pulse.ScheduleBlock(alignment_context=self.left_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.left_context) - block2 += pulse.Play(self.test_waveform0, self.d1) - block2 += pulse.Play(self.test_waveform0, self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) self.assertEqual(block1, block2) def test_instruction_in_order_left(self): """Test equality is True if two blocks have instructions in same order.""" block1 = pulse.ScheduleBlock(alignment_context=self.left_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.left_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) self.assertEqual(block1, block2) def test_instruction_out_of_order_right(self): """Test equality is True if two blocks have instructions in different order.""" block1 = pulse.ScheduleBlock(alignment_context=self.right_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.right_context) - block2 += pulse.Play(self.test_waveform0, self.d1) - block2 += pulse.Play(self.test_waveform0, self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) self.assertEqual(block1, block2) def test_instruction_in_order_right(self): """Test equality is True if two blocks have instructions in same order.""" block1 = pulse.ScheduleBlock(alignment_context=self.right_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.right_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) self.assertEqual(block1, block2) def test_instruction_out_of_order_sequential(self): """Test equality is False if two blocks have instructions in different order.""" block1 = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block2 += pulse.Play(self.test_waveform0, self.d1) - block2 += pulse.Play(self.test_waveform0, self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) self.assertNotEqual(block1, block2) @@ -478,100 +478,100 @@ def test_instruction_out_of_order_sequential_more(self): https://github.com/Qiskit/qiskit-terra/pull/8005#discussion_r966191018 """ block1 = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) - block2 += pulse.Play(self.test_waveform0, self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) self.assertNotEqual(block1, block2) def test_instruction_in_order_sequential(self): """Test equality is True if two blocks have instructions in same order.""" block1 = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.sequential_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) self.assertEqual(block1, block2) def test_instruction_out_of_order_equispaced(self): """Test equality is False if two blocks have instructions in different order.""" block1 = pulse.ScheduleBlock(alignment_context=self.equispaced_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.equispaced_context) - block2 += pulse.Play(self.test_waveform0, self.d1) - block2 += pulse.Play(self.test_waveform0, self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) self.assertNotEqual(block1, block2) def test_instruction_in_order_equispaced(self): """Test equality is True if two blocks have instructions in same order.""" block1 = pulse.ScheduleBlock(alignment_context=self.equispaced_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.equispaced_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) self.assertEqual(block1, block2) def test_instruction_out_of_order_func(self): """Test equality is False if two blocks have instructions in different order.""" block1 = pulse.ScheduleBlock(alignment_context=self.func_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.func_context) - block2 += pulse.Play(self.test_waveform0, self.d1) - block2 += pulse.Play(self.test_waveform0, self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) self.assertNotEqual(block1, block2) def test_instruction_in_order_func(self): """Test equality is True if two blocks have instructions in same order.""" block1 = pulse.ScheduleBlock(alignment_context=self.func_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform0, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform0, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.func_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) self.assertEqual(block1, block2) def test_instrution_in_oder_but_different_node(self): """Test equality is False if two blocks have different instructions.""" block1 = pulse.ScheduleBlock(alignment_context=self.left_context) - block1 += pulse.Play(self.test_waveform0, self.d0) - block1 += pulse.Play(self.test_waveform1, self.d1) + block1 += pulse.Play(self.test_waveform0, channel=self.d0) + block1 += pulse.Play(self.test_waveform1, channel=self.d1) block2 = pulse.ScheduleBlock(alignment_context=self.left_context) - block2 += pulse.Play(self.test_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, self.d1) + block2 += pulse.Play(self.test_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=self.d1) self.assertNotEqual(block1, block2) def test_instruction_out_of_order_complex_equal(self): """Test complex schedule equality can be correctly evaluated.""" block1_a = pulse.ScheduleBlock(alignment_context=self.left_context) - block1_a += pulse.Delay(10, self.d0) - block1_a += pulse.Play(self.test_waveform1, self.d1) - block1_a += pulse.Play(self.test_waveform0, self.d0) + block1_a += pulse.Delay(10, channel=self.d0) + block1_a += pulse.Play(self.test_waveform1, channel=self.d1) + block1_a += pulse.Play(self.test_waveform0, channel=self.d0) block1_b = pulse.ScheduleBlock(alignment_context=self.left_context) - block1_b += pulse.Play(self.test_waveform1, self.d1) - block1_b += pulse.Delay(10, self.d0) - block1_b += pulse.Play(self.test_waveform0, self.d0) + block1_b += pulse.Play(self.test_waveform1, channel=self.d1) + block1_b += pulse.Delay(10, channel=self.d0) + block1_b += pulse.Play(self.test_waveform0, channel=self.d0) block2_a = pulse.ScheduleBlock(alignment_context=self.right_context) block2_a += block1_a @@ -588,14 +588,14 @@ def test_instruction_out_of_order_complex_equal(self): def test_instruction_out_of_order_complex_not_equal(self): """Test complex schedule equality can be correctly evaluated.""" block1_a = pulse.ScheduleBlock(alignment_context=self.left_context) - block1_a += pulse.Play(self.test_waveform0, self.d0) - block1_a += pulse.Play(self.test_waveform1, self.d1) - block1_a += pulse.Delay(10, self.d0) + block1_a += pulse.Play(self.test_waveform0, channel=self.d0) + block1_a += pulse.Play(self.test_waveform1, channel=self.d1) + block1_a += pulse.Delay(10, channel=self.d0) block1_b = pulse.ScheduleBlock(alignment_context=self.left_context) - block1_b += pulse.Play(self.test_waveform1, self.d1) - block1_b += pulse.Delay(10, self.d0) - block1_b += pulse.Play(self.test_waveform0, self.d0) + block1_b += pulse.Play(self.test_waveform1, channel=self.d1) + block1_b += pulse.Delay(10, channel=self.d0) + block1_b += pulse.Play(self.test_waveform0, channel=self.d0) block2_a = pulse.ScheduleBlock(alignment_context=self.right_context) block2_a += block1_a @@ -627,7 +627,7 @@ def setUp(self): def test_report_parameter_assignment(self): """Test duration assignment check.""" block = pulse.ScheduleBlock() - block += pulse.Play(self.test_par_waveform0, self.d0) + block += pulse.Play(self.test_par_waveform0, channel=self.d0) # check parameter evaluation mechanism self.assertTrue(block.is_parameterized()) @@ -641,7 +641,7 @@ def test_report_parameter_assignment(self): def test_cannot_get_duration_if_not_assigned(self): """Test raise error when duration is not assigned.""" block = pulse.ScheduleBlock() - block += pulse.Play(self.test_par_waveform0, self.d0) + block += pulse.Play(self.test_par_waveform0, channel=self.d0) with self.assertRaises(PulseError): # pylint: disable=pointless-statement @@ -650,8 +650,8 @@ def test_cannot_get_duration_if_not_assigned(self): def test_get_assigend_duration(self): """Test duration is correctly evaluated.""" block = pulse.ScheduleBlock() - block += pulse.Play(self.test_par_waveform0, self.d0) - block += pulse.Play(self.test_waveform0, self.d0) + block += pulse.Play(self.test_par_waveform0, channel=self.d0) + block += pulse.Play(self.test_waveform0, channel=self.d0) block = block.assign_parameters({self.dur0: 300}) @@ -662,12 +662,12 @@ def test_equality_of_parametrized_channels(self): par_ch = circuit.Parameter("ch") block1 = pulse.ScheduleBlock(alignment_context=self.left_context) - block1 += pulse.Play(self.test_waveform0, pulse.DriveChannel(par_ch)) - block1 += pulse.Play(self.test_par_waveform0, self.d0) + block1 += pulse.Play(self.test_waveform0, channel=pulse.DriveChannel(par_ch)) + block1 += pulse.Play(self.test_par_waveform0, channel=self.d0) block2 = pulse.ScheduleBlock(alignment_context=self.left_context) - block2 += pulse.Play(self.test_par_waveform0, self.d0) - block2 += pulse.Play(self.test_waveform0, pulse.DriveChannel(par_ch)) + block2 += pulse.Play(self.test_par_waveform0, channel=self.d0) + block2 += pulse.Play(self.test_waveform0, channel=pulse.DriveChannel(par_ch)) self.assertEqual(block1, block2) @@ -678,13 +678,13 @@ def test_equality_of_parametrized_channels(self): def test_replace_parametrized_instruction(self): """Test parametrized instruction can updated with parameter table.""" block = pulse.ScheduleBlock() - block += pulse.Play(self.test_par_waveform0, self.d0) - block += pulse.Delay(100, self.d0) - block += pulse.Play(self.test_waveform0, self.d0) + block += pulse.Play(self.test_par_waveform0, channel=self.d0) + block += pulse.Delay(100, channel=self.d0) + block += pulse.Play(self.test_waveform0, channel=self.d0) replaced = block.replace( - pulse.Play(self.test_par_waveform0, self.d0), - pulse.Play(self.test_par_waveform1, self.d0), + pulse.Play(self.test_par_waveform0, channel=self.d0), + pulse.Play(self.test_par_waveform1, channel=self.d0), ) self.assertTrue(replaced.is_parameterized()) @@ -698,10 +698,10 @@ def test_parametrized_context(self): param_context = transforms.AlignEquispaced(duration=duration) block = pulse.ScheduleBlock(alignment_context=param_context) - block += pulse.Delay(10, self.d0) - block += pulse.Delay(10, self.d0) - block += pulse.Delay(10, self.d0) - block += pulse.Delay(10, self.d0) + block += pulse.Delay(10, channel=self.d0) + block += pulse.Delay(10, channel=self.d0) + block += pulse.Delay(10, channel=self.d0) + block += pulse.Delay(10, channel=self.d0) self.assertTrue(block.is_parameterized()) self.assertFalse(block.is_schedulable()) @@ -710,10 +710,10 @@ def test_parametrized_context(self): self.assertTrue(block.is_schedulable()) ref_sched = pulse.Schedule() - ref_sched = ref_sched.insert(0, pulse.Delay(10, self.d0)) - ref_sched = ref_sched.insert(30, pulse.Delay(10, self.d0)) - ref_sched = ref_sched.insert(60, pulse.Delay(10, self.d0)) - ref_sched = ref_sched.insert(90, pulse.Delay(10, self.d0)) + ref_sched = ref_sched.insert(0, pulse.Delay(10, channel=self.d0)) + ref_sched = ref_sched.insert(30, pulse.Delay(10, channel=self.d0)) + ref_sched = ref_sched.insert(60, pulse.Delay(10, channel=self.d0)) + ref_sched = ref_sched.insert(90, pulse.Delay(10, channel=self.d0)) self.assertScheduleEqual(block, ref_sched) diff --git a/test/python/pulse/test_builder.py b/test/python/pulse/test_builder.py index 6ec5089760f..b723af7ecb8 100644 --- a/test/python/pulse/test_builder.py +++ b/test/python/pulse/test_builder.py @@ -123,10 +123,10 @@ def test_align_sequential(self): reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(8, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(8, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(3, instructions.Delay(5, d1), inplace=True) + reference.insert(3, instructions.Delay(5, channel=d1), inplace=True) self.assertScheduleEqual(schedule, reference) @@ -146,12 +146,12 @@ def test_align_left(self): reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(3, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(3, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(3, instructions.Delay(5, d1), inplace=True) + reference.insert(3, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(0, instructions.Delay(11, d2), inplace=True) + reference.insert(0, instructions.Delay(11, channel=d2), inplace=True) self.assertScheduleEqual(schedule, reference) @@ -171,12 +171,12 @@ def test_align_right(self): reference = pulse.Schedule() # d0 - reference.insert(8, instructions.Delay(3, d0), inplace=True) - reference.insert(11, instructions.Delay(13, d0), inplace=True) + reference.insert(8, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(11, instructions.Delay(13, channel=d0), inplace=True) # d1 - reference.insert(19, instructions.Delay(5, d1), inplace=True) + reference.insert(19, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(0, instructions.Delay(11, d2), inplace=True) + reference.insert(0, instructions.Delay(11, channel=d2), inplace=True) self.assertScheduleEqual(schedule, reference) @@ -189,9 +189,9 @@ def test_phase_offset(self): pulse.delay(10, d0) reference = pulse.Schedule() - reference += instructions.ShiftPhase(3.14, d0) - reference += instructions.Delay(10, d0) - reference += instructions.ShiftPhase(-3.14, d0) + reference += instructions.ShiftPhase(3.14, channel=d0) + reference += instructions.Delay(10, channel=d0) + reference += instructions.ShiftPhase(-3.14, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -204,9 +204,9 @@ def test_frequency_offset(self): pulse.delay(10, d0) reference = pulse.Schedule() - reference += instructions.ShiftFrequency(1e9, d0) - reference += instructions.Delay(10, d0) - reference += instructions.ShiftFrequency(-1e9, d0) + reference += instructions.ShiftFrequency(1e9, channel=d0) + reference += instructions.Delay(10, channel=d0) + reference += instructions.ShiftFrequency(-1e9, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -220,12 +220,12 @@ def test_phase_compensated_frequency_offset(self): pulse.delay(10, d0) reference = pulse.Schedule() - reference += instructions.ShiftFrequency(1e9, d0) - reference += instructions.Delay(10, d0) + reference += instructions.ShiftFrequency(1e9, channel=d0) + reference += instructions.Delay(10, channel=d0) reference += instructions.ShiftPhase( - -2 * np.pi * ((1e9 * 10 * self.configuration.dt) % 1), d0 + -2 * np.pi * ((1e9 * 10 * self.configuration.dt) % 1), channel=d0 ) - reference += instructions.ShiftFrequency(-1e9, d0) + reference += instructions.ShiftFrequency(-1e9, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -265,7 +265,7 @@ def test_delay(self): pulse.delay(10, d0) reference = pulse.Schedule() - reference += instructions.Delay(10, d0) + reference += instructions.Delay(10, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -278,7 +278,7 @@ def test_play_parametric_pulse(self): pulse.play(test_pulse, d0) reference = pulse.Schedule() - reference += instructions.Play(test_pulse, d0) + reference += instructions.Play(test_pulse, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -291,7 +291,7 @@ def test_play_sample_pulse(self): pulse.play(test_pulse, d0) reference = pulse.Schedule() - reference += instructions.Play(test_pulse, d0) + reference += instructions.Play(test_pulse, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -305,7 +305,7 @@ def test_play_array_pulse(self): reference = pulse.Schedule() test_pulse = pulse.Waveform(test_array) - reference += instructions.Play(test_pulse, d0) + reference += instructions.Play(test_pulse, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -328,7 +328,7 @@ def test_acquire_memory_slot(self): pulse.acquire(10, acquire0, mem0) reference = pulse.Schedule() - reference += pulse.Acquire(10, acquire0, mem_slot=mem0) + reference += pulse.Acquire(10, channel=acquire0, mem_slot=mem0) self.assertScheduleEqual(schedule, reference) @@ -341,7 +341,7 @@ def test_acquire_register_slot(self): pulse.acquire(10, acquire0, reg0) reference = pulse.Schedule() - reference += pulse.Acquire(10, acquire0, reg_slot=reg0) + reference += pulse.Acquire(10, channel=acquire0, reg_slot=reg0) self.assertScheduleEqual(schedule, reference) @@ -354,7 +354,7 @@ def test_acquire_qubit(self): pulse.acquire(10, 0, mem0) reference = pulse.Schedule() - reference += pulse.Acquire(10, acquire0, mem_slot=mem0) + reference += pulse.Acquire(10, channel=acquire0, mem_slot=mem0) self.assertScheduleEqual(schedule, reference) @@ -381,7 +381,7 @@ def test_set_frequency(self): pulse.set_frequency(1e9, d0) reference = pulse.Schedule() - reference += instructions.SetFrequency(1e9, d0) + reference += instructions.SetFrequency(1e9, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -393,7 +393,7 @@ def test_shift_frequency(self): pulse.shift_frequency(0.1e9, d0) reference = pulse.Schedule() - reference += instructions.ShiftFrequency(0.1e9, d0) + reference += instructions.ShiftFrequency(0.1e9, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -405,7 +405,7 @@ def test_set_phase(self): pulse.set_phase(3.14, d0) reference = pulse.Schedule() - reference += instructions.SetPhase(3.14, d0) + reference += instructions.SetPhase(3.14, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -417,7 +417,7 @@ def test_shift_phase(self): pulse.shift_phase(3.14, d0) reference = pulse.Schedule() - reference += instructions.ShiftPhase(3.14, d0) + reference += instructions.ShiftPhase(3.14, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -452,12 +452,12 @@ def test_barrier_with_align_right(self): reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(7, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(7, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(9, instructions.Delay(5, d1), inplace=True) + reference.insert(9, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(3, instructions.Delay(11, d2), inplace=True) + reference.insert(3, instructions.Delay(11, channel=d2), inplace=True) self.assertScheduleEqual(schedule, reference) @@ -478,12 +478,12 @@ def test_barrier_with_align_left(self): reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(3, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(3, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(3, instructions.Delay(5, d1), inplace=True) + reference.insert(3, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(3, instructions.Delay(11, d2), inplace=True) + reference.insert(3, instructions.Delay(11, channel=d2), inplace=True) self.assertScheduleEqual(schedule, reference) @@ -525,7 +525,7 @@ def test_append_schedule(self): """Test appending a schedule to the active builder.""" d0 = pulse.DriveChannel(0) reference = pulse.Schedule() - reference += instructions.Delay(10, d0) + reference += instructions.Delay(10, channel=d0) with pulse.build() as schedule: builder.call(reference) @@ -535,7 +535,7 @@ def test_append_schedule(self): def test_append_instruction(self): """Test appending an instruction to the active builder.""" d0 = pulse.DriveChannel(0) - instruction = instructions.Delay(10, d0) + instruction = instructions.Delay(10, channel=d0) with pulse.build() as schedule: builder.append_instruction(instruction) @@ -624,8 +624,8 @@ def test(): self.assertEqual(output, 0.5 * 2) reference = pulse.Schedule() - reference += pulse.Play(pulse.Constant(100, 1.0), pulse.DriveChannel(0)) - reference += pulse.Play(pulse.Gaussian(100, 0.5, 20), pulse.DriveChannel(0)) + reference += pulse.Play(pulse.Constant(100, 1.0), channel=pulse.DriveChannel(0)) + reference += pulse.Play(pulse.Gaussian(100, 0.5, 20), channel=pulse.DriveChannel(0)) self.assertScheduleEqual(schedule, reference) @@ -688,11 +688,11 @@ def test_delay_qubit(self): u1 = pulse.ControlChannel(1) reference = pulse.Schedule() - reference += instructions.Delay(10, d0) - reference += instructions.Delay(10, m0) - reference += instructions.Delay(10, a0) - reference += instructions.Delay(10, u0) - reference += instructions.Delay(10, u1) + reference += instructions.Delay(10, channel=d0) + reference += instructions.Delay(10, channel=m0) + reference += instructions.Delay(10, channel=a0) + reference += instructions.Delay(10, channel=u0) + reference += instructions.Delay(10, channel=u1) self.assertScheduleEqual(schedule, reference) @@ -711,14 +711,14 @@ def test_delay_qubits(self): u1 = pulse.ControlChannel(1) reference = pulse.Schedule() - reference += instructions.Delay(10, d0) - reference += instructions.Delay(10, d1) - reference += instructions.Delay(10, m0) - reference += instructions.Delay(10, m1) - reference += instructions.Delay(10, a0) - reference += instructions.Delay(10, a1) - reference += instructions.Delay(10, u0) - reference += instructions.Delay(10, u1) + reference += instructions.Delay(10, channel=d0) + reference += instructions.Delay(10, channel=d1) + reference += instructions.Delay(10, channel=m0) + reference += instructions.Delay(10, channel=m1) + reference += instructions.Delay(10, channel=a0) + reference += instructions.Delay(10, channel=a1) + reference += instructions.Delay(10, channel=u0) + reference += instructions.Delay(10, channel=u1) self.assertScheduleEqual(schedule, reference) @@ -765,18 +765,18 @@ def get_sched(qubit_idx: [int], backend): # sequential context sequential_reference = pulse.Schedule() - sequential_reference += instructions.Delay(delay_dur, d0) + sequential_reference += instructions.Delay(delay_dur, channel=d0) sequential_reference.insert(delay_dur, single_u2_sched, inplace=True) # align right align_right_reference = pulse.Schedule() - align_right_reference += pulse.Play(library.Constant(long_dur, 0.1), d2) + align_right_reference += pulse.Play(library.Constant(long_dur, 0.1), channel=d2) align_right_reference.insert( long_dur - single_u2_sched.duration, single_u2_sched, inplace=True ) align_right_reference.insert( long_dur - single_u2_sched.duration - short_dur, - pulse.Play(library.Constant(short_dur, 0.1), d1), + pulse.Play(library.Constant(short_dur, 0.1), channel=d1), inplace=True, ) @@ -813,8 +813,8 @@ def test_call(self): d1 = pulse.DriveChannel(1) reference = pulse.Schedule() - reference = reference.insert(10, instructions.Delay(10, d0)) - reference += instructions.Delay(20, d1) + reference = reference.insert(10, instructions.Delay(10, channel=d0)) + reference += instructions.Delay(20, channel=d1) ref_sched = pulse.Schedule() ref_sched += reference @@ -837,8 +837,8 @@ def test_subroutine_not_transformed(self): d1 = pulse.DriveChannel(1) subprogram = pulse.Schedule() - subprogram.insert(0, pulse.Delay(30, d0), inplace=True) - subprogram.insert(10, pulse.Delay(10, d1), inplace=True) + subprogram.insert(0, pulse.Delay(30, channel=d0), inplace=True) + subprogram.insert(10, pulse.Delay(10, channel=d1), inplace=True) with pulse.build() as target: with pulse.align_right(): @@ -846,9 +846,9 @@ def test_subroutine_not_transformed(self): pulse.call(subprogram) reference = pulse.Schedule() - reference.insert(0, pulse.Delay(10, d1), inplace=True) - reference.insert(10, pulse.Delay(30, d0), inplace=True) - reference.insert(20, pulse.Delay(10, d1), inplace=True) + reference.insert(0, pulse.Delay(10, channel=d1), inplace=True) + reference.insert(10, pulse.Delay(30, channel=d0), inplace=True) + reference.insert(20, pulse.Delay(10, channel=d1), inplace=True) self.assertScheduleEqual(target, reference) diff --git a/test/python/pulse/test_builder_v2.py b/test/python/pulse/test_builder_v2.py index 843c8a8447f..5ca935038a6 100644 --- a/test/python/pulse/test_builder_v2.py +++ b/test/python/pulse/test_builder_v2.py @@ -57,12 +57,12 @@ def test_phase_compensated_frequency_offset(self): pulse.delay(10, d0) reference = pulse.Schedule() - reference += instructions.ShiftFrequency(1e9, d0) - reference += instructions.Delay(10, d0) + reference += instructions.ShiftFrequency(1e9, channel=d0) + reference += instructions.Delay(10, channel=d0) reference += instructions.ShiftPhase( - -2 * np.pi * ((1e9 * 10 * self.backend.target.dt) % 1), d0 + -2 * np.pi * ((1e9 * 10 * self.backend.target.dt) % 1), channel=d0 ) - reference += instructions.ShiftFrequency(-1e9, d0) + reference += instructions.ShiftFrequency(-1e9, channel=d0) self.assertScheduleEqual(schedule, reference) @@ -211,8 +211,8 @@ def test(): self.assertEqual(output, 0.5 * 2) reference = pulse.Schedule() - reference += pulse.Play(pulse.Constant(100, 1.0), pulse.DriveChannel(0)) - reference += pulse.Play(pulse.Gaussian(100, 0.5, 20), pulse.DriveChannel(0)) + reference += pulse.Play(pulse.Constant(100, 1.0), channel=pulse.DriveChannel(0)) + reference += pulse.Play(pulse.Gaussian(100, 0.5, 20), channel=pulse.DriveChannel(0)) self.assertScheduleEqual(schedule, reference) @@ -262,11 +262,11 @@ def test_delay_qubit(self): u1 = pulse.ControlChannel(1) reference = pulse.Schedule() - reference += instructions.Delay(10, d0) - reference += instructions.Delay(10, m0) - reference += instructions.Delay(10, a0) - reference += instructions.Delay(10, u0) - reference += instructions.Delay(10, u1) + reference += instructions.Delay(10, channel=d0) + reference += instructions.Delay(10, channel=m0) + reference += instructions.Delay(10, channel=a0) + reference += instructions.Delay(10, channel=u0) + reference += instructions.Delay(10, channel=u1) self.assertScheduleEqual(schedule, reference) @@ -289,17 +289,17 @@ def test_delay_qubits(self): u8 = pulse.ControlChannel(8) reference = pulse.Schedule() - reference += instructions.Delay(10, d0) - reference += instructions.Delay(10, d1) - reference += instructions.Delay(10, m0) - reference += instructions.Delay(10, m1) - reference += instructions.Delay(10, a0) - reference += instructions.Delay(10, a1) - reference += instructions.Delay(10, u0) - reference += instructions.Delay(10, u1) - reference += instructions.Delay(10, u2) - reference += instructions.Delay(10, u3) - reference += instructions.Delay(10, u4) - reference += instructions.Delay(10, u8) + reference += instructions.Delay(10, channel=d0) + reference += instructions.Delay(10, channel=d1) + reference += instructions.Delay(10, channel=m0) + reference += instructions.Delay(10, channel=m1) + reference += instructions.Delay(10, channel=a0) + reference += instructions.Delay(10, channel=a1) + reference += instructions.Delay(10, channel=u0) + reference += instructions.Delay(10, channel=u1) + reference += instructions.Delay(10, channel=u2) + reference += instructions.Delay(10, channel=u3) + reference += instructions.Delay(10, channel=u4) + reference += instructions.Delay(10, channel=u8) self.assertScheduleEqual(schedule, reference) diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index 20e6773d2fd..3bead2a2ae2 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -43,7 +43,7 @@ def test_add_schedule(self): program = Schedule() program.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -62,7 +62,7 @@ def test_add_block(self): """Basic test pulse Schedule format.""" program = ScheduleBlock() program.append( - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -84,7 +84,7 @@ def test_parameterized_schedule(self): program = ScheduleBlock() program.append( - Play(Constant(duration=param1, amp=param2, angle=0.0), DriveChannel(0)), + Play(Constant(duration=param1, amp=param2, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -110,15 +110,15 @@ def test_parameterized_schedule_with_user_args(self): program = ScheduleBlock() program.append( - Play(Constant(duration=10, amp=phi, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=phi, angle=0.0), channel=DriveChannel(0)), inplace=True, ) program.append( - Play(Constant(duration=10, amp=theta, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=theta, angle=0.0), channel=DriveChannel(0)), inplace=True, ) program.append( - Play(Constant(duration=10, amp=lam, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=lam, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -143,7 +143,7 @@ def test_parameterized_schedule_with_wrong_signature(self): program = ScheduleBlock() program.append( - Play(Constant(duration=10, amp=param1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=param1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -157,14 +157,14 @@ def test_equality(self): program1 = Schedule() program1.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) program2 = Schedule() program2.insert( 0, - Play(Constant(duration=10, amp=0.2, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.2, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -189,7 +189,7 @@ def test_add_callable(self): program = Schedule() program.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) @@ -215,13 +215,16 @@ def factory(var1, var2): if var1 > 0: program.insert( 0, - Play(Constant(duration=var2, amp=var1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=var2, amp=var1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) else: program.insert( 0, - Play(Constant(duration=var2, amp=np.abs(var1), angle=np.pi), DriveChannel(0)), + Play( + Constant(duration=var2, amp=np.abs(var1), angle=np.pi), + channel=DriveChannel(0), + ), inplace=True, ) return program @@ -237,7 +240,7 @@ def factory(var1, var2): schedule_ref = Schedule() schedule_ref.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) self.assertEqual(schedule_to_test, schedule_ref) @@ -246,7 +249,7 @@ def factory(var1, var2): schedule_ref = Schedule() schedule_ref.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=np.pi), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=np.pi), channel=DriveChannel(0)), inplace=True, ) self.assertEqual(schedule_to_test, schedule_ref) @@ -316,12 +319,12 @@ def test_add_qobj(self): schedule_ref = Schedule() schedule_ref.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) schedule_ref.insert( 20, - Play(Waveform([0.3, 0.1, 0.2, 0.2, 0.3]), DriveChannel(0)), + Play(Waveform([0.3, 0.1, 0.2, 0.2, 0.3]), channel=DriveChannel(0)), inplace=True, ) self.assertEqual(schedule_to_test, schedule_ref) @@ -383,12 +386,12 @@ def test_parameterized_qobj(self): schedule_ref = Schedule() schedule_ref.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) schedule_ref.insert( 0, - ShiftPhase(1.57, DriveChannel(0)), + ShiftPhase(1.57, channel=DriveChannel(0)), inplace=True, ) self.assertEqual(schedule_to_test, schedule_ref) @@ -451,7 +454,7 @@ def test_equality_with_schedule(self): program = Schedule() program.insert( 0, - Play(Constant(duration=10, amp=0.1, angle=0.0), DriveChannel(0)), + Play(Constant(duration=10, amp=0.1, angle=0.0), channel=DriveChannel(0)), inplace=True, ) entry2 = ScheduleDef() diff --git a/test/python/pulse/test_frames.py b/test/python/pulse/test_frames.py index 1a9b99e1139..2973a93deac 100644 --- a/test/python/pulse/test_frames.py +++ b/test/python/pulse/test_frames.py @@ -18,7 +18,7 @@ QubitFrame, MeasurementFrame, ) -from qiskit.test import QiskitTestCase +from test import QiskitTestCase # pylint: disable=wrong-import-order class TestFrames(QiskitTestCase): diff --git a/test/python/pulse/test_instruction_schedule_map.py b/test/python/pulse/test_instruction_schedule_map.py index bf56f980a72..fce8c6c31e4 100644 --- a/test/python/pulse/test_instruction_schedule_map.py +++ b/test/python/pulse/test_instruction_schedule_map.py @@ -43,7 +43,7 @@ class TestInstructionScheduleMap(QiskitTestCase): def test_add(self): """Test add, and that errors are raised when expected.""" sched = Schedule() - sched.append(Play(Waveform(np.ones(5)), DriveChannel(0)), inplace=True) + sched.append(Play(Waveform(np.ones(5)), channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("u1", 1, sched) @@ -61,7 +61,7 @@ def test_add(self): def test_add_block(self): """Test add block, and that errors are raised when expected.""" sched = ScheduleBlock() - sched.append(Play(Waveform(np.ones(5)), DriveChannel(0)), inplace=True) + sched.append(Play(Waveform(np.ones(5)), channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("u1", 1, sched) @@ -141,7 +141,7 @@ def test_qubit_instructions(self): def test_get(self): """Test `get`.""" sched = Schedule() - sched.append(Play(Waveform(np.ones(5)), DriveChannel(0)), inplace=True) + sched.append(Play(Waveform(np.ones(5)), channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("x", 0, sched) @@ -150,7 +150,7 @@ def test_get(self): def test_get_block(self): """Test `get` block.""" sched = ScheduleBlock() - sched.append(Play(Waveform(np.ones(5)), DriveChannel(0)), inplace=True) + sched.append(Play(Waveform(np.ones(5)), channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("x", 0, sched) @@ -185,7 +185,7 @@ def test_pop(self): def test_add_gate(self): """Test add, and that errors are raised when expected.""" sched = Schedule() - sched.append(Play(Waveform(np.ones(5)), DriveChannel(0))) + sched.append(Play(Waveform(np.ones(5)), channel=DriveChannel(0))) inst_map = InstructionScheduleMap() inst_map.add(U1Gate(0), 1, sched) @@ -270,7 +270,7 @@ def test_qubit_instructions_gate(self): def test_get_gate(self): """Test `get`.""" sched = Schedule() - sched.append(Play(Waveform(np.ones(5)), DriveChannel(0))) + sched.append(Play(Waveform(np.ones(5)), channel=DriveChannel(0))) inst_map = InstructionScheduleMap() inst_map.add(XGate(), 0, sched) @@ -350,12 +350,12 @@ def test_schedule_generator(self): def test_func(dur: int): sched = Schedule() waveform = Constant(int(dur), amp).get_waveform() - sched += Play(waveform, DriveChannel(0)) + sched += Play(waveform, channel=DriveChannel(0)) return sched expected_sched = Schedule() cons_waveform = Constant(dur_val, amp).get_waveform() - expected_sched += Play(cons_waveform, DriveChannel(0)) + expected_sched += Play(cons_waveform, channel=DriveChannel(0)) inst_map = InstructionScheduleMap() inst_map.add("f", (0,), test_func) @@ -373,12 +373,12 @@ def test_func(dur: ParameterExpression, t_val: int): dur_bound = dur.bind({t_param: t_val}) sched = Schedule() waveform = Constant(int(float(dur_bound)), amp).get_waveform() - sched += Play(waveform, DriveChannel(0)) + sched += Play(waveform, channel=DriveChannel(0)) return sched expected_sched = Schedule() cons_waveform = Constant(10, amp).get_waveform() - expected_sched += Play(cons_waveform, DriveChannel(0)) + expected_sched += Play(cons_waveform, channel=DriveChannel(0)) inst_map = InstructionScheduleMap() inst_map.add("f", (0,), test_func) @@ -399,17 +399,17 @@ def test_schedule_with_non_alphanumeric_ordering(self): lamb = Parameter("lam") target_sched = Schedule() - target_sched.insert(0, ShiftPhase(theta, DriveChannel(0)), inplace=True) - target_sched.insert(10, ShiftPhase(phi, DriveChannel(0)), inplace=True) - target_sched.insert(20, ShiftPhase(lamb, DriveChannel(0)), inplace=True) + target_sched.insert(0, ShiftPhase(theta, channel=DriveChannel(0)), inplace=True) + target_sched.insert(10, ShiftPhase(phi, channel=DriveChannel(0)), inplace=True) + target_sched.insert(20, ShiftPhase(lamb, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("target_sched", (0,), target_sched, arguments=["theta", "phi", "lam"]) ref_sched = Schedule() - ref_sched.insert(0, ShiftPhase(0, DriveChannel(0)), inplace=True) - ref_sched.insert(10, ShiftPhase(1, DriveChannel(0)), inplace=True) - ref_sched.insert(20, ShiftPhase(2, DriveChannel(0)), inplace=True) + ref_sched.insert(0, ShiftPhase(0, channel=DriveChannel(0)), inplace=True) + ref_sched.insert(10, ShiftPhase(1, channel=DriveChannel(0)), inplace=True) + ref_sched.insert(20, ShiftPhase(2, channel=DriveChannel(0)), inplace=True) # if parameter is alphanumerical ordering this maps to # theta -> 2 @@ -430,7 +430,7 @@ def test_binding_too_many_parameters(self): param = Parameter("param") target_sched = Schedule() - target_sched.insert(0, ShiftPhase(param, DriveChannel(0)), inplace=True) + target_sched.insert(0, ShiftPhase(param, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("target_sched", (0,), target_sched) @@ -443,7 +443,7 @@ def test_binding_unassigned_parameters(self): param = Parameter("param") target_sched = Schedule() - target_sched.insert(0, ShiftPhase(param, DriveChannel(0)), inplace=True) + target_sched.insert(0, ShiftPhase(param, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("target_sched", (0,), target_sched) @@ -458,17 +458,17 @@ def test_schedule_with_multiple_parameters_under_same_name(self): param3 = Parameter("param") target_sched = Schedule() - target_sched.insert(0, ShiftPhase(param1, DriveChannel(0)), inplace=True) - target_sched.insert(10, ShiftPhase(param2, DriveChannel(0)), inplace=True) - target_sched.insert(20, ShiftPhase(param3, DriveChannel(0)), inplace=True) + target_sched.insert(0, ShiftPhase(param1, channel=DriveChannel(0)), inplace=True) + target_sched.insert(10, ShiftPhase(param2, channel=DriveChannel(0)), inplace=True) + target_sched.insert(20, ShiftPhase(param3, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("target_sched", (0,), target_sched) ref_sched = Schedule() - ref_sched.insert(0, ShiftPhase(1.23, DriveChannel(0)), inplace=True) - ref_sched.insert(10, ShiftPhase(1.23, DriveChannel(0)), inplace=True) - ref_sched.insert(20, ShiftPhase(1.23, DriveChannel(0)), inplace=True) + ref_sched.insert(0, ShiftPhase(1.23, channel=DriveChannel(0)), inplace=True) + ref_sched.insert(10, ShiftPhase(1.23, channel=DriveChannel(0)), inplace=True) + ref_sched.insert(20, ShiftPhase(1.23, channel=DriveChannel(0)), inplace=True) test_sched = inst_map.get("target_sched", (0,), param=1.23) @@ -482,15 +482,15 @@ def test_get_schedule_with_unbound_parameter(self): param2 = Parameter("param2") target_sched = Schedule() - target_sched.insert(0, ShiftPhase(param1, DriveChannel(0)), inplace=True) - target_sched.insert(10, ShiftPhase(param2, DriveChannel(0)), inplace=True) + target_sched.insert(0, ShiftPhase(param1, channel=DriveChannel(0)), inplace=True) + target_sched.insert(10, ShiftPhase(param2, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("target_sched", (0,), target_sched) ref_sched = Schedule() - ref_sched.insert(0, ShiftPhase(param1, DriveChannel(0)), inplace=True) - ref_sched.insert(10, ShiftPhase(1.23, DriveChannel(0)), inplace=True) + ref_sched.insert(0, ShiftPhase(param1, channel=DriveChannel(0)), inplace=True) + ref_sched.insert(10, ShiftPhase(1.23, channel=DriveChannel(0)), inplace=True) test_sched = inst_map.get("target_sched", (0,), param2=1.23) @@ -504,13 +504,13 @@ def test_partially_bound_callable(self): def callable_schedule(par_b, par_a): sched = Schedule() - sched.insert(10, Play(Constant(10, par_b), DriveChannel(0)), inplace=True) - sched.insert(20, Play(Constant(10, par_a), DriveChannel(0)), inplace=True) + sched.insert(10, Play(Constant(10, par_b), channel=DriveChannel(0)), inplace=True) + sched.insert(20, Play(Constant(10, par_a), channel=DriveChannel(0)), inplace=True) return sched ref_sched = Schedule() - ref_sched.insert(10, Play(Constant(10, 0.1), DriveChannel(0)), inplace=True) - ref_sched.insert(20, Play(Constant(10, 0.2), DriveChannel(0)), inplace=True) + ref_sched.insert(10, Play(Constant(10, 0.1), channel=DriveChannel(0)), inplace=True) + ref_sched.insert(20, Play(Constant(10, 0.2), channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() @@ -566,8 +566,8 @@ def test_instmap_picklable_with_arguments(self): param1 = Parameter("P1") param2 = Parameter("P2") sched = Schedule() - sched.insert(0, Play(Constant(100, param1), DriveChannel(0)), inplace=True) - sched.insert(0, Play(Constant(100, param2), DriveChannel(1)), inplace=True) + sched.insert(0, Play(Constant(100, param1), channel=DriveChannel(0)), inplace=True) + sched.insert(0, Play(Constant(100, param2), channel=DriveChannel(1)), inplace=True) to_assign = {"P1": 0.1, "P2": 0.2} # Note that dict keys is not picklable @@ -591,7 +591,7 @@ def test_check_user_cals(self): instmap = FakeOpenPulse2Q().defaults().instruction_schedule_map test_u1 = Schedule() - test_u1 += ShiftPhase(Parameter("P0"), DriveChannel(0)) + test_u1 += ShiftPhase(Parameter("P0"), channel=DriveChannel(0)) instmap.add("u1", (0,), test_u1, arguments=["P0"]) publisher = instmap.get("u1", (0,), P0=0).metadata["publisher"] diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py index f0bdd165db0..96b61470296 100644 --- a/test/python/pulse/test_instructions.py +++ b/test/python/pulse/test_instructions.py @@ -13,16 +13,18 @@ """Unit tests for pulse instructions.""" import numpy as np +from ddt import ddt, named_data, unpack from qiskit import circuit from qiskit.pulse import channels, configuration, instructions, library, exceptions +from qiskit.pulse.model import Qubit, QubitFrame, MixedFrame from test import QiskitTestCase # pylint: disable=wrong-import-order class TestAcquire(QiskitTestCase): """Acquisition tests.""" - def test_can_construct_valid_acquire_command(self): + def test_can_construct_valid_acquire_command_legacy(self): """Test if valid acquire command can be constructed.""" kernel_opts = {"start_window": 0, "stop_window": 10} kernel = configuration.Kernel(name="boxcar", **kernel_opts) @@ -38,14 +40,16 @@ def test_can_construct_valid_acquire_command(self): acq = instructions.Acquire( 10, - channels.AcquireChannel(0), - channels.MemorySlot(0), + channel=channels.AcquireChannel(0), + mem_slot=channels.MemorySlot(0), kernel=kernel, discriminator=discriminator, name="acquire", ) self.assertEqual(acq.duration, 10) + self.assertEqual(acq.channel, channels.AcquireChannel(0)) + self.assertEqual(acq.qubit, channels.AcquireChannel(0)) self.assertEqual(acq.discriminator.name, "linear_discriminator") self.assertEqual(acq.discriminator.params, discriminator_opts) self.assertEqual(acq.kernel.name, "boxcar") @@ -64,18 +68,51 @@ def test_can_construct_valid_acquire_command(self): ), ) + def test_acquire_construction_new_model(self): + """Test if valid acquire command can be constructed with the new model.""" + kernel_opts = {"start_window": 0, "stop_window": 10} + kernel = configuration.Kernel(name="boxcar", **kernel_opts) + + discriminator_opts = { + "neighborhoods": [{"qubits": 1, "channels": 1}], + "cal": "coloring", + "resample": False, + } + discriminator = configuration.Discriminator( + name="linear_discriminator", **discriminator_opts + ) + + acq = instructions.Acquire( + 10, + qubit=Qubit(1), + mem_slot=channels.MemorySlot(0), + kernel=kernel, + discriminator=discriminator, + name="acquire", + ) + + self.assertEqual(acq.duration, 10) + self.assertEqual(acq.channel, None) + self.assertEqual(acq.qubit, Qubit(1)) + self.assertEqual(acq.discriminator.name, "linear_discriminator") + self.assertEqual(acq.discriminator.params, discriminator_opts) + self.assertEqual(acq.kernel.name, "boxcar") + self.assertEqual(acq.kernel.params, kernel_opts) + self.assertIsInstance(acq.id, int) + self.assertEqual(acq.name, "acquire") + def test_instructions_hash(self): """Test hashing for acquire instruction.""" acq_1 = instructions.Acquire( 10, - channels.AcquireChannel(0), - channels.MemorySlot(0), + channel=channels.AcquireChannel(0), + mem_slot=channels.MemorySlot(0), name="acquire", ) acq_2 = instructions.Acquire( 10, - channels.AcquireChannel(0), - channels.MemorySlot(0), + channel=channels.AcquireChannel(0), + mem_slot=channels.MemorySlot(0), name="acquire", ) @@ -85,27 +122,103 @@ def test_instructions_hash(self): self.assertEqual(hash_1, hash_2) +@ddt class TestDelay(QiskitTestCase): """Delay tests.""" - def test_delay(self): + def test_delay_legacy(self): """Test delay.""" - delay = instructions.Delay(10, channels.DriveChannel(0), name="test_name") + delay = instructions.Delay(10, channel=channels.DriveChannel(0), name="test_name") self.assertIsInstance(delay.id, int) self.assertEqual(delay.name, "test_name") self.assertEqual(delay.duration, 10) self.assertIsInstance(delay.duration, int) + self.assertEqual(delay.channel, channels.DriveChannel(0)) + self.assertEqual(delay.inst_target, channels.DriveChannel(0)) self.assertEqual(delay.operands, (10, channels.DriveChannel(0))) - self.assertEqual(delay, instructions.Delay(10, channels.DriveChannel(0))) - self.assertNotEqual(delay, instructions.Delay(11, channels.DriveChannel(1))) + self.assertEqual(delay, instructions.Delay(10, channel=channels.DriveChannel(0))) + self.assertNotEqual(delay, instructions.Delay(11, channel=channels.DriveChannel(1))) self.assertEqual(repr(delay), "Delay(10, DriveChannel(0), name='test_name')") - # Test numpy int for duration - delay = instructions.Delay(np.int32(10), channels.DriveChannel(0), name="test_name2") + def test_delay_np_int(self): + """Test delay with numpy int duration""" + delay = instructions.Delay( + np.int32(10), channel=channels.DriveChannel(0), name="test_name2" + ) self.assertEqual(delay.duration, 10) self.assertIsInstance(delay.duration, np.integer) + @named_data( + ["target", Qubit(0), None, None], + ["target_frame", Qubit(0), QubitFrame(0), None], + ["mixed_frame", None, None, MixedFrame(Qubit(0), QubitFrame(0))], + ) + @unpack + def test_delay_new_model(self, target, frame, mixed_frame): + """Test delay new model.""" + delay = instructions.Delay( + 10, target=target, frame=frame, mixed_frame=mixed_frame, name="test_name" + ) + + self.assertIsInstance(delay.id, int) + self.assertEqual(delay.name, "test_name") + self.assertEqual(delay.duration, 10) + self.assertIsInstance(delay.duration, int) + self.assertEqual(delay.channel, None) + + if frame is not None: + ref = MixedFrame(target, frame) + else: + ref = target or mixed_frame + + self.assertEqual(delay.inst_target, ref) + self.assertEqual(delay.operands, (10, ref)) + + @named_data( + ["none", False, False, False, False], + ["channel_target", True, True, False, False], + ["channel_frame", True, False, True, False], + ["channel_mixed_frame", True, False, False, True], + ["channel_target_frame", True, True, True, False], + ["channel_target_mixed_frame", True, True, False, True], + ["channel_frame_mixed_frame", True, False, True, True], + ["all", True, True, True, True], + ["target_mixed_frame", False, True, False, True], + ["target_frame_mixed_frame", False, True, True, True], + ["only_frame", False, False, True, False], + ["frame_mixed_frame", False, False, True, True], + ) + @unpack + def test_delay_new_model_input_combination_validation( + self, channel, target, frame, mixed_frame + ): + """Test delay instruction input combination validation. + + The combination is set according to the truth value of the arguments passed to the function. + Only combinations which should raise an error should ba passed. + """ + channel = channels.DriveChannel(0) if channel else None + target = Qubit(0) if target else None + frame = QubitFrame(0) if frame else None + mixed_frame = MixedFrame(Qubit(0), QubitFrame(0)) if mixed_frame else None + + with self.assertRaises(exceptions.PulseError): + instructions.Delay( + 10, channel=channel, target=target, frame=frame, mixed_frame=mixed_frame + ) + + def test_delay_new_model_input_type_validation(self): + """Test delay instruction input type validation""" + target = Qubit(0) + frame = QubitFrame(0) + with self.assertRaises(exceptions.PulseError): + instructions.Delay(10, target=frame) + with self.assertRaises(exceptions.PulseError): + instructions.Delay(10, target=target, frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.Delay(10, mixed_frame=frame) + def test_operator_delay(self): """Test Operator(delay).""" from qiskit.circuit import QuantumCircuit @@ -121,29 +234,107 @@ def test_operator_delay(self): self.assertEqual(op_delay, op_identity) +_invalid_frame_input_combinations = [ + ["none", False, False, False, False], + ["channel_target", True, True, False, False], + ["channel_frame", True, False, True, False], + ["channel_mixed_frame", True, False, False, True], + ["channel_target_frame", True, True, True, False], + ["channel_target_mixed_frame", True, True, False, True], + ["channel_frame_mixed_frame", True, False, True, True], + ["target", False, True, False, False], + ["all", True, True, True, True], + ["target_mixed_frame", False, True, False, True], + ["target_frame_mixed_frame", False, True, True, True], + ["frame_mixed_frame", False, False, True, True], +] + +_valid_frame_input_combinations = [ + ["frame", QubitFrame(1), None, None], + ["frame_target", QubitFrame(1), Qubit(1), None], + ["mixed_frame", None, None, MixedFrame(Qubit(1), QubitFrame(2))], +] + + +@ddt class TestSetFrequency(QiskitTestCase): """Set frequency tests.""" - def test_freq(self): + def test_freq_legacy(self): """Test set frequency basic functionality.""" - set_freq = instructions.SetFrequency(4.5e9, channels.DriveChannel(1), name="test") + set_freq = instructions.SetFrequency(4.5e9, channel=channels.DriveChannel(1), name="test") self.assertIsInstance(set_freq.id, int) self.assertEqual(set_freq.duration, 0) self.assertEqual(set_freq.frequency, 4.5e9) + self.assertEqual(set_freq.channel, channels.DriveChannel(1)) + self.assertEqual(set_freq.inst_target, channels.DriveChannel(1)) self.assertEqual(set_freq.operands, (4.5e9, channels.DriveChannel(1))) self.assertEqual( - set_freq, instructions.SetFrequency(4.5e9, channels.DriveChannel(1), name="test") + set_freq, + instructions.SetFrequency(4.5e9, channel=channels.DriveChannel(1), name="test"), ) self.assertNotEqual( - set_freq, instructions.SetFrequency(4.5e8, channels.DriveChannel(1), name="test") + set_freq, + instructions.SetFrequency(4.5e8, channel=channels.DriveChannel(1), name="test"), ) self.assertEqual(repr(set_freq), "SetFrequency(4500000000.0, DriveChannel(1), name='test')") + @named_data(*_valid_frame_input_combinations) + @unpack + def test_set_freq_new_model(self, frame, target, mixed_frame): + """Test set frequency basic functionality with valid inputs.""" + set_freq = instructions.SetFrequency( + 4.5e9, frame=frame, target=target, mixed_frame=mixed_frame, name="test" + ) + + self.assertIsInstance(set_freq.id, int) + self.assertEqual(set_freq.duration, 0) + self.assertEqual(set_freq.frequency, 4.5e9) + self.assertEqual(set_freq.channel, None) + if target is not None: + ref = MixedFrame(target, frame) + else: + ref = frame or mixed_frame + self.assertEqual(set_freq.inst_target, ref) + self.assertEqual(set_freq.operands, (4.5e9, ref)) + + @named_data(*_invalid_frame_input_combinations) + @unpack + def test_set_freq_new_model_input_combination_validation( + self, channel, target, frame, mixed_frame + ): + """Test set freq instruction input combination validation. + + The combination is set according to the truth value of the arguments passed to the function. + Only combinations which should raise an error should ba passed. + """ + channel = channels.DriveChannel(0) if channel else None + target = Qubit(0) if target else None + frame = QubitFrame(0) if frame else None + mixed_frame = MixedFrame(Qubit(0), QubitFrame(0)) if mixed_frame else None + + with self.assertRaises(exceptions.PulseError): + instructions.SetFrequency( + 10, channel=channel, target=target, frame=frame, mixed_frame=mixed_frame + ) + + def test_set_freq_new_model_input_type_validation(self): + """Test set freq instruction input type validation.""" + target = Qubit(0) + frame = QubitFrame(0) + + with self.assertRaises(exceptions.PulseError): + instructions.SetFrequency(10, frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.SetFrequency(10, mixed_frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.SetFrequency(10, target=frame, frame=frame) + def test_freq_non_pulse_channel(self): """Test set frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): - instructions.SetFrequency(4.5e9, channels.RegisterSlot(1), name="test") + instructions.SetFrequency(4.5e9, channel=channels.RegisterSlot(1), name="test") def test_parameter_expression(self): """Test getting all parameters assigned by expression.""" @@ -155,31 +346,89 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@ddt class TestShiftFrequency(QiskitTestCase): """Shift frequency tests.""" - def test_shift_freq(self): + def test_shift_freq_legacy(self): """Test shift frequency basic functionality.""" - shift_freq = instructions.ShiftFrequency(4.5e9, channels.DriveChannel(1), name="test") + shift_freq = instructions.ShiftFrequency( + 4.5e9, channel=channels.DriveChannel(1), name="test" + ) self.assertIsInstance(shift_freq.id, int) self.assertEqual(shift_freq.duration, 0) self.assertEqual(shift_freq.frequency, 4.5e9) + self.assertEqual(shift_freq.channel, channels.DriveChannel(1)) + self.assertEqual(shift_freq.inst_target, channels.DriveChannel(1)) self.assertEqual(shift_freq.operands, (4.5e9, channels.DriveChannel(1))) self.assertEqual( - shift_freq, instructions.ShiftFrequency(4.5e9, channels.DriveChannel(1), name="test") + shift_freq, + instructions.ShiftFrequency(4.5e9, channel=channels.DriveChannel(1), name="test"), ) self.assertNotEqual( - shift_freq, instructions.ShiftFrequency(4.5e8, channels.DriveChannel(1), name="test") + shift_freq, + instructions.ShiftFrequency(4.5e8, channel=channels.DriveChannel(1), name="test"), ) self.assertEqual( repr(shift_freq), "ShiftFrequency(4500000000.0, DriveChannel(1), name='test')" ) + @named_data(*_valid_frame_input_combinations) + @unpack + def test_shift_freq_new_model(self, frame, target, mixed_frame): + """Test shift frequency basic functionality with valid inputs.""" + set_freq = instructions.ShiftFrequency( + 4.5e9, frame=frame, target=target, mixed_frame=mixed_frame, name="test" + ) + + self.assertIsInstance(set_freq.id, int) + self.assertEqual(set_freq.duration, 0) + self.assertEqual(set_freq.frequency, 4.5e9) + self.assertEqual(set_freq.channel, None) + if target is not None: + ref = MixedFrame(target, frame) + else: + ref = frame or mixed_frame + self.assertEqual(set_freq.inst_target, ref) + self.assertEqual(set_freq.operands, (4.5e9, ref)) + + @named_data(*_invalid_frame_input_combinations) + @unpack + def test_shift_freq_new_model_input_combination_validation( + self, channel, target, frame, mixed_frame + ): + """Test shift freq instruction input combination validation. + + The combination is set according to the truth value of the arguments passed to the function. + Only combinations which should raise an error should ba passed. + """ + channel = channels.DriveChannel(0) if channel else None + target = Qubit(0) if target else None + frame = QubitFrame(0) if frame else None + mixed_frame = MixedFrame(Qubit(0), QubitFrame(0)) if mixed_frame else None + + with self.assertRaises(exceptions.PulseError): + instructions.ShiftFrequency( + 10, channel=channel, target=target, frame=frame, mixed_frame=mixed_frame + ) + + def test_shift_freq_new_model_input_type_validation(self): + """Test shift freq instruction input type validation.""" + target = Qubit(0) + frame = QubitFrame(0) + + with self.assertRaises(exceptions.PulseError): + instructions.ShiftFrequency(10, frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.ShiftFrequency(10, mixed_frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.ShiftFrequency(10, target=frame, frame=frame) + def test_freq_non_pulse_channel(self): """Test shift frequency constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): - instructions.ShiftFrequency(4.5e9, channels.RegisterSlot(1), name="test") + instructions.ShiftFrequency(4.5e9, channel=channels.RegisterSlot(1), name="test") def test_parameter_expression(self): """Test getting all parameters assigned by expression.""" @@ -191,30 +440,84 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@ddt class TestSetPhase(QiskitTestCase): """Test the instruction construction.""" def test_default(self): """Test basic SetPhase.""" - set_phase = instructions.SetPhase(1.57, channels.DriveChannel(0)) + set_phase = instructions.SetPhase(1.57, channel=channels.DriveChannel(0)) self.assertIsInstance(set_phase.id, int) self.assertEqual(set_phase.name, None) self.assertEqual(set_phase.duration, 0) self.assertEqual(set_phase.phase, 1.57) + self.assertEqual(set_phase.channel, channels.DriveChannel(0)) + self.assertEqual(set_phase.inst_target, channels.DriveChannel(0)) self.assertEqual(set_phase.operands, (1.57, channels.DriveChannel(0))) self.assertEqual( - set_phase, instructions.SetPhase(1.57, channels.DriveChannel(0), name="test") + set_phase, instructions.SetPhase(1.57, channel=channels.DriveChannel(0), name="test") ) self.assertNotEqual( - set_phase, instructions.SetPhase(1.57j, channels.DriveChannel(0), name="test") + set_phase, instructions.SetPhase(1.57j, channel=channels.DriveChannel(0), name="test") ) self.assertEqual(repr(set_phase), "SetPhase(1.57, DriveChannel(0))") + @named_data(*_valid_frame_input_combinations) + @unpack + def test_set_phase_new_model(self, frame, target, mixed_frame): + """Test set phase basic functionality with valid inputs.""" + set_freq = instructions.SetPhase( + 1.5, frame=frame, target=target, mixed_frame=mixed_frame, name="test" + ) + + self.assertIsInstance(set_freq.id, int) + self.assertEqual(set_freq.duration, 0) + self.assertEqual(set_freq.phase, 1.5) + self.assertEqual(set_freq.channel, None) + if target is not None: + ref = MixedFrame(target, frame) + else: + ref = frame or mixed_frame + self.assertEqual(set_freq.inst_target, ref) + self.assertEqual(set_freq.operands, (1.5, ref)) + + @named_data(*_invalid_frame_input_combinations) + @unpack + def test_set_phase_new_model_input_combination_validation( + self, channel, target, frame, mixed_frame + ): + """Test set phase instruction input combination validation. + + The combination is set according to the truth value of the arguments passed to the function. + Only combinations which should raise an error should ba passed. + """ + channel = channels.DriveChannel(0) if channel else None + target = Qubit(0) if target else None + frame = QubitFrame(0) if frame else None + mixed_frame = MixedFrame(Qubit(0), QubitFrame(0)) if mixed_frame else None + + with self.assertRaises(exceptions.PulseError): + instructions.SetPhase( + 10, channel=channel, target=target, frame=frame, mixed_frame=mixed_frame + ) + + def test_set_phase_new_model_input_type_validation(self): + """Test set phase instruction input type validation.""" + target = Qubit(0) + frame = QubitFrame(0) + + with self.assertRaises(exceptions.PulseError): + instructions.SetPhase(10, frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.SetPhase(10, mixed_frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.SetPhase(10, target=frame, frame=frame) + def test_set_phase_non_pulse_channel(self): """Test shift phase constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): - instructions.SetPhase(1.57, channels.RegisterSlot(1), name="test") + instructions.SetPhase(1.57, channel=channels.RegisterSlot(1), name="test") def test_parameter_expression(self): """Test getting all parameters assigned by expression.""" @@ -226,30 +529,86 @@ def test_parameter_expression(self): self.assertSetEqual(instr.parameters, {p1, p2}) +@ddt class TestShiftPhase(QiskitTestCase): """Test the instruction construction.""" def test_default(self): """Test basic ShiftPhase.""" - shift_phase = instructions.ShiftPhase(1.57, channels.DriveChannel(0)) + shift_phase = instructions.ShiftPhase(1.57, channel=channels.DriveChannel(0)) self.assertIsInstance(shift_phase.id, int) self.assertEqual(shift_phase.name, None) self.assertEqual(shift_phase.duration, 0) self.assertEqual(shift_phase.phase, 1.57) + self.assertEqual(shift_phase.channel, channels.DriveChannel(0)) + self.assertEqual(shift_phase.inst_target, channels.DriveChannel(0)) self.assertEqual(shift_phase.operands, (1.57, channels.DriveChannel(0))) self.assertEqual( - shift_phase, instructions.ShiftPhase(1.57, channels.DriveChannel(0), name="test") + shift_phase, + instructions.ShiftPhase(1.57, channel=channels.DriveChannel(0), name="test"), ) self.assertNotEqual( - shift_phase, instructions.ShiftPhase(1.57j, channels.DriveChannel(0), name="test") + shift_phase, + instructions.ShiftPhase(1.57j, channel=channels.DriveChannel(0), name="test"), ) self.assertEqual(repr(shift_phase), "ShiftPhase(1.57, DriveChannel(0))") + @named_data(*_valid_frame_input_combinations) + @unpack + def test_shift_phase_new_model(self, frame, target, mixed_frame): + """Test shift phase basic functionality with valid inputs.""" + set_freq = instructions.ShiftPhase( + 1.5, frame=frame, target=target, mixed_frame=mixed_frame, name="test" + ) + + self.assertIsInstance(set_freq.id, int) + self.assertEqual(set_freq.duration, 0) + self.assertEqual(set_freq.phase, 1.5) + self.assertEqual(set_freq.channel, None) + if target is not None: + ref = MixedFrame(target, frame) + else: + ref = frame or mixed_frame + self.assertEqual(set_freq.inst_target, ref) + self.assertEqual(set_freq.operands, (1.5, ref)) + + @named_data(*_invalid_frame_input_combinations) + @unpack + def test_shift_phase_new_model_input_combination_validation( + self, channel, target, frame, mixed_frame + ): + """Test shift phase instruction input combination validation. + + The combination is set according to the truth value of the arguments passed to the function. + Only combinations which should raise an error should ba passed. + """ + channel = channels.DriveChannel(0) if channel else None + target = Qubit(0) if target else None + frame = QubitFrame(0) if frame else None + mixed_frame = MixedFrame(Qubit(0), QubitFrame(0)) if mixed_frame else None + + with self.assertRaises(exceptions.PulseError): + instructions.ShiftPhase( + 10, channel=channel, target=target, frame=frame, mixed_frame=mixed_frame + ) + + def test_shift_phase_new_model_input_type_validation(self): + """Test shift phase instruction input type validation.""" + target = Qubit(0) + frame = QubitFrame(0) + + with self.assertRaises(exceptions.PulseError): + instructions.ShiftPhase(10, frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.ShiftPhase(10, mixed_frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.ShiftPhase(10, target=frame, frame=frame) + def test_shift_phase_non_pulse_channel(self): """Test shift phase constructor with illegal channel""" with self.assertRaises(exceptions.PulseError): - instructions.ShiftPhase(1.57, channels.RegisterSlot(1), name="test") + instructions.ShiftPhase(1.57, channel=channels.RegisterSlot(1), name="test") def test_parameter_expression(self): """Test getting all parameters assigned by expression.""" @@ -272,10 +631,11 @@ def test_default(self): self.assertEqual(snapshot.name, "test_name") self.assertEqual(snapshot.type, "state") self.assertEqual(snapshot.duration, 0) - self.assertNotEqual(snapshot, instructions.Delay(10, channels.DriveChannel(0))) + self.assertNotEqual(snapshot, instructions.Delay(10, channel=channels.DriveChannel(0))) self.assertEqual(repr(snapshot), "Snapshot(test_name, state, name='test_name')") +@ddt class TestPlay(QiskitTestCase): """Play tests.""" @@ -285,23 +645,82 @@ def setUp(self): self.duration = 4 self.pulse_op = library.Waveform([1.0] * self.duration, name="test") - def test_play(self): + def test_play_legacy(self): """Test basic play instruction.""" - play = instructions.Play(self.pulse_op, channels.DriveChannel(1)) + play = instructions.Play(self.pulse_op, channel=channels.DriveChannel(1)) self.assertIsInstance(play.id, int) self.assertEqual(play.name, self.pulse_op.name) self.assertEqual(play.duration, self.duration) + self.assertEqual(play.channel, channels.DriveChannel(1)) + self.assertEqual(play.inst_target, channels.DriveChannel(1)) self.assertEqual( repr(play), "Play(Waveform(array([1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j]), name='test')," " DriveChannel(1), name='test')", ) + @named_data( + ["target_frame", Qubit(0), QubitFrame(1), None], + ["mixed_frame", None, None, MixedFrame(Qubit(0), QubitFrame(1))], + ) + @unpack + def test_play_new_model_target_frame(self, target, frame, mixed_frame): + """Test basic play instruction.""" + play = instructions.Play(self.pulse_op, target=target, frame=frame, mixed_frame=mixed_frame) + + self.assertIsInstance(play.id, int) + self.assertEqual(play.name, self.pulse_op.name) + self.assertEqual(play.duration, self.duration) + self.assertEqual(play.pulse, self.pulse_op) + self.assertEqual(play.inst_target, MixedFrame(Qubit(0), QubitFrame(1))) + self.assertEqual(play.channel, None) + def test_play_non_pulse_ch_raises(self): """Test that play instruction on non-pulse channel raises a pulse error.""" with self.assertRaises(exceptions.PulseError): - instructions.Play(self.pulse_op, channels.AcquireChannel(0)) + instructions.Play(self.pulse_op, channel=channels.AcquireChannel(0)) + + @named_data( + ["none", False, False, False, False], + ["channel_target", True, True, False, False], + ["channel_frame", True, False, True, False], + ["channel_mixed_frame", True, False, False, True], + ["channel_target_frame", True, True, True, False], + ["channel_target_mixed_frame", True, True, False, True], + ["channel_frame_mixed_frame", True, False, True, True], + ["all", True, True, True, True], + ["target_mixed_frame", False, True, False, True], + ["target_frame_mixed_frame", False, True, True, True], + ["only_frame", False, False, True, False], + ["only_target", False, False, True, False], + ["frame_mixed_frame", False, False, True, True], + ) + @unpack + def test_play_arguments_combination_validation(self, channel, target, frame, mixed_frame): + """Test that play instruction raises an error if the arguments don't specify a unique mixed + frame""" + channel = channels.DriveChannel(0) if channel else None + target = Qubit(0) if target else None + frame = QubitFrame(0) if frame else None + mixed_frame = MixedFrame(Qubit(0), QubitFrame(0)) if mixed_frame else None + + with self.assertRaises(exceptions.PulseError): + instructions.Play( + self.pulse_op, frame=frame, target=target, mixed_frame=mixed_frame, channel=channel + ) + + def test_play_arguments_type_validation(self): + """Test that play instruction raises an error if arguments of wrong type""" + target = Qubit(0) + frame = QubitFrame(0) + + with self.assertRaises(exceptions.PulseError): + instructions.Play(self.pulse_op, target=frame, frame=frame) + with self.assertRaises(exceptions.PulseError): + instructions.Play(self.pulse_op, target=target, frame=target) + with self.assertRaises(exceptions.PulseError): + instructions.Play(self.pulse_op, mixed_frame=frame) class TestDirectives(QiskitTestCase): diff --git a/test/python/pulse/test_macros.py b/test/python/pulse/test_macros.py index 05937c88982..550845dd779 100644 --- a/test/python/pulse/test_macros.py +++ b/test/python/pulse/test_macros.py @@ -46,7 +46,7 @@ def test_measure(self): sched = macros.measure(qubits=[0], backend=self.backend) expected = Schedule( self.inst_map.get("measure", [0, 1]).filter(channels=[MeasureChannel(0)]), - Acquire(10, AcquireChannel(0), MemorySlot(0)), + Acquire(10, channel=AcquireChannel(0), mem_slot=MemorySlot(0)), ) self.assertEqual(sched.instructions, expected.instructions) @@ -55,7 +55,7 @@ def test_measure_sched_with_qubit_mem_slots(self): sched = macros.measure(qubits=[0], backend=self.backend, qubit_mem_slots={0: 1}) expected = Schedule( self.inst_map.get("measure", [0, 1]).filter(channels=[MeasureChannel(0)]), - Acquire(10, AcquireChannel(0), MemorySlot(1)), + Acquire(10, channel=AcquireChannel(0), mem_slot=MemorySlot(1)), ) self.assertEqual(sched.instructions, expected.instructions) @@ -69,15 +69,15 @@ def test_measure_sched_with_meas_map(self): ) expected = Schedule( self.inst_map.get("measure", [0, 1]).filter(channels=[MeasureChannel(0)]), - Acquire(10, AcquireChannel(0), MemorySlot(0)), + Acquire(10, channel=AcquireChannel(0), mem_slot=MemorySlot(0)), ) self.assertEqual(sched_with_meas_map_list.instructions, expected.instructions) self.assertEqual(sched_with_meas_map_dict.instructions, expected.instructions) def test_measure_with_custom_inst_map(self): """Test measure with custom inst_map, meas_map with measure_name.""" - q0_sched = Play(GaussianSquare(1200, 1, 0.4, 1150), MeasureChannel(0)) - q0_sched += Acquire(1200, AcquireChannel(0), MemorySlot(0)) + q0_sched = Play(GaussianSquare(1200, 1, 0.4, 1150), channel=MeasureChannel(0)) + q0_sched += Acquire(1200, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) inst_map = InstructionScheduleMap() inst_map.add("my_sched", 0, q0_sched) sched = macros.measure( @@ -112,7 +112,7 @@ def test_measure_v2_sched_with_qubit_mem_slots(self): ] ) measure_duration = expected.filter(instruction_types=[Play]).duration - expected += Acquire(measure_duration, AcquireChannel(0), MemorySlot(2)) + expected += Acquire(measure_duration, channel=AcquireChannel(0), mem_slot=MemorySlot(2)) self.assertEqual(sched.instructions, expected.instructions) def test_measure_v2_sched_with_meas_map(self): @@ -129,7 +129,7 @@ def test_measure_v2_sched_with_meas_map(self): ] ) measure_duration = expected.filter(instruction_types=[Play]).duration - expected += Acquire(measure_duration, AcquireChannel(0), MemorySlot(0)) + expected += Acquire(measure_duration, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) self.assertEqual(sched_with_meas_map_list.instructions, expected.instructions) self.assertEqual(sched_with_meas_map_dict.instructions, expected.instructions) @@ -147,8 +147,8 @@ def test_multiple_measure_v2(self): ] ) measure_duration = expected.filter(instruction_types=[Play]).duration - expected += Acquire(measure_duration, AcquireChannel(0), MemorySlot(0)) - expected += Acquire(measure_duration, AcquireChannel(1), MemorySlot(1)) + expected += Acquire(measure_duration, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) + expected += Acquire(measure_duration, channel=AcquireChannel(1), mem_slot=MemorySlot(1)) self.assertEqual(sched.instructions, expected.instructions) def test_output_with_measure_v1_and_measure_v2(self): diff --git a/test/python/pulse/test_mixed_frames.py b/test/python/pulse/test_mixed_frames.py index 95ebd556d1c..ef9e979d86b 100644 --- a/test/python/pulse/test_mixed_frames.py +++ b/test/python/pulse/test_mixed_frames.py @@ -18,7 +18,8 @@ GenericFrame, MixedFrame, ) -from qiskit.test import QiskitTestCase +from qiskit.pulse.exceptions import PulseError +from test import QiskitTestCase # pylint: disable=wrong-import-order class TestMixedFrames(QiskitTestCase): @@ -36,6 +37,15 @@ def test_mixed_frame_initialization(self): mixed_frame = MixedFrame(port, frame) self.assertEqual(mixed_frame.pulse_target, port) + def test_mixed_frames_bad_input_types(self): + """Test that bad input types raise error""" + with self.assertRaises(PulseError): + MixedFrame(1, GenericFrame("a")) + with self.assertRaises(PulseError): + MixedFrame(Qubit(0), Qubit(1)) + with self.assertRaises(PulseError): + MixedFrame(GenericFrame("a"), Qubit(1)) + def test_mixed_frames_comparison(self): """Test the comparison of various mixed frames""" self.assertEqual( diff --git a/test/python/pulse/test_parameter_manager.py b/test/python/pulse/test_parameter_manager.py index baeb30e4749..3b075c35809 100644 --- a/test/python/pulse/test_parameter_manager.py +++ b/test/python/pulse/test_parameter_manager.py @@ -75,22 +75,22 @@ def setUp(self): # schedule under test subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft()) - subroutine += pulse.ShiftPhase(self.phi1, self.d1) - subroutine += pulse.Play(self.parametric_waveform1, self.d1) + subroutine += pulse.ShiftPhase(self.phi1, channel=self.d1) + subroutine += pulse.Play(self.parametric_waveform1, channel=self.d1) long_schedule = pulse.ScheduleBlock( alignment_context=AlignEquispaced(self.context_dur), name="long_schedule" ) long_schedule += subroutine - long_schedule += pulse.ShiftPhase(self.phi2, self.d2) - long_schedule += pulse.Play(self.parametric_waveform2, self.d2) - long_schedule += pulse.ShiftPhase(self.phi3, self.d3) - long_schedule += pulse.Play(self.parametric_waveform3, self.d3) + long_schedule += pulse.ShiftPhase(self.phi2, channel=self.d2) + long_schedule += pulse.Play(self.parametric_waveform2, channel=self.d2) + long_schedule += pulse.ShiftPhase(self.phi3, channel=self.d3) + long_schedule += pulse.Play(self.parametric_waveform3, channel=self.d3) long_schedule += pulse.Acquire( self.meas_dur, - pulse.AcquireChannel(self.ch1), + channel=pulse.AcquireChannel(self.ch1), mem_slot=pulse.MemorySlot(self.mem1), reg_slot=pulse.RegisterSlot(self.reg1), ) @@ -125,7 +125,9 @@ def test_get_parameter_from_pulse(self): def test_get_parameter_from_acquire(self): """Test get parameters from acquire instruction.""" - test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1), pulse.MemorySlot(self.ch1)) + test_obj = pulse.Acquire( + 16000, channel=pulse.AcquireChannel(self.ch1), mem_slot=pulse.MemorySlot(self.ch1) + ) visitor = ParameterGetter() visitor.visit(test_obj) @@ -136,7 +138,7 @@ def test_get_parameter_from_acquire(self): def test_get_parameter_from_inst(self): """Test get parameters from instruction.""" - test_obj = pulse.ShiftPhase(self.phi1 + self.phi2, pulse.DriveChannel(0)) + test_obj = pulse.ShiftPhase(self.phi1 + self.phi2, channel=pulse.DriveChannel(0)) visitor = ParameterGetter() visitor.visit(test_obj) @@ -151,7 +153,7 @@ def test_with_function(self): def get_shift(variable): return variable - 1 - test_obj = pulse.ShiftPhase(get_shift(self.phi1), self.d1) + test_obj = pulse.ShiftPhase(get_shift(self.phi1), channel=self.d1) visitor = ParameterGetter() visitor.visit(test_obj) @@ -212,27 +214,31 @@ def test_set_parameter_to_pulse(self): def test_set_parameter_to_acquire(self): """Test set parameters to acquire instruction.""" - test_obj = pulse.Acquire(16000, pulse.AcquireChannel(self.ch1), pulse.MemorySlot(self.ch1)) + test_obj = pulse.Acquire( + 16000, channel=pulse.AcquireChannel(self.ch1), mem_slot=pulse.MemorySlot(self.ch1) + ) value_dict = {self.ch1: 2} visitor = ParameterSetter(param_map=value_dict) assigned = visitor.visit(test_obj) - ref_obj = pulse.Acquire(16000, pulse.AcquireChannel(2), pulse.MemorySlot(2)) + ref_obj = pulse.Acquire( + 16000, channel=pulse.AcquireChannel(2), mem_slot=pulse.MemorySlot(2) + ) self.assertEqual(assigned, ref_obj) def test_set_parameter_to_inst(self): """Test get parameters from instruction.""" - test_obj = pulse.ShiftPhase(self.phi1 + self.phi2, pulse.DriveChannel(0)) + test_obj = pulse.ShiftPhase(self.phi1 + self.phi2, channel=pulse.DriveChannel(0)) value_dict = {self.phi1: 0.123, self.phi2: 0.456} visitor = ParameterSetter(param_map=value_dict) assigned = visitor.visit(test_obj) - ref_obj = pulse.ShiftPhase(0.579, pulse.DriveChannel(0)) + ref_obj = pulse.ShiftPhase(0.579, channel=pulse.DriveChannel(0)) self.assertEqual(assigned, ref_obj) @@ -242,14 +248,14 @@ def test_with_function(self): def get_shift(variable): return variable - 1 - test_obj = pulse.ShiftPhase(get_shift(self.phi1), self.d1) + test_obj = pulse.ShiftPhase(get_shift(self.phi1), channel=self.d1) value_dict = {self.phi1: 2.0, self.ch1: 2} visitor = ParameterSetter(param_map=value_dict) assigned = visitor.visit(test_obj) - ref_obj = pulse.ShiftPhase(1.0, pulse.DriveChannel(2)) + ref_obj = pulse.ShiftPhase(1.0, channel=pulse.DriveChannel(2)) self.assertEqual(assigned, ref_obj) @@ -271,7 +277,7 @@ def test_nested_assignment_partial_bind(self): Inline the schedule and partially bind parameters.""" context = AlignEquispaced(duration=self.context_dur) subroutine = pulse.ScheduleBlock(alignment_context=context) - subroutine += pulse.Play(self.parametric_waveform1, self.d1) + subroutine += pulse.Play(self.parametric_waveform1, channel=self.d1) nested_block = pulse.ScheduleBlock() @@ -290,7 +296,7 @@ def test_nested_assignment_partial_bind(self): ref_context = AlignEquispaced(duration=1000) ref_subroutine = pulse.ScheduleBlock(alignment_context=ref_context) ref_subroutine += pulse.Play( - pulse.Gaussian(200, self.amp1_1 + self.amp1_2, 50), pulse.DriveChannel(1) + pulse.Gaussian(200, self.amp1_1 + self.amp1_2, 50), channel=pulse.DriveChannel(1) ) ref_nested_block = pulse.ScheduleBlock() @@ -366,7 +372,7 @@ def test_invalid_pulse_amplitude(self): test_sched.append( pulse.Play( pulse.Constant(160, amp=2 * amp), - pulse.DriveChannel(0), + channel=pulse.DriveChannel(0), ), inplace=True, ) @@ -382,7 +388,8 @@ def test_disable_validation_parameter_assignment(self): test_sched = pulse.ScheduleBlock() test_sched.append( pulse.Play( - pulse.Gaussian(duration=100, amp=0.5, sigma=sig, angle=0.0), pulse.DriveChannel(0) + pulse.Gaussian(duration=100, amp=0.5, sigma=sig, angle=0.0), + channel=pulse.DriveChannel(0), ), inplace=True, ) @@ -395,7 +402,7 @@ def test_disable_validation_parameter_assignment(self): test_sched.append( pulse.Play( pulse.Gaussian(duration=100, amp=0.5, sigma=sig, angle=0.0), - pulse.DriveChannel(0), + channel=pulse.DriveChannel(0), ), inplace=True, ) @@ -431,19 +438,22 @@ def test_set_parameter_to_complex_schedule(self): # create ref schedule subroutine = pulse.ScheduleBlock(alignment_context=AlignLeft()) - subroutine += pulse.ShiftPhase(1.0, pulse.DriveChannel(0)) - subroutine += pulse.Play(pulse.Gaussian(100, 0.3, 25), pulse.DriveChannel(0)) + subroutine += pulse.ShiftPhase(1.0, channel=pulse.DriveChannel(0)) + subroutine += pulse.Play(pulse.Gaussian(100, 0.3, 25), channel=pulse.DriveChannel(0)) ref_obj = pulse.ScheduleBlock(alignment_context=AlignEquispaced(1000), name="long_schedule") ref_obj += subroutine - ref_obj += pulse.ShiftPhase(2.0, pulse.DriveChannel(2)) - ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25), pulse.DriveChannel(2)) - ref_obj += pulse.ShiftPhase(3.0, pulse.DriveChannel(4)) - ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25), pulse.DriveChannel(4)) + ref_obj += pulse.ShiftPhase(2.0, channel=pulse.DriveChannel(2)) + ref_obj += pulse.Play(pulse.Gaussian(125, 0.3, 25), channel=pulse.DriveChannel(2)) + ref_obj += pulse.ShiftPhase(3.0, channel=pulse.DriveChannel(4)) + ref_obj += pulse.Play(pulse.Gaussian(150, 0.4, 25), channel=pulse.DriveChannel(4)) ref_obj += pulse.Acquire( - 300, pulse.AcquireChannel(0), pulse.MemorySlot(3), pulse.RegisterSlot(0) + 300, + channel=pulse.AcquireChannel(0), + mem_slot=pulse.MemorySlot(3), + reg_slot=pulse.RegisterSlot(0), ) self.assertEqual(assigned, ref_obj) @@ -460,7 +470,7 @@ def test_attribute_parameters(self): waveform = pulse.library.Gaussian(duration=128, sigma=sigma, amp=amp) block = pulse.ScheduleBlock() - block += pulse.Play(waveform, pulse.DriveChannel(10)) + block += pulse.Play(waveform, channel=pulse.DriveChannel(10)) ref_set = {amp, sigma} @@ -475,7 +485,7 @@ def test_parametric_pulses(self): waveform = pulse.library.Gaussian(duration=128, sigma=sigma, amp=amp) block = pulse.ScheduleBlock() - block += pulse.Play(waveform, pulse.DriveChannel(10)) + block += pulse.Play(waveform, channel=pulse.DriveChannel(10)) block.assign_parameters({amp: 0.2, sigma: 4}, inplace=True) self.assertEqual(block.blocks[0].pulse.amp, 0.2) @@ -494,10 +504,10 @@ def test_overlapping_pulses(self): param_idx = Parameter("q") schedule = pulse.Schedule() - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(param_idx)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(param_idx)) with self.assertRaises(PulseError): schedule |= pulse.Play( - pulse.Waveform([0.5, 0.5, 0.5, 0.5]), pulse.DriveChannel(param_idx) + pulse.Waveform([0.5, 0.5, 0.5, 0.5]), channel=pulse.DriveChannel(param_idx) ) def test_overlapping_on_assignment(self): @@ -505,8 +515,8 @@ def test_overlapping_on_assignment(self): param_idx = Parameter("q") schedule = pulse.Schedule() - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(1)) - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(param_idx)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(1)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(param_idx)) with self.assertRaises(PulseError): schedule.assign_parameters({param_idx: 1}) @@ -515,8 +525,10 @@ def test_overlapping_on_expression_assigment_to_zero(self): param_idx = Parameter("q") schedule = pulse.Schedule() - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(param_idx)) - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(2 * param_idx)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(param_idx)) + schedule |= pulse.Play( + pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(2 * param_idx) + ) with self.assertRaises(PulseError): schedule.assign_parameters({param_idx: 0}) @@ -525,9 +537,9 @@ def test_merging_upon_assignment(self): param_idx = Parameter("q") schedule = pulse.Schedule() - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(1)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(1)) schedule = schedule.insert( - 4, pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(param_idx)) + 4, pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(param_idx)) ) schedule.assign_parameters({param_idx: 1}) @@ -540,8 +552,8 @@ def test_overlapping_on_multiple_assignment(self): param_idx2 = Parameter("q2") schedule = pulse.Schedule() - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(param_idx1)) - schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), pulse.DriveChannel(param_idx2)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(param_idx1)) + schedule |= pulse.Play(pulse.Waveform([1, 1, 1, 1]), channel=pulse.DriveChannel(param_idx2)) schedule.assign_parameters({param_idx1: 2}) with self.assertRaises(PulseError): @@ -552,7 +564,7 @@ def test_cannot_build_schedule_with_unassigned_duration(self): dur = Parameter("dur") ch = pulse.DriveChannel(0) - test_play = pulse.Play(pulse.Gaussian(dur, 0.1, dur / 4), ch) + test_play = pulse.Play(pulse.Gaussian(dur, 0.1, dur / 4), channel=ch) sched = pulse.Schedule() with self.assertRaises(UnassignedDurationError): diff --git a/test/python/pulse/test_pulse_targets.py b/test/python/pulse/test_pulse_targets.py index d3a8c92c321..0ac3b3bef12 100644 --- a/test/python/pulse/test_pulse_targets.py +++ b/test/python/pulse/test_pulse_targets.py @@ -18,7 +18,7 @@ Coupler, Port, ) -from qiskit.test import QiskitTestCase +from test import QiskitTestCase # pylint: disable=wrong-import-order class TestLogicalElements(QiskitTestCase): diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index 40d637887ed..b6250651ae1 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -72,7 +72,7 @@ def test_append_an_instruction_to_empty_schedule(self): lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule() - sched = sched.append(Play(lp0, self.config.drive(0))) + sched = sched.append(Play(lp0, channel=self.config.drive(0))) self.assertEqual(0, sched.start_time) self.assertEqual(3, sched.stop_time) @@ -81,8 +81,8 @@ def test_append_instructions_applying_to_different_channels(self): lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule() - sched = sched.append(Play(lp0, self.config.drive(0))) - sched = sched.append(Play(lp0, self.config.drive(1))) + sched = sched.append(Play(lp0, channel=self.config.drive(0))) + sched = sched.append(Play(lp0, channel=self.config.drive(1))) self.assertEqual(0, sched.start_time) # appending to separate channel so should be at same time. self.assertEqual(3, sched.stop_time) @@ -92,7 +92,7 @@ def test_insert_an_instruction_into_empty_schedule(self): lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule() - sched = sched.insert(10, Play(lp0, self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(0))) self.assertEqual(10, sched.start_time) self.assertEqual(13, sched.stop_time) @@ -101,8 +101,8 @@ def test_insert_an_instruction_before_an_existing_instruction(self): lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule() - sched = sched.insert(10, Play(lp0, self.config.drive(0))) - sched = sched.insert(5, Play(lp0, self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(5, Play(lp0, channel=self.config.drive(0))) self.assertEqual(5, sched.start_time) self.assertEqual(13, sched.stop_time) @@ -111,9 +111,9 @@ def test_fail_to_insert_instruction_into_occupied_timing(self): lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule() - sched = sched.insert(10, Play(lp0, self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(0))) with self.assertRaises(PulseError): - sched.insert(11, Play(lp0, self.config.drive(0))) + sched.insert(11, Play(lp0, channel=self.config.drive(0))) def test_can_create_valid_schedule(self): """Test valid schedule creation without error.""" @@ -121,14 +121,17 @@ def test_can_create_valid_schedule(self): gp1 = library.Gaussian(duration=20, amp=0.7, sigma=3) sched = Schedule() - sched = sched.append(Play(gp0, self.config.drive(0))) - sched = sched.insert(60, ShiftPhase(-1.57, self.config.drive(0))) - sched = sched.insert(30, Play(gp1, self.config.drive(0))) - sched = sched.insert(60, Play(gp0, self.config.control([0, 1])[0])) + sched = sched.append(Play(gp0, channel=self.config.drive(0))) + sched = sched.insert(60, ShiftPhase(-1.57, channel=self.config.drive(0))) + sched = sched.insert(30, Play(gp1, channel=self.config.drive(0))) + sched = sched.insert(60, Play(gp0, channel=self.config.control([0, 1])[0])) sched = sched.insert(80, Snapshot("label", "snap_type")) - sched = sched.insert(90, ShiftPhase(1.57, self.config.drive(0))) + sched = sched.insert(90, ShiftPhase(1.57, channel=self.config.drive(0))) sched = sched.insert( - 90, Acquire(10, self.config.acquire(0), MemorySlot(0), RegisterSlot(0)) + 90, + Acquire( + 10, channel=self.config.acquire(0), mem_slot=MemorySlot(0), reg_slot=RegisterSlot(0) + ), ) self.assertEqual(0, sched.start_time) self.assertEqual(100, sched.stop_time) @@ -151,13 +154,13 @@ def test_can_create_valid_schedule_with_syntax_sugar(self): gp1 = library.Gaussian(duration=20, amp=0.5, sigma=3) sched = Schedule() - sched += Play(gp0, self.config.drive(0)) - sched |= ShiftPhase(-1.57, self.config.drive(0)) << 60 - sched |= Play(gp1, self.config.drive(0)) << 30 - sched |= Play(gp0, self.config.control(qubits=[0, 1])[0]) << 60 + sched += Play(gp0, channel=self.config.drive(0)) + sched |= ShiftPhase(-1.57, channel=self.config.drive(0)) << 60 + sched |= Play(gp1, channel=self.config.drive(0)) << 30 + sched |= Play(gp0, channel=self.config.control(qubits=[0, 1])[0]) << 60 sched |= Snapshot("label", "snap_type") << 60 - sched |= ShiftPhase(1.57, self.config.drive(0)) << 90 - sched |= Acquire(10, self.config.acquire(0), MemorySlot(0)) << 90 + sched |= ShiftPhase(1.57, channel=self.config.drive(0)) << 90 + sched |= Acquire(10, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) << 90 sched += sched def test_immutability(self): @@ -165,11 +168,11 @@ def test_immutability(self): gp0 = library.Gaussian(duration=100, amp=0.7, sigma=3) gp1 = library.Gaussian(duration=20, amp=0.5, sigma=3) - sched = Play(gp1, self.config.drive(0)) << 100 + sched = Play(gp1, channel=self.config.drive(0)) << 100 # if schedule was mutable the next two sequences would overlap and an error # would be raised. - sched.insert(0, Play(gp0, self.config.drive(0))) - sched.insert(0, Play(gp0, self.config.drive(0))) + sched.insert(0, Play(gp0, channel=self.config.drive(0))) + sched.insert(0, Play(gp0, channel=self.config.drive(0))) def test_inplace(self): """Test that in place operations on schedule are still immutable.""" @@ -177,9 +180,9 @@ def test_inplace(self): gp1 = library.Gaussian(duration=20, amp=0.5, sigma=3) sched = Schedule() - sched = sched + Play(gp1, self.config.drive(0)) + sched = sched + Play(gp1, channel=self.config.drive(0)) sched2 = sched - sched += Play(gp0, self.config.drive(0)) + sched += Play(gp0, channel=self.config.drive(0)) self.assertNotEqual(sched, sched2) def test_empty_schedule(self): @@ -198,8 +201,10 @@ def test_overlapping_schedules(self): """Test overlapping schedules.""" def my_test_make_schedule(acquire: int, memoryslot: int, shift: int): - sched1 = Acquire(acquire, AcquireChannel(0), MemorySlot(memoryslot)) - sched2 = Acquire(acquire, AcquireChannel(1), MemorySlot(memoryslot)).shift(shift) + sched1 = Acquire(acquire, channel=AcquireChannel(0), mem_slot=MemorySlot(memoryslot)) + sched2 = Acquire( + acquire, channel=AcquireChannel(1), mem_slot=MemorySlot(memoryslot) + ).shift(shift) return Schedule(sched1, sched2) @@ -222,11 +227,11 @@ def test_flat_instruction_sequence_returns_instructions(self): # normal schedule subsched = Schedule() - subsched = subsched.insert(20, Play(lp0, self.config.drive(0))) # grand child 1 - subsched = subsched.append(Play(lp0, self.config.drive(0))) # grand child 2 + subsched = subsched.insert(20, Play(lp0, channel=self.config.drive(0))) # grand child 1 + subsched = subsched.append(Play(lp0, channel=self.config.drive(0))) # grand child 2 sched = Schedule() - sched = sched.append(Play(lp0, self.config.drive(0))) # child + sched = sched.append(Play(lp0, channel=self.config.drive(0))) # child sched = sched.append(subsched) for _, instr in sched.instructions: self.assertIsInstance(instr, Instruction) @@ -236,11 +241,11 @@ def test_absolute_start_time_of_grandchild(self): lp0 = self.linear(duration=10, slope=0.02, intercept=0.01) subsched = Schedule() - subsched = subsched.insert(20, Play(lp0, self.config.drive(0))) # grand child 1 - subsched = subsched.append(Play(lp0, self.config.drive(0))) # grand child 2 + subsched = subsched.insert(20, Play(lp0, channel=self.config.drive(0))) # grand child 1 + subsched = subsched.append(Play(lp0, channel=self.config.drive(0))) # grand child 2 sched = Schedule() - sched = sched.append(Play(lp0, self.config.drive(0))) # child + sched = sched.append(Play(lp0, channel=self.config.drive(0))) # child sched = sched.append(subsched) start_times = sorted(shft + instr.start_time for shft, instr in sched.instructions) @@ -251,11 +256,11 @@ def test_shift_schedule(self): lp0 = self.linear(duration=10, slope=0.02, intercept=0.01) subsched = Schedule() - subsched = subsched.insert(20, Play(lp0, self.config.drive(0))) # grand child 1 - subsched = subsched.append(Play(lp0, self.config.drive(0))) # grand child 2 + subsched = subsched.insert(20, Play(lp0, channel=self.config.drive(0))) # grand child 1 + subsched = subsched.append(Play(lp0, channel=self.config.drive(0))) # grand child 2 sched = Schedule() - sched = sched.append(Play(lp0, self.config.drive(0))) # child + sched = sched.append(Play(lp0, channel=self.config.drive(0))) # child sched = sched.append(subsched) shift = sched.shift(100) @@ -266,17 +271,21 @@ def test_shift_schedule(self): def test_keep_original_schedule_after_attached_to_another_schedule(self): """Test if a schedule keeps its children after attached to another schedule.""" - children = Acquire(10, self.config.acquire(0), MemorySlot(0)).shift(20) + Acquire( - 10, self.config.acquire(0), MemorySlot(0) - ) + children = Acquire(10, channel=self.config.acquire(0), mem_slot=MemorySlot(0)).shift( + 20 + ) + Acquire(10, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) self.assertEqual(2, len(list(children.instructions))) - sched = Acquire(10, self.config.acquire(0), MemorySlot(0)).append(children) + sched = Acquire(10, channel=self.config.acquire(0), mem_slot=MemorySlot(0)).append(children) self.assertEqual(3, len(list(sched.instructions))) # add 2 instructions to children (2 instructions -> 4 instructions) - children = children.append(Acquire(10, self.config.acquire(0), MemorySlot(0))) - children = children.insert(100, Acquire(10, self.config.acquire(0), MemorySlot(0))) + children = children.append( + Acquire(10, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) + ) + children = children.insert( + 100, Acquire(10, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) + ) self.assertEqual(4, len(list(children.instructions))) # sched must keep 3 instructions (must not update to 5 instructions) self.assertEqual(3, len(list(sched.instructions))) @@ -308,13 +317,16 @@ def test_name_inherited(self): sched3 = sched1 | sched2 self.assertEqual(sched3.name, "test_name") - sched_acq = Acquire(10, self.config.acquire(1), MemorySlot(1), name="acq_name") | sched1 + sched_acq = ( + Acquire(10, channel=self.config.acquire(1), mem_slot=MemorySlot(1), name="acq_name") + | sched1 + ) self.assertEqual(sched_acq.name, "acq_name") - sched_pulse = Play(gp0, self.config.drive(0)) | sched1 + sched_pulse = Play(gp0, channel=self.config.drive(0)) | sched1 self.assertEqual(sched_pulse.name, "pulse_name") - sched_fc = ShiftPhase(0.1, self.config.drive(0), name="fc_name") | sched1 + sched_fc = ShiftPhase(0.1, channel=self.config.drive(0), name="fc_name") | sched1 self.assertEqual(sched_fc.name, "fc_name") sched_snapshot = snapshot | sched1 @@ -327,7 +339,10 @@ def test_schedule_with_acquire_on_single_qubit(self): sched_single = sched_single.insert( 10, Acquire( - 10, self.config.acquire(i), mem_slot=MemorySlot(i), reg_slot=RegisterSlot(i) + 10, + channel=self.config.acquire(i), + mem_slot=MemorySlot(i), + reg_slot=RegisterSlot(i), ), ) @@ -337,12 +352,19 @@ def test_schedule_with_acquire_on_single_qubit(self): def test_parametric_commands_in_sched(self): """Test that schedules can be built with parametric commands.""" sched = Schedule(name="test_parametric") - sched += Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), DriveChannel(0)) - sched += Play(Drag(duration=25, amp=0.4, angle=0.5, sigma=7.8, beta=4), DriveChannel(1)) - sched += Play(Constant(duration=25, amp=1), DriveChannel(2)) + sched += Play( + Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), channel=DriveChannel(0) + ) + sched += Play( + Drag(duration=25, amp=0.4, angle=0.5, sigma=7.8, beta=4), channel=DriveChannel(1) + ) + sched += Play(Constant(duration=25, amp=1), channel=DriveChannel(2)) sched_duration = sched.duration sched += ( - Play(GaussianSquare(duration=1500, amp=0.2, sigma=8, width=140), MeasureChannel(0)) + Play( + GaussianSquare(duration=1500, amp=0.2, sigma=8, width=140), + channel=MeasureChannel(0), + ) << sched_duration ) self.assertEqual(sched.duration, 1525) @@ -351,46 +373,46 @@ def test_parametric_commands_in_sched(self): def test_numpy_integer_input(self): """Test that mixed integer duration types can build a schedule (#5754).""" sched = Schedule() - sched += Delay(np.int32(25), DriveChannel(0)) - sched += Play(Constant(duration=30, amp=0.1), DriveChannel(0)) + sched += Delay(np.int32(25), channel=DriveChannel(0)) + sched += Play(Constant(duration=30, amp=0.1), channel=DriveChannel(0)) self.assertEqual(sched.duration, 55) def test_negative_time_raises(self): """Test that a negative time will raise an error.""" sched = Schedule() - sched += Delay(1, DriveChannel(0)) + sched += Delay(1, channel=DriveChannel(0)) with self.assertRaises(PulseError): sched.shift(-10) def test_shift_float_time_raises(self): """Test that a floating time will raise an error with shift.""" sched = Schedule() - sched += Delay(1, DriveChannel(0)) + sched += Delay(1, channel=DriveChannel(0)) with self.assertRaises(PulseError): sched.shift(0.1) def test_insert_float_time_raises(self): """Test that a floating time will raise an error with insert.""" sched = Schedule() - sched += Delay(1, DriveChannel(0)) + sched += Delay(1, channel=DriveChannel(0)) with self.assertRaises(PulseError): sched.insert(10.1, sched) def test_shift_unshift(self): """Test shift and then unshifting of schedule""" reference_sched = Schedule() - reference_sched += Delay(10, DriveChannel(0)) + reference_sched += Delay(10, channel=DriveChannel(0)) shifted_sched = reference_sched.shift(10).shift(-10) self.assertEqual(shifted_sched, reference_sched) def test_duration(self): """Test schedule.duration.""" reference_sched = Schedule() - reference_sched = reference_sched.insert(10, Delay(10, DriveChannel(0))) - reference_sched = reference_sched.insert(10, Delay(50, DriveChannel(1))) - reference_sched = reference_sched.insert(10, ShiftPhase(0.1, DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(10, channel=DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(50, channel=DriveChannel(1))) + reference_sched = reference_sched.insert(10, ShiftPhase(0.1, channel=DriveChannel(0))) - reference_sched = reference_sched.insert(100, ShiftPhase(0.1, DriveChannel(1))) + reference_sched = reference_sched.insert(100, ShiftPhase(0.1, channel=DriveChannel(1))) self.assertEqual(reference_sched.duration, 100) self.assertEqual(reference_sched.duration, 100) @@ -398,11 +420,11 @@ def test_duration(self): def test_ch_duration(self): """Test schedule.ch_duration.""" reference_sched = Schedule() - reference_sched = reference_sched.insert(10, Delay(10, DriveChannel(0))) - reference_sched = reference_sched.insert(10, Delay(50, DriveChannel(1))) - reference_sched = reference_sched.insert(10, ShiftPhase(0.1, DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(10, channel=DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(50, channel=DriveChannel(1))) + reference_sched = reference_sched.insert(10, ShiftPhase(0.1, channel=DriveChannel(0))) - reference_sched = reference_sched.insert(100, ShiftPhase(0.1, DriveChannel(1))) + reference_sched = reference_sched.insert(100, ShiftPhase(0.1, channel=DriveChannel(1))) self.assertEqual(reference_sched.ch_duration(DriveChannel(0)), 20) self.assertEqual(reference_sched.ch_duration(DriveChannel(1)), 100) @@ -413,11 +435,11 @@ def test_ch_duration(self): def test_ch_start_time(self): """Test schedule.ch_start_time.""" reference_sched = Schedule() - reference_sched = reference_sched.insert(10, Delay(10, DriveChannel(0))) - reference_sched = reference_sched.insert(10, Delay(50, DriveChannel(1))) - reference_sched = reference_sched.insert(10, ShiftPhase(0.1, DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(10, channel=DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(50, channel=DriveChannel(1))) + reference_sched = reference_sched.insert(10, ShiftPhase(0.1, channel=DriveChannel(0))) - reference_sched = reference_sched.insert(100, ShiftPhase(0.1, DriveChannel(1))) + reference_sched = reference_sched.insert(100, ShiftPhase(0.1, channel=DriveChannel(1))) self.assertEqual(reference_sched.ch_start_time(DriveChannel(0)), 10) self.assertEqual(reference_sched.ch_start_time(DriveChannel(1)), 10) @@ -425,11 +447,11 @@ def test_ch_start_time(self): def test_ch_stop_time(self): """Test schedule.ch_stop_time.""" reference_sched = Schedule() - reference_sched = reference_sched.insert(10, Delay(10, DriveChannel(0))) - reference_sched = reference_sched.insert(10, Delay(50, DriveChannel(1))) - reference_sched = reference_sched.insert(10, ShiftPhase(0.1, DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(10, channel=DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(50, channel=DriveChannel(1))) + reference_sched = reference_sched.insert(10, ShiftPhase(0.1, channel=DriveChannel(0))) - reference_sched = reference_sched.insert(100, ShiftPhase(0.1, DriveChannel(1))) + reference_sched = reference_sched.insert(100, ShiftPhase(0.1, channel=DriveChannel(1))) self.assertEqual(reference_sched.ch_stop_time(DriveChannel(0)), 20) self.assertEqual(reference_sched.ch_stop_time(DriveChannel(1)), 100) @@ -437,11 +459,11 @@ def test_ch_stop_time(self): def test_timeslots(self): """Test schedule.timeslots.""" reference_sched = Schedule() - reference_sched = reference_sched.insert(10, Delay(10, DriveChannel(0))) - reference_sched = reference_sched.insert(10, Delay(50, DriveChannel(1))) - reference_sched = reference_sched.insert(10, ShiftPhase(0.1, DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(10, channel=DriveChannel(0))) + reference_sched = reference_sched.insert(10, Delay(50, channel=DriveChannel(1))) + reference_sched = reference_sched.insert(10, ShiftPhase(0.1, channel=DriveChannel(0))) - reference_sched = reference_sched.insert(100, ShiftPhase(0.1, DriveChannel(1))) + reference_sched = reference_sched.insert(100, ShiftPhase(0.1, channel=DriveChannel(1))) self.assertEqual(reference_sched.timeslots[DriveChannel(0)], [(10, 10), (10, 20)]) self.assertEqual(reference_sched.timeslots[DriveChannel(1)], [(10, 60), (100, 100)]) @@ -453,7 +475,7 @@ def test_len(self): lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) for j in range(1, 10): - sched = sched.append(Play(lp0, self.config.drive(0))) + sched = sched.append(Play(lp0, channel=self.config.drive(0))) self.assertEqual(len(sched), j) def test_inherit_from(self): @@ -473,8 +495,8 @@ class TestReplace(BaseTestSchedule): def test_replace_instruction(self): """Test replacement of simple instruction""" - old = Play(Constant(100, 1.0), DriveChannel(0)) - new = Play(Constant(100, 0.1), DriveChannel(0)) + old = Play(Constant(100, 1.0), channel=DriveChannel(0)) + new = Play(Constant(100, 0.1), channel=DriveChannel(0)) sched = Schedule(old) new_sched = sched.replace(old, new) @@ -489,14 +511,14 @@ def test_replace_schedule(self): """Test replacement of schedule.""" old = Schedule( - Delay(10, DriveChannel(0)), - Delay(100, DriveChannel(1)), + Delay(10, channel=DriveChannel(0)), + Delay(100, channel=DriveChannel(1)), ) new = Schedule( - Play(Constant(10, 1.0), DriveChannel(0)), - Play(Constant(100, 0.1), DriveChannel(1)), + Play(Constant(10, 1.0), channel=DriveChannel(0)), + Play(Constant(100, 0.1), channel=DriveChannel(1)), ) - const = Play(Constant(100, 1.0), DriveChannel(0)) + const = Play(Constant(100, 1.0), channel=DriveChannel(0)) sched = Schedule() sched += const @@ -515,12 +537,12 @@ def test_replace_schedule(self): def test_replace_fails_on_overlap(self): """Test that replacement fails on overlap.""" - old = Play(Constant(20, 1.0), DriveChannel(0)) - new = Play(Constant(100, 0.1), DriveChannel(0)) + old = Play(Constant(20, 1.0), channel=DriveChannel(0)) + new = Play(Constant(100, 0.1), channel=DriveChannel(0)) sched = Schedule() sched += old - sched += Delay(100, DriveChannel(0)) + sched += Delay(100, channel=DriveChannel(0)) with self.assertRaises(PulseError): sched.replace(old, new) @@ -538,7 +560,7 @@ def test_delay_drive_channel(self): drive_ch = self.config.drive(0) pulse = Waveform(np.full(10, 0.1)) # should pass as is an append - sched = Delay(self.delay_time, drive_ch) + Play(pulse, drive_ch) + sched = Delay(self.delay_time, channel=drive_ch) + Play(pulse, channel=drive_ch) self.assertIsInstance(sched, Schedule) pulse_instr = sched.instructions[-1] # assert last instruction is pulse @@ -547,7 +569,7 @@ def test_delay_drive_channel(self): self.assertEqual(pulse_instr[0], 10) # should fail due to overlap with self.assertRaises(PulseError): - sched = Delay(self.delay_time, drive_ch) | Play(pulse, drive_ch) + sched = Delay(self.delay_time, channel=drive_ch) | Play(pulse, channel=drive_ch) def test_delay_measure_channel(self): """Test Delay on MeasureChannel""" @@ -555,11 +577,11 @@ def test_delay_measure_channel(self): measure_ch = self.config.measure(0) pulse = Waveform(np.full(10, 0.1)) # should pass as is an append - sched = Delay(self.delay_time, measure_ch) + Play(pulse, measure_ch) + sched = Delay(self.delay_time, channel=measure_ch) + Play(pulse, channel=measure_ch) self.assertIsInstance(sched, Schedule) # should fail due to overlap with self.assertRaises(PulseError): - sched = Delay(self.delay_time, measure_ch) | Play(pulse, measure_ch) + sched = Delay(self.delay_time, channel=measure_ch) | Play(pulse, channel=measure_ch) def test_delay_control_channel(self): """Test Delay on ControlChannel""" @@ -567,11 +589,11 @@ def test_delay_control_channel(self): control_ch = self.config.control([0, 1])[0] pulse = Waveform(np.full(10, 0.1)) # should pass as is an append - sched = Delay(self.delay_time, control_ch) + Play(pulse, control_ch) + sched = Delay(self.delay_time, channel=control_ch) + Play(pulse, channel=control_ch) self.assertIsInstance(sched, Schedule) # should fail due to overlap with self.assertRaises(PulseError): - sched = Delay(self.delay_time, control_ch) | Play(pulse, control_ch) + sched = Delay(self.delay_time, channel=control_ch) | Play(pulse, channel=control_ch) self.assertIsInstance(sched, Schedule) def test_delay_acquire_channel(self): @@ -579,11 +601,15 @@ def test_delay_acquire_channel(self): acquire_ch = self.config.acquire(0) # should pass as is an append - sched = Delay(self.delay_time, acquire_ch) + Acquire(10, acquire_ch, MemorySlot(0)) + sched = Delay(self.delay_time, channel=acquire_ch) + Acquire( + 10, channel=acquire_ch, mem_slot=MemorySlot(0) + ) self.assertIsInstance(sched, Schedule) # should fail due to overlap with self.assertRaises(PulseError): - sched = Delay(self.delay_time, acquire_ch) | Acquire(10, acquire_ch, MemorySlot(0)) + sched = Delay(self.delay_time, channel=acquire_ch) | Acquire( + 10, channel=acquire_ch, mem_slot=MemorySlot(0) + ) self.assertIsInstance(sched, Schedule) def test_delay_snapshot_channel(self): @@ -592,11 +618,11 @@ def test_delay_snapshot_channel(self): snapshot_ch = SnapshotChannel() snapshot = Snapshot(label="test") # should pass as is an append - sched = Delay(self.delay_time, snapshot_ch) + snapshot + sched = Delay(self.delay_time, channel=snapshot_ch) + snapshot self.assertIsInstance(sched, Schedule) # should fail due to overlap with self.assertRaises(PulseError): - sched = Delay(self.delay_time, snapshot_ch) | snapshot << 5 + sched = Delay(self.delay_time, channel=snapshot_ch) | snapshot << 5 self.assertIsInstance(sched, Schedule) @@ -607,12 +633,12 @@ def test_filter_channels(self): """Test filtering over channels.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") - sched = sched.insert(0, Play(lp0, self.config.drive(0))) - sched = sched.insert(10, Play(lp0, self.config.drive(1))) - sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) - sched = sched.insert(60, Acquire(5, AcquireChannel(0), MemorySlot(0))) - sched = sched.insert(60, Acquire(5, AcquireChannel(1), MemorySlot(1))) - sched = sched.insert(90, Play(lp0, self.config.drive(0))) + sched = sched.insert(0, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(1))) + sched = sched.insert(30, ShiftPhase(-1.57, channel=self.config.drive(0))) + sched = sched.insert(60, Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0))) + sched = sched.insert(60, Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1))) + sched = sched.insert(90, Play(lp0, channel=self.config.drive(0))) # split instructions for those on AcquireChannel(1) and those not filtered, excluded = self._filter_and_test_consistency(sched, channels=[AcquireChannel(1)]) @@ -631,8 +657,8 @@ def test_filter_channels(self): def test_filter_exclude_name(self): """Test the name of the schedules after applying filter and exclude functions.""" sched = Schedule(name="test-schedule") - sched = sched.insert(10, Acquire(5, AcquireChannel(0), MemorySlot(0))) - sched = sched.insert(10, Acquire(5, AcquireChannel(1), MemorySlot(1))) + sched = sched.insert(10, Acquire(5, channel=AcquireChannel(0), mem_slot=MemorySlot(0))) + sched = sched.insert(10, Acquire(5, channel=AcquireChannel(1), mem_slot=MemorySlot(1))) excluded = sched.exclude(channels=[AcquireChannel(0)]) filtered = sched.filter(channels=[AcquireChannel(1)]) @@ -644,15 +670,17 @@ def test_filter_inst_types(self): """Test filtering on instruction types.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") - sched = sched.insert(0, Play(lp0, self.config.drive(0))) - sched = sched.insert(10, Play(lp0, self.config.drive(1))) - sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) - sched = sched.insert(40, SetFrequency(8.0, self.config.drive(0))) - sched = sched.insert(50, ShiftFrequency(4.0e6, self.config.drive(0))) - sched = sched.insert(55, SetPhase(3.14, self.config.drive(0))) + sched = sched.insert(0, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(1))) + sched = sched.insert(30, ShiftPhase(-1.57, channel=self.config.drive(0))) + sched = sched.insert(40, SetFrequency(8.0, channel=self.config.drive(0))) + sched = sched.insert(50, ShiftFrequency(4.0e6, channel=self.config.drive(0))) + sched = sched.insert(55, SetPhase(3.14, channel=self.config.drive(0))) for i in range(2): - sched = sched.insert(60, Acquire(5, self.config.acquire(i), MemorySlot(i))) - sched = sched.insert(90, Play(lp0, self.config.drive(0))) + sched = sched.insert( + 60, Acquire(5, channel=self.config.acquire(i), mem_slot=MemorySlot(i)) + ) + sched = sched.insert(90, Play(lp0, channel=self.config.drive(0))) # test on Acquire only_acquire, no_acquire = self._filter_and_test_consistency( @@ -706,12 +734,14 @@ def test_filter_intervals(self): """Test filtering on intervals.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") - sched = sched.insert(0, Play(lp0, self.config.drive(0))) - sched = sched.insert(10, Play(lp0, self.config.drive(1))) - sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) + sched = sched.insert(0, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(1))) + sched = sched.insert(30, ShiftPhase(-1.57, channel=self.config.drive(0))) for i in range(2): - sched = sched.insert(60, Acquire(5, self.config.acquire(i), MemorySlot(i))) - sched = sched.insert(90, Play(lp0, self.config.drive(0))) + sched = sched.insert( + 60, Acquire(5, channel=self.config.acquire(i), mem_slot=MemorySlot(i)) + ) + sched = sched.insert(90, Play(lp0, channel=self.config.drive(0))) # split schedule into instructions occurring in (0,13), and those outside filtered, excluded = self._filter_and_test_consistency(sched, time_ranges=((0, 13),)) @@ -758,13 +788,15 @@ def test_filter_multiple(self): """Test filter composition.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") - sched = sched.insert(0, Play(lp0, self.config.drive(0))) - sched = sched.insert(10, Play(lp0, self.config.drive(1))) - sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) + sched = sched.insert(0, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(1))) + sched = sched.insert(30, ShiftPhase(-1.57, channel=self.config.drive(0))) for i in range(2): - sched = sched.insert(60, Acquire(5, self.config.acquire(i), MemorySlot(i))) + sched = sched.insert( + 60, Acquire(5, channel=self.config.acquire(i), mem_slot=MemorySlot(i)) + ) - sched = sched.insert(90, Play(lp0, self.config.drive(0))) + sched = sched.insert(90, Play(lp0, channel=self.config.drive(0))) # split instructions with filters on channel 0, of type Play # occurring in the time interval (25, 100) @@ -806,9 +838,9 @@ def test_custom_filters(self): """Test custom filters.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") - sched = sched.insert(0, Play(lp0, self.config.drive(0))) - sched = sched.insert(10, Play(lp0, self.config.drive(1))) - sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) + sched = sched.insert(0, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(1))) + sched = sched.insert(30, ShiftPhase(-1.57, channel=self.config.drive(0))) filtered, excluded = self._filter_and_test_consistency(sched, lambda x: True) for i in filtered.instructions: @@ -835,12 +867,14 @@ def test_empty_filters(self): """Test behavior on empty filters.""" lp0 = self.linear(duration=3, slope=0.2, intercept=0.1) sched = Schedule(name="fake_experiment") - sched = sched.insert(0, Play(lp0, self.config.drive(0))) - sched = sched.insert(10, Play(lp0, self.config.drive(1))) - sched = sched.insert(30, ShiftPhase(-1.57, self.config.drive(0))) + sched = sched.insert(0, Play(lp0, channel=self.config.drive(0))) + sched = sched.insert(10, Play(lp0, channel=self.config.drive(1))) + sched = sched.insert(30, ShiftPhase(-1.57, channel=self.config.drive(0))) for i in range(2): - sched = sched.insert(60, Acquire(5, self.config.acquire(i), MemorySlot(i))) - sched = sched.insert(90, Play(lp0, self.config.drive(0))) + sched = sched.insert( + 60, Acquire(5, channel=self.config.acquire(i), mem_slot=MemorySlot(i)) + ) + sched = sched.insert(90, Play(lp0, channel=self.config.drive(0))) # empty channels filtered, excluded = self._filter_and_test_consistency(sched, channels=[]) @@ -887,30 +921,31 @@ class TestScheduleEquality(BaseTestSchedule): def test_different_channels(self): """Test equality is False if different channels.""" self.assertNotEqual( - Schedule(ShiftPhase(0, DriveChannel(0))), Schedule(ShiftPhase(0, DriveChannel(1))) + Schedule(ShiftPhase(0, channel=DriveChannel(0))), + Schedule(ShiftPhase(0, channel=DriveChannel(1))), ) def test_same_time_equal(self): """Test equal if instruction at same time.""" self.assertEqual( - Schedule((0, ShiftPhase(0, DriveChannel(1)))), - Schedule((0, ShiftPhase(0, DriveChannel(1)))), + Schedule((0, ShiftPhase(0, channel=DriveChannel(1)))), + Schedule((0, ShiftPhase(0, channel=DriveChannel(1)))), ) def test_different_time_not_equal(self): """Test that not equal if instruction at different time.""" self.assertNotEqual( - Schedule((0, ShiftPhase(0, DriveChannel(1)))), - Schedule((1, ShiftPhase(0, DriveChannel(1)))), + Schedule((0, ShiftPhase(0, channel=DriveChannel(1)))), + Schedule((1, ShiftPhase(0, channel=DriveChannel(1)))), ) def test_single_channel_out_of_order(self): """Test that schedule with single channel equal when out of order.""" instructions = [ - (0, ShiftPhase(0, DriveChannel(0))), - (15, Play(Waveform(np.ones(10)), DriveChannel(0))), - (5, Play(Waveform(np.ones(10)), DriveChannel(0))), + (0, ShiftPhase(0, channel=DriveChannel(0))), + (15, Play(Waveform(np.ones(10)), channel=DriveChannel(0))), + (5, Play(Waveform(np.ones(10)), channel=DriveChannel(0))), ] self.assertEqual(Schedule(*instructions), Schedule(*reversed(instructions))) @@ -918,8 +953,8 @@ def test_single_channel_out_of_order(self): def test_multiple_channels_out_of_order(self): """Test that schedule with multiple channels equal when out of order.""" instructions = [ - (0, ShiftPhase(0, DriveChannel(1))), - (1, Acquire(10, AcquireChannel(0), MemorySlot(1))), + (0, ShiftPhase(0, channel=DriveChannel(1))), + (1, Acquire(10, channel=AcquireChannel(0), mem_slot=MemorySlot(1))), ] self.assertEqual(Schedule(*instructions), Schedule(*reversed(instructions))) @@ -928,19 +963,19 @@ def test_same_commands_on_two_channels_at_same_time_out_of_order(self): """Test that schedule with same commands on two channels at the same time equal when out of order.""" sched1 = Schedule() - sched1 = sched1.append(Delay(100, DriveChannel(1))) - sched1 = sched1.append(Delay(100, ControlChannel(1))) + sched1 = sched1.append(Delay(100, channel=DriveChannel(1))) + sched1 = sched1.append(Delay(100, channel=ControlChannel(1))) sched2 = Schedule() - sched2 = sched2.append(Delay(100, ControlChannel(1))) - sched2 = sched2.append(Delay(100, DriveChannel(1))) + sched2 = sched2.append(Delay(100, channel=ControlChannel(1))) + sched2 = sched2.append(Delay(100, channel=DriveChannel(1))) self.assertEqual(sched1, sched2) def test_different_name_equal(self): """Test that names are ignored when checking equality.""" self.assertEqual( - Schedule((0, ShiftPhase(0, DriveChannel(1), name="fc1")), name="s1"), - Schedule((0, ShiftPhase(0, DriveChannel(1), name="fc2")), name="s2"), + Schedule((0, ShiftPhase(0, channel=DriveChannel(1), name="fc1")), name="s1"), + Schedule((0, ShiftPhase(0, channel=DriveChannel(1), name="fc2")), name="s2"), ) diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py index 5918a6e6993..91a531bd7b3 100644 --- a/test/python/pulse/test_transforms.py +++ b/test/python/pulse/test_transforms.py @@ -56,41 +56,53 @@ def setUp(self): def test_align_measures(self): """Test that one acquire is delayed to match the time of the later acquire.""" sched = pulse.Schedule(name="fake_experiment") - sched.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True) - sched.insert(1, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - sched.insert(10, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) - sched.insert(10, Play(self.short_pulse, self.config.measure(0)), inplace=True) - sched.insert(11, Play(self.short_pulse, self.config.measure(0)), inplace=True) - sched.insert(10, Play(self.short_pulse, self.config.measure(1)), inplace=True) + sched.insert(0, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + sched.insert( + 1, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + sched.insert( + 10, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) + sched.insert(10, Play(self.short_pulse, channel=self.config.measure(0)), inplace=True) + sched.insert(11, Play(self.short_pulse, channel=self.config.measure(0)), inplace=True) + sched.insert(10, Play(self.short_pulse, channel=self.config.measure(1)), inplace=True) aligned = transforms.align_measures([sched])[0] self.assertEqual(aligned.name, "fake_experiment") ref = pulse.Schedule(name="fake_experiment") - ref.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True) - ref.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - ref.insert(10, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) - ref.insert(19, Play(self.short_pulse, self.config.measure(0)), inplace=True) - ref.insert(20, Play(self.short_pulse, self.config.measure(0)), inplace=True) - ref.insert(10, Play(self.short_pulse, self.config.measure(1)), inplace=True) + ref.insert(0, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + ref.insert( + 10, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + ref.insert( + 10, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) + ref.insert(19, Play(self.short_pulse, channel=self.config.measure(0)), inplace=True) + ref.insert(20, Play(self.short_pulse, channel=self.config.measure(0)), inplace=True) + ref.insert(10, Play(self.short_pulse, channel=self.config.measure(1)), inplace=True) self.assertEqual(aligned, ref) aligned = transforms.align_measures([sched], self.inst_map, align_time=20)[0] ref = pulse.Schedule(name="fake_experiment") - ref.insert(10, Play(self.short_pulse, self.config.drive(0)), inplace=True) - ref.insert(20, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - ref.insert(20, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) - ref.insert(29, Play(self.short_pulse, self.config.measure(0)), inplace=True) - ref.insert(30, Play(self.short_pulse, self.config.measure(0)), inplace=True) - ref.insert(20, Play(self.short_pulse, self.config.measure(1)), inplace=True) + ref.insert(10, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + ref.insert( + 20, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + ref.insert( + 20, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) + ref.insert(29, Play(self.short_pulse, channel=self.config.measure(0)), inplace=True) + ref.insert(30, Play(self.short_pulse, channel=self.config.measure(0)), inplace=True) + ref.insert(20, Play(self.short_pulse, channel=self.config.measure(1)), inplace=True) self.assertEqual(aligned, ref) def test_align_post_u3(self): """Test that acquires are scheduled no sooner than the duration of the longest X gate.""" sched = pulse.Schedule(name="fake_experiment") - sched = sched.insert(0, Play(self.short_pulse, self.config.drive(0))) - sched = sched.insert(1, Acquire(5, self.config.acquire(0), MemorySlot(0))) + sched = sched.insert(0, Play(self.short_pulse, channel=self.config.drive(0))) + sched = sched.insert(1, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0))) sched = transforms.align_measures([sched], self.inst_map)[0] for time, inst in sched.instructions: if isinstance(inst, Acquire): @@ -104,30 +116,54 @@ def test_multi_acquire(self): """Test that the last acquire is aligned to if multiple acquires occur on the same channel.""" sched = pulse.Schedule() - sched.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True) - sched.insert(4, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - sched.insert(20, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) - sched.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) + sched.insert(0, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + sched.insert( + 4, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + sched.insert( + 20, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) + sched.insert( + 10, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) aligned = transforms.align_measures([sched], self.inst_map) ref = pulse.Schedule() - ref.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True) - ref.insert(20, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - ref.insert(20, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) - ref.insert(26, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) + ref.insert(0, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + ref.insert( + 20, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + ref.insert( + 20, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) + ref.insert( + 26, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) self.assertEqual(aligned[0], ref) def test_multiple_acquires(self): """Test that multiple acquires are also aligned.""" sched = pulse.Schedule(name="fake_experiment") - sched.insert(0, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - sched.insert(5, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - sched.insert(10, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) + sched.insert( + 0, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + sched.insert( + 5, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + sched.insert( + 10, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) ref = pulse.Schedule() - ref.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - ref.insert(15, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) - ref.insert(10, Acquire(5, self.config.acquire(1), MemorySlot(1)), inplace=True) + ref.insert( + 10, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + ref.insert( + 15, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) + ref.insert( + 10, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1)), inplace=True + ) aligned = transforms.align_measures([sched], self.inst_map)[0] @@ -136,11 +172,15 @@ def test_multiple_acquires(self): def test_align_across_schedules(self): """Test that acquires are aligned together across multiple schedules.""" sched1 = pulse.Schedule(name="fake_experiment") - sched1 = sched1.insert(0, Play(self.short_pulse, self.config.drive(0))) - sched1 = sched1.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0))) + sched1 = sched1.insert(0, Play(self.short_pulse, channel=self.config.drive(0))) + sched1 = sched1.insert( + 10, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) + ) sched2 = pulse.Schedule(name="fake_experiment") - sched2 = sched2.insert(3, Play(self.short_pulse, self.config.drive(0))) - sched2 = sched2.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0))) + sched2 = sched2.insert(3, Play(self.short_pulse, channel=self.config.drive(0))) + sched2 = sched2.insert( + 25, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) + ) schedules = transforms.align_measures([sched1, sched2], self.inst_map) for time, inst in schedules[0].instructions: if isinstance(inst, Acquire): @@ -152,25 +192,35 @@ def test_align_across_schedules(self): def test_align_all(self): """Test alignment of all instructions in a schedule.""" sched0 = pulse.Schedule() - sched0.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True) - sched0.insert(10, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) + sched0.insert(0, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + sched0.insert( + 10, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) sched1 = pulse.Schedule() - sched1.insert(25, Play(self.short_pulse, self.config.drive(0)), inplace=True) - sched1.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) + sched1.insert(25, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + sched1.insert( + 25, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) all_aligned = transforms.align_measures([sched0, sched1], self.inst_map, align_all=True) ref1_aligned = pulse.Schedule() - ref1_aligned.insert(15, Play(self.short_pulse, self.config.drive(0)), inplace=True) - ref1_aligned.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) + ref1_aligned.insert(15, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True) + ref1_aligned.insert( + 25, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) self.assertEqual(all_aligned[0], ref1_aligned) self.assertEqual(all_aligned[1], sched1) ref1_not_aligned = pulse.Schedule() - ref1_not_aligned.insert(0, Play(self.short_pulse, self.config.drive(0)), inplace=True) - ref1_not_aligned.insert(25, Acquire(5, self.config.acquire(0), MemorySlot(0)), inplace=True) + ref1_not_aligned.insert( + 0, Play(self.short_pulse, channel=self.config.drive(0)), inplace=True + ) + ref1_not_aligned.insert( + 25, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)), inplace=True + ) all_not_aligned = transforms.align_measures( [sched0, sched1], @@ -183,11 +233,15 @@ def test_align_all(self): def test_measurement_at_zero(self): """Test that acquire at t=0 works.""" sched1 = pulse.Schedule(name="fake_experiment") - sched1 = sched1.insert(0, Play(self.short_pulse, self.config.drive(0))) - sched1 = sched1.insert(0, Acquire(5, self.config.acquire(0), MemorySlot(0))) + sched1 = sched1.insert(0, Play(self.short_pulse, channel=self.config.drive(0))) + sched1 = sched1.insert( + 0, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) + ) sched2 = pulse.Schedule(name="fake_experiment") - sched2 = sched2.insert(0, Play(self.short_pulse, self.config.drive(0))) - sched2 = sched2.insert(0, Acquire(5, self.config.acquire(0), MemorySlot(0))) + sched2 = sched2.insert(0, Play(self.short_pulse, channel=self.config.drive(0))) + sched2 = sched2.insert( + 0, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0)) + ) schedules = transforms.align_measures([sched1, sched2], max_calibration_duration=0) for time, inst in schedules[0].instructions: if isinstance(inst, Acquire): @@ -208,9 +262,9 @@ def setUp(self): samples=np.array([0.02739068], dtype=np.complex128), name="p0" ) sched = pulse.Schedule(name="fake_experiment") - sched = sched.insert(0, Play(self.short_pulse, self.config.drive(0))) - sched = sched.insert(5, Acquire(5, self.config.acquire(0), MemorySlot(0))) - sched = sched.insert(5, Acquire(5, self.config.acquire(1), MemorySlot(1))) + sched = sched.insert(0, Play(self.short_pulse, channel=self.config.drive(0))) + sched = sched.insert(5, Acquire(5, channel=self.config.acquire(0), mem_slot=MemorySlot(0))) + sched = sched.insert(5, Acquire(5, channel=self.config.acquire(1), mem_slot=MemorySlot(1))) self.sched = sched def test_add_implicit(self): @@ -243,7 +297,7 @@ def test_dont_add_all(self): def test_multiple_acquires(self): """Test for multiple acquires.""" sched = pulse.Schedule() - acq_q0 = pulse.Acquire(1200, AcquireChannel(0), MemorySlot(0)) + acq_q0 = pulse.Acquire(1200, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) sched += acq_q0 sched += acq_q0 << sched.duration sched = transforms.add_implicit_acquires(sched, meas_map=[[0]]) @@ -261,18 +315,18 @@ def test_padding_schedule(self): """Test padding schedule.""" delay = 10 sched = ( - Delay(delay, DriveChannel(0)).shift(10) - + Delay(delay, DriveChannel(0)).shift(10) - + Delay(delay, DriveChannel(1)).shift(10) + Delay(delay, channel=DriveChannel(0)).shift(10) + + Delay(delay, channel=DriveChannel(0)).shift(10) + + Delay(delay, channel=DriveChannel(1)).shift(10) ) ref_sched = ( sched # pylint: disable=unsupported-binary-operation - | Delay(delay, DriveChannel(0)) - | Delay(delay, DriveChannel(0)).shift(20) - | Delay(delay, DriveChannel(1)) + | Delay(delay, channel=DriveChannel(0)) + | Delay(delay, channel=DriveChannel(0)).shift(20) + | Delay(delay, channel=DriveChannel(1)) | Delay( # pylint: disable=unsupported-binary-operation - 2 * delay, DriveChannel(1) + 2 * delay, channel=DriveChannel(1) ).shift(20) ) @@ -286,18 +340,18 @@ def test_padding_schedule_inverse_order(self): """ delay = 10 sched = ( - Delay(delay, DriveChannel(1)).shift(10) - + Delay(delay, DriveChannel(0)).shift(10) - + Delay(delay, DriveChannel(0)).shift(10) + Delay(delay, channel=DriveChannel(1)).shift(10) + + Delay(delay, channel=DriveChannel(0)).shift(10) + + Delay(delay, channel=DriveChannel(0)).shift(10) ) ref_sched = ( sched # pylint: disable=unsupported-binary-operation - | Delay(delay, DriveChannel(0)) - | Delay(delay, DriveChannel(0)).shift(20) - | Delay(delay, DriveChannel(1)) + | Delay(delay, channel=DriveChannel(0)) + | Delay(delay, channel=DriveChannel(0)).shift(20) + | Delay(delay, channel=DriveChannel(1)) | Delay( # pylint: disable=unsupported-binary-operation - 2 * delay, DriveChannel(1) + 2 * delay, channel=DriveChannel(1) ).shift(20) ) @@ -307,9 +361,15 @@ def test_padding_until_less(self): """Test padding until time that is less than schedule duration.""" delay = 10 - sched = Delay(delay, DriveChannel(0)).shift(10) + Delay(delay, DriveChannel(1)) + sched = Delay(delay, channel=DriveChannel(0)).shift(10) + Delay( + delay, channel=DriveChannel(1) + ) - ref_sched = sched | Delay(delay, DriveChannel(0)) | Delay(5, DriveChannel(1)).shift(10) + ref_sched = ( + sched + | Delay(delay, channel=DriveChannel(0)) + | Delay(5, channel=DriveChannel(1)).shift(10) + ) self.assertEqual(transforms.pad(sched, until=15), ref_sched) @@ -317,13 +377,17 @@ def test_padding_until_greater(self): """Test padding until time that is greater than schedule duration.""" delay = 10 - sched = Delay(delay, DriveChannel(0)).shift(10) + Delay(delay, DriveChannel(1)) + sched = Delay(delay, channel=DriveChannel(0)).shift(10) + Delay( + delay, channel=DriveChannel(1) + ) ref_sched = ( sched # pylint: disable=unsupported-binary-operation - | Delay(delay, DriveChannel(0)) - | Delay(30, DriveChannel(0)).shift(20) - | Delay(40, DriveChannel(1)).shift(10) # pylint: disable=unsupported-binary-operation + | Delay(delay, channel=DriveChannel(0)) + | Delay(30, channel=DriveChannel(0)).shift(20) + | Delay(40, channel=DriveChannel(1)).shift( + 10 + ) # pylint: disable=unsupported-binary-operation ) self.assertEqual(transforms.pad(sched, until=50), ref_sched) @@ -331,9 +395,15 @@ def test_padding_until_greater(self): def test_padding_supplied_channels(self): """Test padding of only specified channels.""" delay = 10 - sched = Delay(delay, DriveChannel(0)).shift(10) + Delay(delay, DriveChannel(1)) + sched = Delay(delay, channel=DriveChannel(0)).shift(10) + Delay( + delay, channel=DriveChannel(1) + ) - ref_sched = sched | Delay(delay, DriveChannel(0)) | Delay(2 * delay, DriveChannel(2)) + ref_sched = ( + sched + | Delay(delay, channel=DriveChannel(0)) + | Delay(2 * delay, channel=DriveChannel(2)) + ) channels = [DriveChannel(0), DriveChannel(2)] @@ -342,19 +412,23 @@ def test_padding_supplied_channels(self): def test_padding_less_than_sched_duration(self): """Test that the until arg is respected even for less than the input schedule duration.""" delay = 10 - sched = Delay(delay, DriveChannel(0)) + Delay(delay, DriveChannel(0)).shift(20) - ref_sched = sched | pulse.Delay(5, DriveChannel(0)).shift(10) + sched = Delay(delay, channel=DriveChannel(0)) + Delay(delay, channel=DriveChannel(0)).shift( + 20 + ) + ref_sched = sched | pulse.Delay(5, channel=DriveChannel(0)).shift(10) self.assertEqual(transforms.pad(sched, until=15), ref_sched) def test_padding_prepended_delay(self): """Test that there is delay before the first instruction.""" delay = 10 - sched = Delay(delay, DriveChannel(0)).shift(10) + Delay(delay, DriveChannel(0)) + sched = Delay(delay, channel=DriveChannel(0)).shift(10) + Delay( + delay, channel=DriveChannel(0) + ) ref_sched = ( - Delay(delay, DriveChannel(0)) - + Delay(delay, DriveChannel(0)) - + Delay(delay, DriveChannel(0)) + Delay(delay, channel=DriveChannel(0)) + + Delay(delay, channel=DriveChannel(0)) + + Delay(delay, channel=DriveChannel(0)) ) self.assertEqual(transforms.pad(sched, until=30, inplace=True), ref_sched) @@ -363,15 +437,15 @@ def test_pad_no_delay_on_classical_io_channels(self): """Test padding does not apply to classical IO channels.""" delay = 10 sched = ( - Delay(delay, MemorySlot(0)).shift(20) - + Delay(delay, RegisterSlot(0)).shift(10) - + Delay(delay, SnapshotChannel()) + Delay(delay, channel=MemorySlot(0)).shift(20) + + Delay(delay, channel=RegisterSlot(0)).shift(10) + + Delay(delay, channel=SnapshotChannel()) ) ref_sched = ( - Delay(delay, MemorySlot(0)).shift(20) - + Delay(delay, RegisterSlot(0)).shift(10) - + Delay(delay, SnapshotChannel()) + Delay(delay, channel=MemorySlot(0)).shift(20) + + Delay(delay, channel=RegisterSlot(0)).shift(10) + + Delay(delay, channel=SnapshotChannel()) ) self.assertEqual(transforms.pad(sched, until=15), ref_sched) @@ -393,8 +467,8 @@ def test_with_duplicates(self): """Test compression of schedule.""" schedule = Schedule() drive_channel = DriveChannel(0) - schedule += Play(Waveform([0.0, 0.1]), drive_channel) - schedule += Play(Waveform([0.0, 0.1]), drive_channel) + schedule += Play(Waveform([0.0, 0.1]), channel=drive_channel) + schedule += Play(Waveform([0.0, 0.1]), channel=drive_channel) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -408,9 +482,9 @@ def test_sample_pulse_with_clipping(self): """Test sample pulses with clipping.""" schedule = Schedule() drive_channel = DriveChannel(0) - schedule += Play(Waveform([0.0, 1.0]), drive_channel) - schedule += Play(Waveform([0.0, 1.001], epsilon=1e-3), drive_channel) - schedule += Play(Waveform([0.0, 1.0000000001]), drive_channel) + schedule += Play(Waveform([0.0, 1.0]), channel=drive_channel) + schedule += Play(Waveform([0.0, 1.001], epsilon=1e-3), channel=drive_channel) + schedule += Play(Waveform([0.0, 1.0000000001]), channel=drive_channel) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -424,9 +498,9 @@ def test_no_duplicates(self): """Test with no pulse duplicates.""" schedule = Schedule() drive_channel = DriveChannel(0) - schedule += Play(Waveform([0.0, 1.0]), drive_channel) - schedule += Play(Waveform([0.0, 0.9]), drive_channel) - schedule += Play(Waveform([0.0, 0.3]), drive_channel) + schedule += Play(Waveform([0.0, 1.0]), channel=drive_channel) + schedule += Play(Waveform([0.0, 0.9]), channel=drive_channel) + schedule += Play(Waveform([0.0, 0.3]), channel=drive_channel) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -437,14 +511,26 @@ def test_parametric_pulses_with_duplicates(self): """Test with parametric pulses.""" schedule = Schedule() drive_channel = DriveChannel(0) - schedule += Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), drive_channel) - schedule += Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), drive_channel) - schedule += Play(GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), drive_channel) - schedule += Play(GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), drive_channel) - schedule += Play(Constant(duration=150, amp=0.5, angle=0.7), drive_channel) - schedule += Play(Constant(duration=150, amp=0.5, angle=0.7), drive_channel) - schedule += Play(Drag(duration=25, amp=0.4, angle=-0.3, sigma=7.8, beta=4), drive_channel) - schedule += Play(Drag(duration=25, amp=0.4, angle=-0.3, sigma=7.8, beta=4), drive_channel) + schedule += Play( + Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), channel=drive_channel + ) + schedule += Play( + Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), channel=drive_channel + ) + schedule += Play( + GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), channel=drive_channel + ) + schedule += Play( + GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), channel=drive_channel + ) + schedule += Play(Constant(duration=150, amp=0.5, angle=0.7), channel=drive_channel) + schedule += Play(Constant(duration=150, amp=0.5, angle=0.7), channel=drive_channel) + schedule += Play( + Drag(duration=25, amp=0.4, angle=-0.3, sigma=7.8, beta=4), channel=drive_channel + ) + schedule += Play( + Drag(duration=25, amp=0.4, angle=-0.3, sigma=7.8, beta=4), channel=drive_channel + ) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -456,14 +542,26 @@ def test_parametric_pulses_with_no_duplicates(self): """Test parametric pulses with no duplicates.""" schedule = Schedule() drive_channel = DriveChannel(0) - schedule += Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), drive_channel) - schedule += Play(Gaussian(duration=25, sigma=4, amp=0.49, angle=np.pi / 2), drive_channel) - schedule += Play(GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), drive_channel) - schedule += Play(GaussianSquare(duration=150, amp=0.19, sigma=8, width=140), drive_channel) - schedule += Play(Constant(duration=150, amp=0.5, angle=0.3), drive_channel) - schedule += Play(Constant(duration=150, amp=0.51, angle=0.3), drive_channel) - schedule += Play(Drag(duration=25, amp=0.5, angle=0.5, sigma=7.8, beta=4), drive_channel) - schedule += Play(Drag(duration=25, amp=0.5, angle=0.51, sigma=7.8, beta=4), drive_channel) + schedule += Play( + Gaussian(duration=25, sigma=4, amp=0.5, angle=np.pi / 2), channel=drive_channel + ) + schedule += Play( + Gaussian(duration=25, sigma=4, amp=0.49, angle=np.pi / 2), channel=drive_channel + ) + schedule += Play( + GaussianSquare(duration=150, amp=0.2, sigma=8, width=140), channel=drive_channel + ) + schedule += Play( + GaussianSquare(duration=150, amp=0.19, sigma=8, width=140), channel=drive_channel + ) + schedule += Play(Constant(duration=150, amp=0.5, angle=0.3), channel=drive_channel) + schedule += Play(Constant(duration=150, amp=0.51, angle=0.3), channel=drive_channel) + schedule += Play( + Drag(duration=25, amp=0.5, angle=0.5, sigma=7.8, beta=4), channel=drive_channel + ) + schedule += Play( + Drag(duration=25, amp=0.5, angle=0.51, sigma=7.8, beta=4), channel=drive_channel + ) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -473,8 +571,8 @@ def test_parametric_pulses_with_no_duplicates(self): def test_with_different_channels(self): """Test with different channels.""" schedule = Schedule() - schedule += Play(Waveform([0.0, 0.1]), DriveChannel(0)) - schedule += Play(Waveform([0.0, 0.1]), DriveChannel(1)) + schedule += Play(Waveform([0.0, 0.1]), channel=DriveChannel(0)) + schedule += Play(Waveform([0.0, 0.1]), channel=DriveChannel(1)) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -485,8 +583,8 @@ def test_with_different_channels(self): def test_sample_pulses_with_tolerance(self): """Test sample pulses with tolerance.""" schedule = Schedule() - schedule += Play(Waveform([0.0, 0.1001], epsilon=1e-3), DriveChannel(0)) - schedule += Play(Waveform([0.0, 0.1], epsilon=1e-3), DriveChannel(1)) + schedule += Play(Waveform([0.0, 0.1001], epsilon=1e-3), channel=DriveChannel(0)) + schedule += Play(Waveform([0.0, 0.1], epsilon=1e-3), channel=DriveChannel(1)) compressed_schedule = transforms.compress_pulses([schedule]) original_pulse_ids = get_pulse_ids([schedule]) @@ -500,9 +598,9 @@ def test_multiple_schedules(self): for _ in range(2): schedule = Schedule() drive_channel = DriveChannel(0) - schedule += Play(Waveform([0.0, 0.1]), drive_channel) - schedule += Play(Waveform([0.0, 0.1]), drive_channel) - schedule += Play(Waveform([0.0, 0.2]), drive_channel) + schedule += Play(Waveform([0.0, 0.1]), channel=drive_channel) + schedule += Play(Waveform([0.0, 0.1]), channel=drive_channel) + schedule += Play(Waveform([0.0, 0.2]), channel=drive_channel) schedules.append(schedule) compressed_schedule = transforms.compress_pulses(schedules) @@ -523,17 +621,17 @@ def test_align_sequential(self): d1 = pulse.DriveChannel(1) schedule = pulse.Schedule() - schedule.insert(1, instructions.Delay(3, d0), inplace=True) - schedule.insert(4, instructions.Delay(5, d1), inplace=True) - schedule.insert(12, instructions.Delay(7, d0), inplace=True) + schedule.insert(1, instructions.Delay(3, channel=d0), inplace=True) + schedule.insert(4, instructions.Delay(5, channel=d1), inplace=True) + schedule.insert(12, instructions.Delay(7, channel=d0), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(8, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(8, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(3, instructions.Delay(5, d1), inplace=True) + reference.insert(3, instructions.Delay(5, channel=d1), inplace=True) self.assertEqual(schedule, reference) @@ -545,17 +643,17 @@ def test_align_sequential_with_barrier(self): d1 = pulse.DriveChannel(1) schedule = pulse.Schedule() - schedule.insert(1, instructions.Delay(3, d0), inplace=True) + schedule.insert(1, instructions.Delay(3, channel=d0), inplace=True) schedule.append(directives.RelativeBarrier(d0, d1), inplace=True) - schedule.insert(4, instructions.Delay(5, d1), inplace=True) - schedule.insert(12, instructions.Delay(7, d0), inplace=True) + schedule.insert(4, instructions.Delay(5, channel=d1), inplace=True) + schedule.insert(12, instructions.Delay(7, channel=d0), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(0, instructions.Delay(3, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) reference.insert(3, directives.RelativeBarrier(d0, d1), inplace=True) - reference.insert(3, instructions.Delay(5, d1), inplace=True) - reference.insert(8, instructions.Delay(7, d0), inplace=True) + reference.insert(3, instructions.Delay(5, channel=d1), inplace=True) + reference.insert(8, instructions.Delay(7, channel=d0), inplace=True) self.assertEqual(schedule, reference) @@ -572,23 +670,23 @@ def test_align_left(self): d2 = pulse.DriveChannel(2) schedule = pulse.Schedule() - schedule.insert(1, instructions.Delay(3, d0), inplace=True) - schedule.insert(17, instructions.Delay(11, d2), inplace=True) + schedule.insert(1, instructions.Delay(3, channel=d0), inplace=True) + schedule.insert(17, instructions.Delay(11, channel=d2), inplace=True) sched_grouped = pulse.Schedule() - sched_grouped += instructions.Delay(5, d1) - sched_grouped += instructions.Delay(7, d0) + sched_grouped += instructions.Delay(5, channel=d1) + sched_grouped += instructions.Delay(7, channel=d0) schedule.append(sched_grouped, inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(3, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(3, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(3, instructions.Delay(5, d1), inplace=True) + reference.insert(3, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(0, instructions.Delay(11, d2), inplace=True) + reference.insert(0, instructions.Delay(11, channel=d2), inplace=True) self.assertEqual(schedule, reference) @@ -601,24 +699,24 @@ def test_align_left_with_barrier(self): d2 = pulse.DriveChannel(2) schedule = pulse.Schedule() - schedule.insert(1, instructions.Delay(3, d0), inplace=True) + schedule.insert(1, instructions.Delay(3, channel=d0), inplace=True) schedule.append(directives.RelativeBarrier(d0, d1, d2), inplace=True) - schedule.insert(17, instructions.Delay(11, d2), inplace=True) + schedule.insert(17, instructions.Delay(11, channel=d2), inplace=True) sched_grouped = pulse.Schedule() - sched_grouped += instructions.Delay(5, d1) - sched_grouped += instructions.Delay(7, d0) + sched_grouped += instructions.Delay(5, channel=d1) + sched_grouped += instructions.Delay(7, channel=d0) schedule.append(sched_grouped, inplace=True) schedule = transforms.remove_directives(context.align(schedule)) reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(3, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(3, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference = reference.insert(3, instructions.Delay(5, d1)) + reference = reference.insert(3, instructions.Delay(5, channel=d1)) # d2 - reference = reference.insert(3, instructions.Delay(11, d2)) + reference = reference.insert(3, instructions.Delay(11, channel=d2)) self.assertEqual(schedule, reference) @@ -635,24 +733,24 @@ def test_align_right(self): d2 = pulse.DriveChannel(2) schedule = pulse.Schedule() - schedule.insert(1, instructions.Delay(3, d0), inplace=True) - schedule.insert(17, instructions.Delay(11, d2), inplace=True) + schedule.insert(1, instructions.Delay(3, channel=d0), inplace=True) + schedule.insert(17, instructions.Delay(11, channel=d2), inplace=True) sched_grouped = pulse.Schedule() - sched_grouped.insert(2, instructions.Delay(5, d1), inplace=True) - sched_grouped += instructions.Delay(7, d0) + sched_grouped.insert(2, instructions.Delay(5, channel=d1), inplace=True) + sched_grouped += instructions.Delay(7, channel=d0) schedule.append(sched_grouped, inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() # d0 - reference.insert(1, instructions.Delay(3, d0), inplace=True) - reference.insert(4, instructions.Delay(7, d0), inplace=True) + reference.insert(1, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(4, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(6, instructions.Delay(5, d1), inplace=True) + reference.insert(6, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(0, instructions.Delay(11, d2), inplace=True) + reference.insert(0, instructions.Delay(11, channel=d2), inplace=True) self.assertEqual(schedule, reference) def test_align_right_with_barrier(self): @@ -664,25 +762,25 @@ def test_align_right_with_barrier(self): d2 = pulse.DriveChannel(2) schedule = pulse.Schedule() - schedule.insert(1, instructions.Delay(3, d0), inplace=True) + schedule.insert(1, instructions.Delay(3, channel=d0), inplace=True) schedule.append(directives.RelativeBarrier(d0, d1, d2), inplace=True) - schedule.insert(17, instructions.Delay(11, d2), inplace=True) + schedule.insert(17, instructions.Delay(11, channel=d2), inplace=True) sched_grouped = pulse.Schedule() - sched_grouped.insert(2, instructions.Delay(5, d1), inplace=True) - sched_grouped += instructions.Delay(7, d0) + sched_grouped.insert(2, instructions.Delay(5, channel=d1), inplace=True) + sched_grouped += instructions.Delay(7, channel=d0) schedule.append(sched_grouped, inplace=True) schedule = transforms.remove_directives(context.align(schedule)) reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(7, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(7, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(9, instructions.Delay(5, d1), inplace=True) + reference.insert(9, instructions.Delay(5, channel=d1), inplace=True) # d2 - reference.insert(3, instructions.Delay(11, d2), inplace=True) + reference.insert(3, instructions.Delay(11, channel=d2), inplace=True) self.assertEqual(schedule, reference) @@ -698,13 +796,13 @@ def test_equispaced_with_short_duration(self): schedule = pulse.Schedule() for _ in range(3): - schedule.append(Delay(10, d0), inplace=True) + schedule.append(Delay(10, channel=d0), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(0, Delay(10, d0), inplace=True) - reference.insert(10, Delay(10, d0), inplace=True) - reference.insert(20, Delay(10, d0), inplace=True) + reference.insert(0, Delay(10, channel=d0), inplace=True) + reference.insert(10, Delay(10, channel=d0), inplace=True) + reference.insert(20, Delay(10, channel=d0), inplace=True) self.assertEqual(schedule, reference) @@ -716,13 +814,13 @@ def test_equispaced_with_longer_duration(self): schedule = pulse.Schedule() for _ in range(3): - schedule.append(Delay(10, d0), inplace=True) + schedule.append(Delay(10, channel=d0), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(0, Delay(10, d0), inplace=True) - reference.insert(20, Delay(10, d0), inplace=True) - reference.insert(40, Delay(10, d0), inplace=True) + reference.insert(0, Delay(10, channel=d0), inplace=True) + reference.insert(20, Delay(10, channel=d0), inplace=True) + reference.insert(40, Delay(10, channel=d0), inplace=True) self.assertEqual(schedule, reference) @@ -735,13 +833,13 @@ def test_equispaced_with_multiple_channels_short_duration(self): d1 = pulse.DriveChannel(1) schedule = pulse.Schedule() - schedule.append(Delay(10, d0), inplace=True) - schedule.append(Delay(20, d1), inplace=True) + schedule.append(Delay(10, channel=d0), inplace=True) + schedule.append(Delay(20, channel=d1), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(0, Delay(10, d0), inplace=True) - reference.insert(0, Delay(20, d1), inplace=True) + reference.insert(0, Delay(10, channel=d0), inplace=True) + reference.insert(0, Delay(20, channel=d1), inplace=True) self.assertEqual(schedule, reference) @@ -754,13 +852,13 @@ def test_equispaced_with_multiple_channels_longer_duration(self): d1 = pulse.DriveChannel(1) schedule = pulse.Schedule() - schedule.append(Delay(10, d0), inplace=True) - schedule.append(Delay(20, d1), inplace=True) + schedule.append(Delay(10, channel=d0), inplace=True) + schedule.append(Delay(20, channel=d1), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(0, Delay(10, d0), inplace=True) - reference.insert(10, Delay(20, d1), inplace=True) + reference.insert(0, Delay(10, channel=d0), inplace=True) + reference.insert(10, Delay(20, channel=d1), inplace=True) self.assertEqual(schedule, reference) @@ -781,13 +879,13 @@ def test_numerical_with_short_duration(self): schedule = pulse.Schedule() for _ in range(3): - schedule.append(Delay(10, d0), inplace=True) + schedule.append(Delay(10, channel=d0), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(0, Delay(10, d0), inplace=True) - reference.insert(10, Delay(10, d0), inplace=True) - reference.insert(20, Delay(10, d0), inplace=True) + reference.insert(0, Delay(10, channel=d0), inplace=True) + reference.insert(10, Delay(10, channel=d0), inplace=True) + reference.insert(20, Delay(10, channel=d0), inplace=True) self.assertEqual(schedule, reference) @@ -799,13 +897,13 @@ def test_numerical_with_longer_duration(self): schedule = pulse.Schedule() for _ in range(3): - schedule.append(Delay(10, d0), inplace=True) + schedule.append(Delay(10, channel=d0), inplace=True) schedule = context.align(schedule) reference = pulse.Schedule() - reference.insert(15, Delay(10, d0), inplace=True) - reference.insert(35, Delay(10, d0), inplace=True) - reference.insert(55, Delay(10, d0), inplace=True) + reference.insert(15, Delay(10, channel=d0), inplace=True) + reference.insert(35, Delay(10, channel=d0), inplace=True) + reference.insert(55, Delay(10, channel=d0), inplace=True) self.assertEqual(schedule, reference) @@ -821,11 +919,11 @@ def test_flatten(self): d1 = pulse.DriveChannel(1) schedule = pulse.Schedule() - schedule += instructions.Delay(3, d0) + schedule += instructions.Delay(3, channel=d0) grouped = pulse.Schedule() - grouped += instructions.Delay(5, d1) - grouped += instructions.Delay(7, d0) + grouped += instructions.Delay(5, channel=d1) + grouped += instructions.Delay(7, channel=d0) # include a grouped schedule grouped = schedule + grouped @@ -838,10 +936,10 @@ def test_flatten(self): reference = pulse.Schedule() # d0 - reference.insert(0, instructions.Delay(3, d0), inplace=True) - reference.insert(3, instructions.Delay(7, d0), inplace=True) + reference.insert(0, instructions.Delay(3, channel=d0), inplace=True) + reference.insert(3, instructions.Delay(7, channel=d0), inplace=True) # d1 - reference.insert(0, instructions.Delay(5, d1), inplace=True) + reference.insert(0, instructions.Delay(5, channel=d1), inplace=True) self.assertEqual(flattened, reference) self.assertNotEqual(grouped, reference) @@ -869,13 +967,13 @@ def test_remove_directives(self): schedule = pulse.Schedule() schedule += _TestDirective(d0, d1) - schedule += instructions.Delay(3, d0) + schedule += instructions.Delay(3, channel=d0) schedule += _TestDirective(d0, d1) schedule = transforms.remove_directives(schedule) reference = pulse.Schedule() # d0 - reference += instructions.Delay(3, d0) + reference += instructions.Delay(3, channel=d0) self.assertEqual(schedule, reference) diff --git a/test/python/qobj/test_pulse_converter.py b/test/python/qobj/test_pulse_converter.py index cacbde2cd8b..5f3f7e0581e 100644 --- a/test/python/qobj/test_pulse_converter.py +++ b/test/python/qobj/test_pulse_converter.py @@ -57,7 +57,7 @@ class TestInstructionToQobjConverter(QiskitTestCase): def test_drive_instruction(self): """Test converted qobj from Play.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play(Waveform(np.arange(0, 0.01), name="linear"), DriveChannel(0)) + instruction = Play(Waveform(np.arange(0, 0.01), name="linear"), channel=DriveChannel(0)) valid_qobj = PulseQobjInstruction(name="linear", ch="d0", t0=0) self.assertEqual(converter(0, instruction), valid_qobj) @@ -66,7 +66,9 @@ def test_gaussian_pulse_instruction(self): amp = 0.3 angle = -0.7 converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play(Gaussian(duration=25, sigma=15, amp=amp, angle=angle), DriveChannel(0)) + instruction = Play( + Gaussian(duration=25, sigma=15, amp=amp, angle=angle), channel=DriveChannel(0) + ) valid_qobj = PulseQobjInstruction( name="parametric_pulse", pulse_shape="gaussian", @@ -83,7 +85,7 @@ def test_gaussian_square_pulse_instruction(self): angle = -0.6 instruction = Play( GaussianSquare(duration=1500, sigma=15, amp=amp, width=1300, angle=angle), - MeasureChannel(1), + channel=MeasureChannel(1), ) valid_qobj = PulseQobjInstruction( @@ -103,7 +105,7 @@ def test_gaussian_square_pulse_instruction(self): def test_constant_pulse_instruction(self): """Test that parametric pulses are correctly converted to PulseQobjInstructions.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Play(Constant(duration=25, amp=1, angle=np.pi), ControlChannel(2)) + instruction = Play(Constant(duration=25, amp=1, angle=np.pi), channel=ControlChannel(2)) valid_qobj = PulseQobjInstruction( name="parametric_pulse", @@ -120,7 +122,7 @@ def test_drag_pulse_instruction(self): angle = -0.6 converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) instruction = Play( - Drag(duration=25, sigma=15, amp=amp, angle=angle, beta=0.5), DriveChannel(0) + Drag(duration=25, sigma=15, amp=amp, angle=angle, beta=0.5), channel=DriveChannel(0) ) valid_qobj = PulseQobjInstruction( @@ -136,13 +138,13 @@ def test_frame_change(self): """Test converted qobj from ShiftPhase.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) valid_qobj = PulseQobjInstruction(name="fc", ch="d0", t0=0, phase=0.1) - instruction = ShiftPhase(0.1, DriveChannel(0)) + instruction = ShiftPhase(0.1, channel=DriveChannel(0)) self.assertEqual(converter(0, instruction), valid_qobj) def test_set_phase(self): """Test converted qobj from ShiftPhase.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = SetPhase(3.14, DriveChannel(0)) + instruction = SetPhase(3.14, channel=DriveChannel(0)) valid_qobj = PulseQobjInstruction(name="setp", ch="d0", t0=0, phase=3.14) @@ -151,7 +153,7 @@ def test_set_phase(self): def test_set_frequency(self): """Test converted qobj from SetFrequency.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = SetFrequency(8.0e9, DriveChannel(0)) + instruction = SetFrequency(8.0e9, channel=DriveChannel(0)) valid_qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) @@ -160,7 +162,7 @@ def test_set_frequency(self): def test_shift_frequency(self): """Test converted qobj from ShiftFrequency.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = ShiftFrequency(8.0e9, DriveChannel(0)) + instruction = ShiftFrequency(8.0e9, channel=DriveChannel(0)) valid_qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) @@ -169,14 +171,16 @@ def test_shift_frequency(self): def test_acquire(self): """Test converted qobj from AcquireInstruction.""" converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2) - instruction = Acquire(10, AcquireChannel(0), MemorySlot(0), RegisterSlot(0)) + instruction = Acquire( + 10, channel=AcquireChannel(0), mem_slot=MemorySlot(0), reg_slot=RegisterSlot(0) + ) valid_qobj = PulseQobjInstruction( name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0], register_slot=[0] ) self.assertEqual(converter(0, instruction), valid_qobj) # without register - instruction = Acquire(10, AcquireChannel(0), MemorySlot(0)) + instruction = Acquire(10, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) valid_qobj = PulseQobjInstruction( name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0] ) @@ -207,7 +211,7 @@ def setUp(self): def test_drive_instruction(self): """Test converted qobj from PulseInstruction.""" - instruction = Play(self.linear, DriveChannel(0)) + instruction = Play(self.linear, channel=DriveChannel(0)) qobj = PulseQobjInstruction(name="linear", ch="d0", t0=10) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.instructions[0][-1], instruction) @@ -216,7 +220,7 @@ def test_parametric_pulses(self): """Test converted qobj from ParametricInstruction.""" instruction = Play( Gaussian(duration=25, sigma=15, amp=0.5, angle=np.pi / 2, name="pulse1"), - DriveChannel(0), + channel=DriveChannel(0), ) qobj = PulseQobjInstruction( name="parametric_pulse", @@ -253,14 +257,14 @@ def test_frame_change(self): qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1) converted_instruction = self.converter(qobj) - instruction = ShiftPhase(0.1, MeasureChannel(0)) + instruction = ShiftPhase(0.1, channel=MeasureChannel(0)) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) self.assertEqual(converted_instruction.instructions[0][-1], instruction) def test_parameterized_frame_change(self): """Test converted qobj from ShiftPhase.""" - instruction = ShiftPhase(4.0, MeasureChannel(0)) + instruction = ShiftPhase(4.0, channel=MeasureChannel(0)) shifted = instruction << 10 qobj = PulseQobjInstruction(name="fc", ch="m0", t0=10, phase="P1*2") @@ -280,7 +284,7 @@ def test_set_phase(self): qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase=3.14) converted_instruction = self.converter(qobj) - instruction = SetPhase(3.14, MeasureChannel(0)) + instruction = SetPhase(3.14, channel=MeasureChannel(0)) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 0) self.assertEqual(converted_instruction.instructions[0][-1], instruction) @@ -294,14 +298,14 @@ def test_parameterized_set_phase(self): bind_dict = {converted_instruction.get_parameters("p")[0]: 3.14} evaluated_instruction = converted_instruction.assign_parameters(bind_dict) - instruction = SetPhase(3.14 / 2, MeasureChannel(0)) + instruction = SetPhase(3.14 / 2, channel=MeasureChannel(0)) self.assertEqual(evaluated_instruction.start_time, 0) self.assertEqual(evaluated_instruction.duration, 0) self.assertEqual(evaluated_instruction.instructions[0][-1], instruction) def test_set_frequency(self): """Test converted qobj from SetFrequency.""" - instruction = SetFrequency(8.0e9, DriveChannel(0)) + instruction = SetFrequency(8.0e9, channel=DriveChannel(0)) qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0) converted_instruction = self.converter(qobj) @@ -322,7 +326,7 @@ def test_parameterized_set_frequency(self): bind_dict = {converted_instruction.get_parameters("f")[0]: 2.0} evaluated_instruction = converted_instruction.assign_parameters(bind_dict) - instruction = SetFrequency(2.0e9, DriveChannel(0)) + instruction = SetFrequency(2.0e9, channel=DriveChannel(0)) self.assertEqual(evaluated_instruction.start_time, 2) self.assertEqual(evaluated_instruction.duration, 2) @@ -330,7 +334,7 @@ def test_parameterized_set_frequency(self): def test_shift_frequency(self): """Test converted qobj from ShiftFrequency.""" - instruction = ShiftFrequency(8.0e9, DriveChannel(0)) + instruction = ShiftFrequency(8.0e9, channel=DriveChannel(0)) qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0) converted_instruction = self.converter(qobj) @@ -342,7 +346,7 @@ def test_shift_frequency(self): def test_parameterized_shift_frequency(self): """Test converted qobj from ShiftFrequency, with a parameterized frequency.""" - instruction = ShiftFrequency(8.0e9, DriveChannel(0)) + instruction = ShiftFrequency(8.0e9, channel=DriveChannel(0)) qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=1, frequency="f / 1000") self.assertTrue("frequency" in qobj.to_dict()) @@ -353,7 +357,7 @@ def test_parameterized_shift_frequency(self): bind_dict = {converted_instruction.get_parameters("f")[0]: 3.14} evaluated_instruction = converted_instruction.assign_parameters(bind_dict) - instruction = ShiftFrequency(3.14e6, DriveChannel(0)) + instruction = ShiftFrequency(3.14e6, channel=DriveChannel(0)) self.assertEqual(evaluated_instruction.start_time, 1) self.assertEqual(evaluated_instruction.duration, 1) @@ -361,7 +365,7 @@ def test_parameterized_shift_frequency(self): def test_delay(self): """Test converted qobj from Delay.""" - instruction = Delay(10, DriveChannel(0)) + instruction = Delay(10, channel=DriveChannel(0)) qobj = PulseQobjInstruction(name="delay", ch="d0", t0=0, duration=10) converted_instruction = self.converter(qobj) @@ -376,9 +380,9 @@ def test_acquire(self): for i in range(self.num_qubits): schedule |= Acquire( 10, - AcquireChannel(i), - MemorySlot(i), - RegisterSlot(i), + channel=AcquireChannel(i), + mem_slot=MemorySlot(i), + reg_slot=RegisterSlot(i), kernel=Kernel(name="test_kern", test_params="test"), discriminator=Discriminator(name="test_disc", test_params=1.0), ) diff --git a/test/python/qpy/test_block_load_from_qpy.py b/test/python/qpy/test_block_load_from_qpy.py index 10c1b8eda1e..ecdd0db69fc 100644 --- a/test/python/qpy/test_block_load_from_qpy.py +++ b/test/python/qpy/test_block_load_from_qpy.py @@ -196,8 +196,8 @@ def test_called_schedule(self): Thus referenced Schedule is still QPY compatible. """ refsched = Schedule() - refsched.insert(20, Play(Constant(100, 0.1), DriveChannel(0))) - refsched.insert(50, Play(Constant(100, 0.1), DriveChannel(1))) + refsched.insert(20, Play(Constant(100, 0.1), channel=DriveChannel(0))) + refsched.insert(50, Play(Constant(100, 0.1), channel=DriveChannel(1))) with builder.build() as test_sched: builder.call(refsched, name="test_ref") diff --git a/test/python/scheduler/test_basic_scheduler.py b/test/python/scheduler/test_basic_scheduler.py index 16ec00927c6..36f8e722893 100644 --- a/test/python/scheduler/test_basic_scheduler.py +++ b/test/python/scheduler/test_basic_scheduler.py @@ -237,7 +237,7 @@ def test_measure_combined(self): (2, self.inst_map.get("cx", [0, 1])), (24, self.inst_map.get("measure", [0, 1])), (34, self.inst_map.get("measure", [0, 1]).filter(channels=[MeasureChannel(1)])), - (34, Acquire(10, AcquireChannel(1), MemorySlot(1))), + (34, Acquire(10, channel=AcquireChannel(1), mem_slot=MemorySlot(1))), ) self.assertEqual(sched.instructions, expected.instructions) @@ -362,7 +362,7 @@ def test_parametric_input(self): qc = QuantumCircuit(qr) qc.append(Gate("gauss", 1, []), qargs=[qr[0]]) custom_gauss = Schedule( - Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), DriveChannel(0)) + Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), channel=DriveChannel(0)) ) self.inst_map.add("gauss", [0], custom_gauss) sched = schedule(qc, self.backend, inst_map=self.inst_map) @@ -375,13 +375,17 @@ def test_pulse_gates(self): qc.append(U2Gate(0, 0), [q[0]]) qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) - qc.add_calibration("u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(0))), [0, 0]) - qc.add_calibration("u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1))), [0, 0]) + qc.add_calibration( + "u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), channel=DriveChannel(0))), [0, 0] + ) + qc.add_calibration( + "u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), channel=DriveChannel(1))), [0, 0] + ) sched = schedule(qc, self.backend) expected = Schedule( - Play(Gaussian(28, 0.2, 4), DriveChannel(0)), - (28, Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1)))), + Play(Gaussian(28, 0.2, 4), channel=DriveChannel(0)), + (28, Schedule(Play(Gaussian(28, 0.2, 4), channel=DriveChannel(1)))), ) self.assertEqual(sched.instructions, expected.instructions) @@ -393,8 +397,8 @@ def test_calibrated_measurements(self): qc.append(U2Gate(0, 0), [q[0]]) qc.measure(q[0], c[0]) - meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) - meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) + meas_sched = Play(Gaussian(1200, 0.2, 4), channel=MeasureChannel(0)) + meas_sched |= Acquire(1200, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) qc.add_calibration("measure", [0], meas_sched) sched = schedule(qc, self.backend) @@ -410,8 +414,8 @@ def test_subset_calibrated_measurements(self): qc.measure(2, 2) meas_scheds = [] for qubit in [0, 2]: - meas = Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) + Acquire( - 1200, AcquireChannel(qubit), MemorySlot(qubit) + meas = Play(Gaussian(1200, 0.2, 4), channel=MeasureChannel(qubit)) + Acquire( + 1200, channel=AcquireChannel(qubit), mem_slot=MemorySlot(qubit) ) meas_scheds.append(meas) qc.add_calibration("measure", [qubit], meas) @@ -429,8 +433,8 @@ def test_clbits_of_calibrated_measurements(self): qc = QuantumCircuit(q, c) qc.measure(q[0], c[1]) - meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) - meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) + meas_sched = Play(Gaussian(1200, 0.2, 4), channel=MeasureChannel(0)) + meas_sched |= Acquire(1200, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) qc.add_calibration("measure", [0], meas_sched) sched = schedule(qc, self.backend) @@ -499,7 +503,7 @@ def test_schedule_block_in_instmap(self): sched = schedule(qc, self.backend, inst_map=instmap) ref_sched = Schedule() - ref_sched += Play(Gaussian(100, 0.1, 10), DriveChannel(0)) + ref_sched += Play(Gaussian(100, 0.1, 10), channel=DriveChannel(0)) self.assertEqual(sched, ref_sched) @@ -562,7 +566,7 @@ def test_alap_pass(self): 0 + 16 + 16 + 64, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(0), + channel=MeasureChannel(0), name="pulse_2", ), ), @@ -570,12 +574,12 @@ def test_alap_pass(self): 0 + 16 + 16 + 64, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(1), + channel=MeasureChannel(1), name="pulse_2", ), ), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), + (0 + 16 + 16 + 64, Acquire(1792, channel=AcquireChannel(0), mem_slot=MemorySlot(0))), + (0 + 16 + 16 + 64, Acquire(1792, channel=AcquireChannel(1), mem_slot=MemorySlot(1))), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -695,7 +699,7 @@ def test_asap_pass(self): 0 + 16 + 16 + 64, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(0), + channel=MeasureChannel(0), name="pulse_2", ), ), @@ -703,12 +707,12 @@ def test_asap_pass(self): 0 + 16 + 16 + 64, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(1), + channel=MeasureChannel(1), name="pulse_2", ), ), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(0), MemorySlot(0))), - (0 + 16 + 16 + 64, Acquire(1792, AcquireChannel(1), MemorySlot(1))), + (0 + 16 + 16 + 64, Acquire(1792, channel=AcquireChannel(0), mem_slot=MemorySlot(0))), + (0 + 16 + 16 + 64, Acquire(1792, channel=AcquireChannel(1), mem_slot=MemorySlot(1))), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) @@ -930,7 +934,7 @@ def test_parametric_input(self): qc = QuantumCircuit(qr) qc.append(Gate("gauss", 1, []), qargs=[qr[0]]) custom_gauss = Schedule( - Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), DriveChannel(0)) + Play(Gaussian(duration=25, sigma=4, amp=0.5, angle=pi / 2), channel=DriveChannel(0)) ) self.inst_map.add("gauss", [0], custom_gauss) sched = schedule(qc, self.backend, inst_map=self.inst_map) @@ -943,13 +947,17 @@ def test_pulse_gates(self): qc.append(U2Gate(0, 0), [q[0]]) qc.barrier(q[0], q[1]) qc.append(U2Gate(0, 0), [q[1]]) - qc.add_calibration("u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(0))), [0, 0]) - qc.add_calibration("u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1))), [0, 0]) + qc.add_calibration( + "u2", [0], Schedule(Play(Gaussian(28, 0.2, 4), channel=DriveChannel(0))), [0, 0] + ) + qc.add_calibration( + "u2", [1], Schedule(Play(Gaussian(28, 0.2, 4), channel=DriveChannel(1))), [0, 0] + ) sched = schedule(qc, self.backend) expected = Schedule( - Play(Gaussian(28, 0.2, 4), DriveChannel(0)), - (28, Schedule(Play(Gaussian(28, 0.2, 4), DriveChannel(1)))), + Play(Gaussian(28, 0.2, 4), channel=DriveChannel(0)), + (28, Schedule(Play(Gaussian(28, 0.2, 4), channel=DriveChannel(1)))), ) self.assertEqual(sched.instructions, expected.instructions) @@ -970,9 +978,9 @@ def test_calibrated_measurements(self): angle=-0.247301694, name="my_custom_calibration", ), - MeasureChannel(0), + channel=MeasureChannel(0), ) - meas_sched |= Acquire(1472, AcquireChannel(0), MemorySlot(0)) + meas_sched |= Acquire(1472, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) qc.add_calibration("measure", [0], meas_sched) sched = schedule(qc, self.backend) @@ -988,8 +996,8 @@ def test_subset_calibrated_measurements(self): qc.measure(2, 2) meas_scheds = [] for qubit in [0, 2]: - meas = Play(Gaussian(1200, 0.2, 4), MeasureChannel(qubit)) + Acquire( - 1200, AcquireChannel(qubit), MemorySlot(qubit) + meas = Play(Gaussian(1200, 0.2, 4), channel=MeasureChannel(qubit)) + Acquire( + 1200, channel=AcquireChannel(qubit), mem_slot=MemorySlot(qubit) ) meas_scheds.append(meas) qc.add_calibration("measure", [qubit], meas) @@ -1007,8 +1015,8 @@ def test_clbits_of_calibrated_measurements(self): qc = QuantumCircuit(q, c) qc.measure(q[0], c[1]) - meas_sched = Play(Gaussian(1200, 0.2, 4), MeasureChannel(0)) - meas_sched |= Acquire(1200, AcquireChannel(0), MemorySlot(0)) + meas_sched = Play(Gaussian(1200, 0.2, 4), channel=MeasureChannel(0)) + meas_sched |= Acquire(1200, channel=AcquireChannel(0), mem_slot=MemorySlot(0)) qc.add_calibration("measure", [0], meas_sched) sched = schedule(qc, self.backend) @@ -1077,7 +1085,7 @@ def test_schedule_block_in_instmap(self): sched = schedule(qc, self.backend, inst_map=instmap) ref_sched = Schedule() - ref_sched += Play(Gaussian(100, 0.1, 10), DriveChannel(0)) + ref_sched += Play(Gaussian(100, 0.1, 10), channel=DriveChannel(0)) self.assertEqual(sched, ref_sched) @@ -1090,7 +1098,7 @@ def test_inst_sched_map_get_measure_0(self): 0, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(0), + channel=MeasureChannel(0), name="pulse_2", ), ), @@ -1098,7 +1106,7 @@ def test_inst_sched_map_get_measure_0(self): 0, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(1), + channel=MeasureChannel(1), name="pulse_2", ), ), @@ -1106,13 +1114,13 @@ def test_inst_sched_map_get_measure_0(self): 0, Play( Waveform(samples=self.pulse_2_samples, name="pulse_2"), - MeasureChannel(2), + channel=MeasureChannel(2), name="pulse_2", ), ), - (0, Acquire(1792, AcquireChannel(0), MemorySlot(0))), - (0, Acquire(1792, AcquireChannel(1), MemorySlot(1))), - (0, Acquire(1792, AcquireChannel(2), MemorySlot(2))), + (0, Acquire(1792, channel=AcquireChannel(0), mem_slot=MemorySlot(0))), + (0, Acquire(1792, channel=AcquireChannel(1), mem_slot=MemorySlot(1))), + (0, Acquire(1792, channel=AcquireChannel(2), mem_slot=MemorySlot(2))), name="measure", ) self.assertEqual(sched_from_backend, expected_sched) diff --git a/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py b/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py index d15e2f0a697..3a0323f2f3f 100644 --- a/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py +++ b/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py @@ -340,7 +340,7 @@ def test_invalid_pulse_duration(self): # this will cause backend error since this doesn't fit with waveform memory chunk. custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(100, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) @@ -357,7 +357,7 @@ def test_short_pulse_duration(self): # this will cause backend error since this doesn't fit with waveform memory chunk. custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(32, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) @@ -375,10 +375,10 @@ def test_short_pulse_duration_multiple_pulse(self): # this should fail in the validation custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(32, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) custom_gate.insert( - 32, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + 32, pulse.Play(pulse.Constant(32, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) @@ -394,7 +394,7 @@ def test_valid_pulse_duration(self): # this is valid duration pulse custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(160, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(160, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) diff --git a/test/python/transpiler/test_calibrationbuilder.py b/test/python/transpiler/test_calibrationbuilder.py index bc64d954a42..7007e7afe16 100644 --- a/test/python/transpiler/test_calibrationbuilder.py +++ b/test/python/transpiler/test_calibrationbuilder.py @@ -368,12 +368,14 @@ def test_pass_alive_with_dcx_ish(self): """Test if the pass is not terminated by error with direct CX input.""" cx_sched = Schedule() # Fake direct cr - cx_sched.insert(0, Play(GaussianSquare(800, 0.2, 64, 544), ControlChannel(1)), inplace=True) + cx_sched.insert( + 0, Play(GaussianSquare(800, 0.2, 64, 544), channel=ControlChannel(1)), inplace=True + ) # Fake direct compensation tone # Compensation tone doesn't have dedicated pulse class. # So it's reported as a waveform now. compensation_tone = Waveform(0.1 * np.ones(800, dtype=complex)) - cx_sched.insert(0, Play(compensation_tone, DriveChannel(0)), inplace=True) + cx_sched.insert(0, Play(compensation_tone, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("cx", (1, 0), schedule=cx_sched) @@ -456,12 +458,14 @@ def test_pass_alive_with_dcx_ish(self): """Test if the pass is not terminated by error with direct CX input.""" cx_sched = Schedule() # Fake direct cr - cx_sched.insert(0, Play(GaussianSquare(800, 0.2, 64, 544), ControlChannel(1)), inplace=True) + cx_sched.insert( + 0, Play(GaussianSquare(800, 0.2, 64, 544), channel=ControlChannel(1)), inplace=True + ) # Fake direct compensation tone # Compensation tone doesn't have dedicated pulse class. # So it's reported as a waveform now. compensation_tone = Waveform(0.1 * np.ones(800, dtype=complex)) - cx_sched.insert(0, Play(compensation_tone, DriveChannel(0)), inplace=True) + cx_sched.insert(0, Play(compensation_tone, channel=DriveChannel(0)), inplace=True) inst_map = InstructionScheduleMap() inst_map.add("cx", (1, 0), schedule=cx_sched) @@ -566,7 +570,7 @@ def test_with_normalizerxangles(self): angle=0.04477749999041481, name="drag_2276", ), - DriveChannel(0), + channel=DriveChannel(0), ), inplace=True, ) diff --git a/test/python/transpiler/test_instruction_alignments.py b/test/python/transpiler/test_instruction_alignments.py index bd14891bb8c..20aeba990ed 100644 --- a/test/python/transpiler/test_instruction_alignments.py +++ b/test/python/transpiler/test_instruction_alignments.py @@ -29,7 +29,7 @@ def test_invalid_pulse_duration(self): # this will cause backend error since this doesn't fit with waveform memory chunk. custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(100, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) @@ -47,7 +47,7 @@ def test_short_pulse_duration(self): # this will cause backend error since this doesn't fit with waveform memory chunk. custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(32, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) @@ -66,10 +66,10 @@ def test_short_pulse_duration_multiple_pulse(self): # this should fail in the validation custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(32, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) custom_gate.insert( - 32, pulse.Play(pulse.Constant(32, 0.1), pulse.DriveChannel(0)), inplace=True + 32, pulse.Play(pulse.Constant(32, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) @@ -86,7 +86,7 @@ def test_valid_pulse_duration(self): # this is valid duration pulse custom_gate = pulse.Schedule(name="custom_x_gate") custom_gate.insert( - 0, pulse.Play(pulse.Constant(160, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(160, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) circuit = QuantumCircuit(1) diff --git a/test/python/transpiler/test_scheduling_padding_pass.py b/test/python/transpiler/test_scheduling_padding_pass.py index f2f4f6a24bc..0d0fc2c0716 100644 --- a/test/python/transpiler/test_scheduling_padding_pass.py +++ b/test/python/transpiler/test_scheduling_padding_pass.py @@ -794,7 +794,7 @@ def test_scheduling_with_calibration(self): qc.x(1) qc.cx(0, 1) - xsched = Schedule(Play(Constant(300, 0.1), DriveChannel(0))) + xsched = Schedule(Play(Constant(300, 0.1), channel=DriveChannel(0))) qc.add_calibration("x", (0,), xsched) durations = InstructionDurations([("x", None, 160), ("cx", None, 600)]) diff --git a/test/python/visualization/pulse_v2/test_core.py b/test/python/visualization/pulse_v2/test_core.py index 5855bbafae4..32316ca409c 100644 --- a/test/python/visualization/pulse_v2/test_core.py +++ b/test/python/visualization/pulse_v2/test_core.py @@ -255,17 +255,23 @@ def setUp(self) -> None: self.sched = pulse.Schedule() self.sched.insert( 0, - pulse.Play(pulse.Waveform([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]), pulse.DriveChannel(0)), + pulse.Play( + pulse.Waveform([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]), channel=pulse.DriveChannel(0) + ), inplace=True, ) self.sched.insert( 10, - pulse.Play(pulse.Waveform([0.5, 0.4, 0.3, 0.2, 0.1, 0.0]), pulse.DriveChannel(0)), + pulse.Play( + pulse.Waveform([0.5, 0.4, 0.3, 0.2, 0.1, 0.0]), channel=pulse.DriveChannel(0) + ), inplace=True, ) self.sched.insert( 0, - pulse.Play(pulse.Waveform([0.3, 0.3, 0.3, 0.3, 0.3, 0.3]), pulse.DriveChannel(1)), + pulse.Play( + pulse.Waveform([0.3, 0.3, 0.3, 0.3, 0.3, 0.3]), channel=pulse.DriveChannel(1) + ), inplace=True, ) diff --git a/test/python/visualization/pulse_v2/test_events.py b/test/python/visualization/pulse_v2/test_events.py index fbef9d3de80..f91abab3a37 100644 --- a/test/python/visualization/pulse_v2/test_events.py +++ b/test/python/visualization/pulse_v2/test_events.py @@ -25,10 +25,10 @@ def test_parse_program(self): test_pulse = pulse.Gaussian(10, 0.1, 3) sched = pulse.Schedule() - sched = sched.insert(0, pulse.SetPhase(3.14, pulse.DriveChannel(0))) - sched = sched.insert(0, pulse.Play(test_pulse, pulse.DriveChannel(0))) - sched = sched.insert(10, pulse.ShiftPhase(-1.57, pulse.DriveChannel(0))) - sched = sched.insert(10, pulse.Play(test_pulse, pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.SetPhase(3.14, channel=pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.Play(test_pulse, channel=pulse.DriveChannel(0))) + sched = sched.insert(10, pulse.ShiftPhase(-1.57, channel=pulse.DriveChannel(0))) + sched = sched.insert(10, pulse.Play(test_pulse, channel=pulse.DriveChannel(0))) ch_events = events.ChannelEvents.load_program(sched, pulse.DriveChannel(0)) @@ -38,13 +38,13 @@ def test_parse_program(self): self.assertEqual(inst_data0.t0, 0) self.assertEqual(inst_data0.frame.phase, 3.14) self.assertEqual(inst_data0.frame.freq, 0) - self.assertEqual(inst_data0.inst, pulse.Play(test_pulse, pulse.DriveChannel(0))) + self.assertEqual(inst_data0.inst, pulse.Play(test_pulse, channel=pulse.DriveChannel(0))) inst_data1 = waveforms[1] self.assertEqual(inst_data1.t0, 10) self.assertEqual(inst_data1.frame.phase, 1.57) self.assertEqual(inst_data1.frame.freq, 0) - self.assertEqual(inst_data1.inst, pulse.Play(test_pulse, pulse.DriveChannel(0))) + self.assertEqual(inst_data1.inst, pulse.Play(test_pulse, channel=pulse.DriveChannel(0))) # check frame data frames = list(ch_events.get_frame_changes()) @@ -52,20 +52,22 @@ def test_parse_program(self): self.assertEqual(inst_data0.t0, 0) self.assertEqual(inst_data0.frame.phase, 3.14) self.assertEqual(inst_data0.frame.freq, 0) - self.assertListEqual(inst_data0.inst, [pulse.SetPhase(3.14, pulse.DriveChannel(0))]) + self.assertListEqual(inst_data0.inst, [pulse.SetPhase(3.14, channel=pulse.DriveChannel(0))]) inst_data1 = frames[1] self.assertEqual(inst_data1.t0, 10) self.assertEqual(inst_data1.frame.phase, -1.57) self.assertEqual(inst_data1.frame.freq, 0) - self.assertListEqual(inst_data1.inst, [pulse.ShiftPhase(-1.57, pulse.DriveChannel(0))]) + self.assertListEqual( + inst_data1.inst, [pulse.ShiftPhase(-1.57, channel=pulse.DriveChannel(0))] + ) def test_multiple_frames_at_the_same_time(self): """Test multiple frame instruction at the same time.""" # shift phase followed by set phase sched = pulse.Schedule() - sched = sched.insert(0, pulse.ShiftPhase(-1.57, pulse.DriveChannel(0))) - sched = sched.insert(0, pulse.SetPhase(3.14, pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.ShiftPhase(-1.57, channel=pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.SetPhase(3.14, channel=pulse.DriveChannel(0))) ch_events = events.ChannelEvents.load_program(sched, pulse.DriveChannel(0)) frames = list(ch_events.get_frame_changes()) @@ -74,8 +76,8 @@ def test_multiple_frames_at_the_same_time(self): # set phase followed by shift phase sched = pulse.Schedule() - sched = sched.insert(0, pulse.SetPhase(3.14, pulse.DriveChannel(0))) - sched = sched.insert(0, pulse.ShiftPhase(-1.57, pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.SetPhase(3.14, channel=pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.ShiftPhase(-1.57, channel=pulse.DriveChannel(0))) ch_events = events.ChannelEvents.load_program(sched, pulse.DriveChannel(0)) frames = list(ch_events.get_frame_changes()) @@ -85,8 +87,8 @@ def test_multiple_frames_at_the_same_time(self): def test_frequency(self): """Test parse frequency.""" sched = pulse.Schedule() - sched = sched.insert(0, pulse.ShiftFrequency(1.0, pulse.DriveChannel(0))) - sched = sched.insert(5, pulse.SetFrequency(5.0, pulse.DriveChannel(0))) + sched = sched.insert(0, pulse.ShiftFrequency(1.0, channel=pulse.DriveChannel(0))) + sched = sched.insert(5, pulse.SetFrequency(5.0, channel=pulse.DriveChannel(0))) ch_events = events.ChannelEvents.load_program(sched, pulse.DriveChannel(0)) ch_events.set_config(dt=0.1, init_frequency=3.0, init_phase=0) @@ -102,7 +104,7 @@ def test_parameterized_parametric_pulse(self): """Test generating waveforms that are parameterized.""" param = circuit.Parameter("amp") - test_waveform = pulse.Play(pulse.Constant(10, param), pulse.DriveChannel(0)) + test_waveform = pulse.Play(pulse.Constant(10, param), channel=pulse.DriveChannel(0)) ch_events = events.ChannelEvents( waveforms={0: test_waveform}, frames={}, channel=pulse.DriveChannel(0) @@ -122,9 +124,9 @@ def test_parameterized_frame_change(self): """ param = circuit.Parameter("phase") - test_fc1 = pulse.ShiftPhase(param, pulse.DriveChannel(0)) - test_fc2 = pulse.ShiftPhase(1.57, pulse.DriveChannel(0)) - test_waveform = pulse.Play(pulse.Constant(10, 0.1), pulse.DriveChannel(0)) + test_fc1 = pulse.ShiftPhase(param, channel=pulse.DriveChannel(0)) + test_fc2 = pulse.ShiftPhase(1.57, channel=pulse.DriveChannel(0)) + test_waveform = pulse.Play(pulse.Constant(10, 0.1), channel=pulse.DriveChannel(0)) ch_events = events.ChannelEvents( waveforms={0: test_waveform}, @@ -152,11 +154,11 @@ def test_zero_duration_delay(self): ch = pulse.DriveChannel(0) test_sched = pulse.Schedule() - test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), ch) - test_sched += pulse.Delay(0, ch) - test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), ch) - test_sched += pulse.Delay(1, ch) - test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), ch) + test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), channel=ch) + test_sched += pulse.Delay(0, channel=ch) + test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), channel=ch) + test_sched += pulse.Delay(1, channel=ch) + test_sched += pulse.Play(pulse.Gaussian(160, 0.1, 40), channel=ch) ch_events = events.ChannelEvents.load_program(test_sched, ch) diff --git a/test/python/visualization/pulse_v2/test_generators.py b/test/python/visualization/pulse_v2/test_generators.py index c5f5e8da98a..f26a9ad7549 100644 --- a/test/python/visualization/pulse_v2/test_generators.py +++ b/test/python/visualization/pulse_v2/test_generators.py @@ -85,7 +85,7 @@ def test_parse_waveform(self): """Test helper function that parse waveform with Waveform instance.""" test_pulse = pulse.library.Gaussian(10, 0.1, 3).get_waveform() - inst = pulse.Play(test_pulse, pulse.DriveChannel(0)) + inst = pulse.Play(test_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(inst, 0, 0, 10, 0.1) x, y, _ = waveform._parse_waveform(inst_data) @@ -100,7 +100,7 @@ def test_parse_waveform_parametric(self): """Test helper function that parse waveform with ParametricPulse instance.""" test_pulse = pulse.library.Gaussian(10, 0.1, 3) - inst = pulse.Play(test_pulse, pulse.DriveChannel(0)) + inst = pulse.Play(test_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(inst, 0, 0, 10, 0.1) x, y, _ = waveform._parse_waveform(inst_data) @@ -114,7 +114,7 @@ def test_parse_waveform_parametric(self): def test_gen_filled_waveform_stepwise_play(self): """Test gen_filled_waveform_stepwise with play instruction.""" my_pulse = pulse.Waveform(samples=[0, 0.5 + 0.5j, 0.5 + 0.5j, 0], name="my_pulse") - play = pulse.Play(my_pulse, pulse.DriveChannel(0)) + play = pulse.Play(my_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(play, np.pi / 2, 5e9, 5, 0.1) objs = waveform.gen_filled_waveform_stepwise( @@ -218,7 +218,7 @@ def test_gen_filled_waveform_stepwise_acquire(self): def test_gen_iqx_latex_waveform_name_x90(self): """Test gen_iqx_latex_waveform_name with x90 waveform.""" iqx_pulse = pulse.Waveform(samples=[0, 0, 0, 0], name="X90p_d0_1234567") - play = pulse.Play(iqx_pulse, pulse.DriveChannel(0)) + play = pulse.Play(iqx_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(play, 0, 0, 0, 0.1) obj = waveform.gen_ibmq_latex_waveform_name( @@ -246,7 +246,7 @@ def test_gen_iqx_latex_waveform_name_x90(self): def test_gen_iqx_latex_waveform_name_x180(self): """Test gen_iqx_latex_waveform_name with x180 waveform.""" iqx_pulse = pulse.Waveform(samples=[0, 0, 0, 0], name="Xp_d0_1234567") - play = pulse.Play(iqx_pulse, pulse.DriveChannel(0)) + play = pulse.Play(iqx_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(play, 0, 0, 0, 0.1) obj = waveform.gen_ibmq_latex_waveform_name( @@ -264,7 +264,7 @@ def test_gen_iqx_latex_waveform_name_x180(self): def test_gen_iqx_latex_waveform_name_cr(self): """Test gen_iqx_latex_waveform_name with CR waveform.""" iqx_pulse = pulse.Waveform(samples=[0, 0, 0, 0], name="CR90p_u0_1234567") - play = pulse.Play(iqx_pulse, pulse.ControlChannel(0)) + play = pulse.Play(iqx_pulse, channel=pulse.ControlChannel(0)) inst_data = create_instruction(play, 0, 0, 0, 0.1) obj = waveform.gen_ibmq_latex_waveform_name( @@ -282,7 +282,7 @@ def test_gen_iqx_latex_waveform_name_cr(self): def test_gen_iqx_latex_waveform_name_compensation_tone(self): """Test gen_iqx_latex_waveform_name with CR compensation waveform.""" iqx_pulse = pulse.Waveform(samples=[0, 0, 0, 0], name="CR90p_d0_u0_1234567") - play = pulse.Play(iqx_pulse, pulse.DriveChannel(0)) + play = pulse.Play(iqx_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(play, 0, 0, 0, 0.1) obj = waveform.gen_ibmq_latex_waveform_name( @@ -300,7 +300,7 @@ def test_gen_iqx_latex_waveform_name_compensation_tone(self): def test_gen_waveform_max_value(self): """Test gen_waveform_max_value.""" iqx_pulse = pulse.Waveform(samples=[0, 0.1, 0.3, -0.2j], name="test") - play = pulse.Play(iqx_pulse, pulse.DriveChannel(0)) + play = pulse.Play(iqx_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(play, 0, 0, 0, 0.1) objs = waveform.gen_waveform_max_value( @@ -343,7 +343,7 @@ def test_gen_filled_waveform_stepwise_opaque(self): """Test generating waveform with unbound parameter.""" amp = circuit.Parameter("amp") my_pulse = pulse.Gaussian(10, amp, 3, name="my_pulse") - play = pulse.Play(my_pulse, pulse.DriveChannel(0)) + play = pulse.Play(my_pulse, channel=pulse.DriveChannel(0)) inst_data = create_instruction(play, np.pi / 2, 5e9, 5, 0.1, True) objs = waveform.gen_filled_waveform_stepwise( @@ -589,8 +589,8 @@ def test_frequency_to_text(self): def test_gen_formatted_phase(self): """Test gen_formatted_phase.""" fcs = [ - pulse.ShiftPhase(np.pi / 2, pulse.DriveChannel(0)), - pulse.ShiftFrequency(1e6, pulse.DriveChannel(0)), + pulse.ShiftPhase(np.pi / 2, channel=pulse.DriveChannel(0)), + pulse.ShiftFrequency(1e6, channel=pulse.DriveChannel(0)), ] inst_data = create_instruction(fcs, np.pi / 2, 1e6, 5, 0.1) @@ -617,8 +617,8 @@ def test_gen_formatted_phase(self): def test_gen_formatted_freq_mhz(self): """Test gen_formatted_freq_mhz.""" fcs = [ - pulse.ShiftPhase(np.pi / 2, pulse.DriveChannel(0)), - pulse.ShiftFrequency(1e6, pulse.DriveChannel(0)), + pulse.ShiftPhase(np.pi / 2, channel=pulse.DriveChannel(0)), + pulse.ShiftFrequency(1e6, channel=pulse.DriveChannel(0)), ] inst_data = create_instruction(fcs, np.pi / 2, 1e6, 5, 0.1) @@ -647,8 +647,8 @@ def test_gen_formatted_freq_mhz(self): def test_gen_formatted_frame_values(self): """Test gen_formatted_frame_values.""" fcs = [ - pulse.ShiftPhase(np.pi / 2, pulse.DriveChannel(0)), - pulse.ShiftFrequency(1e6, pulse.DriveChannel(0)), + pulse.ShiftPhase(np.pi / 2, channel=pulse.DriveChannel(0)), + pulse.ShiftFrequency(1e6, channel=pulse.DriveChannel(0)), ] inst_data = create_instruction(fcs, np.pi / 2, 1e6, 5, 0.1) @@ -663,8 +663,8 @@ def test_gen_formatted_frame_values(self): def test_gen_raw_operand_values_compact(self): """Test gen_raw_operand_values_compact.""" fcs = [ - pulse.ShiftPhase(np.pi / 2, pulse.DriveChannel(0)), - pulse.ShiftFrequency(1e6, pulse.DriveChannel(0)), + pulse.ShiftPhase(np.pi / 2, channel=pulse.DriveChannel(0)), + pulse.ShiftFrequency(1e6, channel=pulse.DriveChannel(0)), ] inst_data = create_instruction(fcs, np.pi / 2, 1e6, 5, 0.1) @@ -682,8 +682,8 @@ def test_gen_raw_operand_values_compact(self): def gen_frame_symbol(self): """Test gen_frame_symbol.""" fcs = [ - pulse.ShiftPhase(np.pi / 2, pulse.DriveChannel(0)), - pulse.ShiftFrequency(1e6, pulse.DriveChannel(0)), + pulse.ShiftPhase(np.pi / 2, channel=pulse.DriveChannel(0)), + pulse.ShiftFrequency(1e6, channel=pulse.DriveChannel(0)), ] inst_data = create_instruction(fcs, np.pi / 2, 1e6, 5, 0.1) @@ -720,7 +720,7 @@ def gen_frame_symbol(self): def gen_frame_symbol_with_parameters(self): """Test gen_frame_symbol with parameterized frame.""" theta = -1.0 * circuit.Parameter("P0") - fcs = [pulse.ShiftPhase(theta, pulse.DriveChannel(0))] + fcs = [pulse.ShiftPhase(theta, channel=pulse.DriveChannel(0))] inst_data = create_instruction(fcs, np.pi / 2, 1e6, 5, 0.1) obj = frame.gen_frame_symbol(inst_data, formatter=self.formatter, device=self.device)[0] diff --git a/test/python/visualization/pulse_v2/test_layouts.py b/test/python/visualization/pulse_v2/test_layouts.py index d6a868956fa..31752bcaf29 100644 --- a/test/python/visualization/pulse_v2/test_layouts.py +++ b/test/python/visualization/pulse_v2/test_layouts.py @@ -234,7 +234,7 @@ def setUp(self) -> None: self.device = device_info.OpenPulseBackendInfo(name="test_backend", dt=1e-9) self.prog = pulse.Schedule(name="test_sched") self.prog.insert( - 0, pulse.Play(pulse.Constant(100, 0.1), pulse.DriveChannel(0)), inplace=True + 0, pulse.Play(pulse.Constant(100, 0.1), channel=pulse.DriveChannel(0)), inplace=True ) def detail_title(self):