From 223e5bc0c193da620bdd2b5abaf549a3c1e02d09 Mon Sep 17 00:00:00 2001 From: Wahaj Javed Date: Wed, 21 Oct 2020 19:59:37 +0500 Subject: [PATCH 1/9] Deprecate ScheduleComponent class Deprecate the ScheduleComponent class and remove it as the base class of Schedule and Instruction. Anywhere that currently accepts a ScheduleComponent should instead accept a Union[Schedule, Instruction]. Propagate the docstrings for the removed properties to Instruction and the Schedule classes themselves. Use Schedule and Instruction type forwardRef of the classes in the typed arguments * deprecate channels argument in ch_start_time method of Instruction Fixes #5076 --- qiskit/compiler/assemble.py | 4 +- qiskit/pulse/instructions/instruction.py | 26 +++++---- qiskit/pulse/interfaces.py | 64 ++++++++++++++++++++- qiskit/pulse/schedule.py | 63 +++++++++++--------- qiskit/pulse/transforms.py | 14 ++--- qiskit/visualization/pulse_visualization.py | 4 +- 6 files changed, 124 insertions(+), 51 deletions(-) diff --git a/qiskit/compiler/assemble.py b/qiskit/compiler/assemble.py index 52b1db59f1a5..5a2f0174c77a 100644 --- a/qiskit/compiler/assemble.py +++ b/qiskit/compiler/assemble.py @@ -19,7 +19,7 @@ from typing import Union, List, Dict, Optional from qiskit.circuit import QuantumCircuit, Qubit, Parameter from qiskit.exceptions import QiskitError -from qiskit.pulse import ScheduleComponent, LoConfig +from qiskit.pulse import LoConfig, Instruction from qiskit.assembler.run_config import RunConfig from qiskit.assembler import assemble_circuits, assemble_schedules from qiskit.qobj import QobjHeader, Qobj @@ -153,7 +153,7 @@ def assemble(experiments: Union[QuantumCircuit, List[QuantumCircuit], Schedule, return assemble_circuits(circuits=bound_experiments, qobj_id=qobj_id, qobj_header=qobj_header, run_config=run_config) - elif all(isinstance(exp, ScheduleComponent) for exp in experiments): + elif all(isinstance(exp, (Schedule, Instruction)) for exp in experiments): run_config = _parse_pulse_args(backend, qubit_lo_freq, meas_lo_freq, qubit_lo_range, meas_lo_range, schedule_los, meas_level, meas_return, diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index ce7d7120b835..b4c4c9c1128b 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -25,18 +25,17 @@ from abc import ABC -from typing import Callable, Dict, Iterable, List, Optional, Tuple +from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union import numpy as np from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.interfaces import ScheduleComponent from qiskit.pulse.schedule import Schedule # pylint: disable=missing-return-doc -class Instruction(ScheduleComponent, ABC): +class Instruction(ABC): """The smallest schedulable unit: a single instruction. It has a fixed duration and specified channels. """ @@ -130,7 +129,7 @@ def duration(self) -> int: return self._duration @property - def _children(self) -> Tuple[ScheduleComponent]: + def _children(self) -> Tuple[Union[Schedule, 'Instruction']]: """Instruction has no child nodes.""" return () @@ -147,12 +146,18 @@ def ch_duration(self, *channels: List[Channel]) -> int: """ return self.ch_stop_time(*channels) - def ch_start_time(self, *channels: List[Channel]) -> int: + def ch_start_time( + self, + *channels: List[Channel] + ) -> int: + # pylint: disable=unused-argument """Return minimum start time for supplied channels. Args: *channels: Supplied channels """ + warnings.warn("``ch_start_time`` channels argument has been deprecated and will be " + "removed in a future release", DeprecationWarning) return 0 def ch_stop_time(self, *channels: List[Channel]) -> int: @@ -181,7 +186,8 @@ def flatten(self) -> 'Instruction': """Return itself as already single instruction.""" return self - def shift(self: ScheduleComponent, time: int, name: Optional[str] = None) -> Schedule: + def shift(self: Union[Schedule, 'Instruction'], + time: int, name: Optional[str] = None) -> Schedule: """Return a new schedule shifted forward by `time`. Args: @@ -192,7 +198,7 @@ def shift(self: ScheduleComponent, time: int, name: Optional[str] = None) -> Sch name = self.name return Schedule((time, self), name=name) - def insert(self, start_time: int, schedule: ScheduleComponent, + def insert(self, start_time: int, schedule: Union[Schedule, 'Instruction'], name: Optional[str] = None) -> Schedule: """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted within ``self`` at ``start_time``. @@ -206,7 +212,7 @@ def insert(self, start_time: int, schedule: ScheduleComponent, name = self.name return Schedule(self, (start_time, schedule), name=name) - def append(self, schedule: ScheduleComponent, + def append(self, schedule: Union[Schedule, 'Instruction'], name: Optional[str] = None) -> Schedule: """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted at the maximum time over all channels shared between ``self`` and ``schedule``. @@ -301,11 +307,11 @@ def __hash__(self) -> int: self._hash = hash((type(self), self.operands, self.name)) return self._hash - def __add__(self, other: ScheduleComponent) -> Schedule: + def __add__(self, other: Union[Schedule, 'Instruction']) -> Schedule: """Return a new schedule with `other` inserted within `self` at `start_time`.""" return self.append(other) - def __or__(self, other: ScheduleComponent) -> Schedule: + def __or__(self, other: Union[Schedule, 'Instruction']) -> Schedule: """Return a new schedule which is the union of `self` and `other`.""" return self.insert(0, other) diff --git a/qiskit/pulse/interfaces.py b/qiskit/pulse/interfaces.py index 4fabbfc96941..3c4a7b4a855a 100644 --- a/qiskit/pulse/interfaces.py +++ b/qiskit/pulse/interfaces.py @@ -11,8 +11,10 @@ # that they have been altered from the originals. """ -ScheduleComponent, a common interface for components of schedule (Instruction and Schedule). +ScheduleComponent has been deprecated. +It is a common interface for components of schedule (Instruction and Schedule). """ +import warnings from abc import ABCMeta, abstractmethod from typing import Tuple, List, Union, Optional @@ -22,68 +24,108 @@ class ScheduleComponent(metaclass=ABCMeta): - """Common interface for components of schedule. """ + """ScheduleComponent has been deprecated. + It has been replaced by `qiskit.pulse.values.Value` and `qiskit.pulse.values.NamedValue``. + Anywhere that currently accepts a ``ScheduleComponent`` should instead accept a + ``Union[Schedule, Instruction]``. + """ @property @abstractmethod def name(self) -> str: """Name of ScheduleComponent.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @property @abstractmethod def channels(self) -> List[Channel]: """Return channels used by schedule.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) + pass @property @abstractmethod def duration(self) -> int: """Duration of this schedule component.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) + pass @property @abstractmethod def start_time(self) -> int: """Starting time of this schedule component.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) + pass @property @abstractmethod def stop_time(self) -> int: """Stopping time of this schedule component.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def ch_duration(self, *channels: List[Channel]) -> int: """Duration of the `channels` in schedule component.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def ch_start_time(self, *channels: List[Channel]) -> int: """Starting time of the `channels` in schedule component. """ + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def ch_stop_time(self, *channels: List[Channel]) -> int: """Stopping of the `channels` in schedule component.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @property @abstractmethod def _children(self) -> Tuple[Union[int, 'ScheduleComponent']]: """Child nodes of this schedule component. """ + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @property @abstractmethod def instructions(self) -> Tuple[Tuple[int, 'Instructions']]: """Return iterable for all `Instruction`s in `Schedule` tree.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def flatten(self) -> 'ScheduleComponent': """Return a new schedule which is the flattened schedule contained all `instructions`.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod @@ -95,6 +137,9 @@ def shift(self: 'ScheduleComponent', time: int, time: Time to shift by name: Name of the new schedule. Defaults to name of parent """ + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod @@ -107,6 +152,9 @@ def insert(self, start_time: int, schedule: 'ScheduleComponent', schedule: schedule to be inserted name: Name of the new schedule. Defaults to name of parent """ + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod @@ -119,19 +167,31 @@ def append(self, schedule: 'ScheduleComponent', schedule: schedule to be appended name: Name of the new schedule. Defaults to name of parent """ + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def __add__(self, schedule: 'ScheduleComponent') -> 'ScheduleComponent': """Return a new schedule with `schedule` inserted within `self` at `start_time`.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def __or__(self, schedule: 'ScheduleComponent') -> 'ScheduleComponent': """Return a new schedule which is the union of `self` and `schedule`.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass @abstractmethod def __lshift__(self, time: int) -> 'ScheduleComponent': """Return a new schedule which is shifted forward by `time`.""" + warnings.warn("ScheduleComponent is deprecated and will be removed in a future release. " + "Anywhere that currently accepts a ``ScheduleComponent`` should instead " + "accept a ``Union[Schedule, Instruction]`` ", DeprecationWarning) pass diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index 53c4c7243ef7..9ecf6bdf8977 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -16,6 +16,7 @@ """ import abc + import copy import itertools import multiprocessing as mp @@ -25,7 +26,6 @@ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.interfaces import ScheduleComponent from qiskit.util import is_main_process # pylint: disable=missing-return-doc @@ -34,7 +34,7 @@ """An interval type is a tuple of a start time (inclusive) and an end time (exclusive).""" -class Schedule(ScheduleComponent): +class Schedule(abc.ABC): """A quantum program *schedule* with exact time constraints for its instructions, operating over all input signal *channels* and supporting special syntaxes for building. """ @@ -44,7 +44,9 @@ class Schedule(ScheduleComponent): # Prefix to use for auto naming. prefix = 'sched' - def __init__(self, *schedules: Union[ScheduleComponent, Tuple[int, ScheduleComponent]], + def __init__(self, + *schedules: Union[Union['Schedule', 'Instruction'], + Tuple[int, Union['Schedule', 'Instruction']]], name: Optional[str] = None): """Create an empty schedule. @@ -74,6 +76,7 @@ def __init__(self, *schedules: Union[ScheduleComponent, Tuple[int, ScheduleCompo @property def name(self) -> str: + """Name of this Schedule""" return self._name @property @@ -83,14 +86,17 @@ def timeslots(self) -> Dict[Channel, List[Interval]]: @property def duration(self) -> int: + """Duration of this schedule.""" return self._duration @property def start_time(self) -> int: + """Starting time of this schedule.""" return self.ch_start_time(*self.channels) @property def stop_time(self) -> int: + """Stopping time of this schedule.""" return self.duration @property @@ -99,13 +105,13 @@ def channels(self) -> Tuple[Channel]: return tuple(self._timeslots.keys()) @property - def _children(self) -> Tuple[Tuple[int, ScheduleComponent], ...]: - """Return the child``ScheduleComponent``s of this ``Schedule`` in the + def _children(self) -> Tuple[Tuple[int, Union['Schedule', 'Instruction']], ...]: + """Return the child``NamedValues``s of this ``Schedule`` in the order they were added to the schedule. Returns: A tuple, where each element is a two-tuple containing the initial - scheduled time of each ``ScheduleComponent`` and the component + scheduled time of each ``NamedValue`` and the component itself. """ return tuple(self.__children) @@ -115,7 +121,7 @@ def instructions(self): """Get the time-ordered instructions from self. ReturnType: - Tuple[Tuple[int, Instruction], ...] + Tuple[Tuple[int, 'Instruction'], ...] """ def key(time_inst_pair): @@ -236,7 +242,7 @@ def _mutable_shift(self, # pylint: disable=arguments-differ def insert(self, start_time: int, - schedule: ScheduleComponent, + schedule: Union['Schedule', 'Instruction'], name: Optional[str] = None, inplace: bool = False ) -> 'Schedule': @@ -255,7 +261,7 @@ def insert(self, def _mutable_insert(self, start_time: int, - schedule: ScheduleComponent + schedule: Union['Schedule', 'Instruction'] ) -> 'Schedule': """Mutably insert `schedule` into `self` at `start_time`. @@ -269,7 +275,7 @@ def _mutable_insert(self, def _immutable_insert(self, start_time: int, - schedule: ScheduleComponent, + schedule: Union['Schedule', 'Instruction'], name: Optional[str] = None, ) -> 'Schedule': """Return a new schedule with ``schedule`` inserted into ``self`` at ``start_time``. @@ -286,7 +292,7 @@ def _immutable_insert(self, return new_sched # pylint: disable=arguments-differ - def append(self, schedule: ScheduleComponent, + def append(self, schedule: Union['Schedule', 'Instruction'], name: Optional[str] = None, inplace: bool = False) -> 'Schedule': r"""Return a new schedule with ``schedule`` inserted at the maximum time over @@ -326,8 +332,8 @@ def filter(self, *filter_funcs: List[Callable], If no arguments are provided, ``self`` is returned. Args: - filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and - return a bool. + filter_funcs: A list of Callables which take a (int, Union['Schedule', Instruction]) + tuple and return a bool. channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``. instruction_types (Optional[Iterable[Type[qiskit.pulse.Instruction]]]): For example, ``[PulseInstruction, AcquireInstruction]``. @@ -353,8 +359,8 @@ def exclude(self, *filter_funcs: List[Callable], self.filter(args) | self.exclude(args) == self Args: - filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and - return a bool. + filter_funcs: A list of Callables which take a (int, Union['Schedule', Instruction]) + tuple and return a bool. channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``. instruction_types (Optional[Iterable[Type[qiskit.pulse.Instruction]]]): For example, ``[PulseInstruction, AcquireInstruction]``. @@ -374,7 +380,7 @@ def _apply_filter(self, filter_func: Callable, new_sched_name: str) -> 'Schedule ``filter_func`` returns ``True``. Args: - filter_func: Function of the form (int, ScheduleComponent) -> bool. + filter_func: Function of the form (int, Union['Schedule', Instruction]) -> bool. new_sched_name: Name of the returned ``Schedule``. """ subschedules = self.flatten()._children @@ -463,7 +469,7 @@ def interval_filter(time_inst) -> bool: # return function returning true iff all filters are passed return lambda x: all([filter_func(x) for filter_func in filter_func_list]) - def _add_timeslots(self, time: int, schedule: ScheduleComponent) -> None: + def _add_timeslots(self, time: int, schedule: Union['Schedule', 'Instruction']) -> None: """Update all time tracking within this schedule based on the given schedule. Args: @@ -510,7 +516,7 @@ def _add_timeslots(self, time: int, schedule: ScheduleComponent) -> None: _check_nonnegative_timeslot(self._timeslots) - def _remove_timeslots(self, time: int, schedule: ScheduleComponent): + def _remove_timeslots(self, time: int, schedule: Union['Schedule', 'Instruction']): """Delete the timeslots if present for the respective schedule component. Args: @@ -548,21 +554,21 @@ def _remove_timeslots(self, time: int, schedule: ScheduleComponent): def _replace_timeslots(self, time: int, - old: ScheduleComponent, - new: ScheduleComponent): + old: Union['Schedule', 'Instruction'], + new: Union['Schedule', 'Instruction']): """Replace the timeslots of ``old`` if present with the timeslots of ``new``. Args: time: The time to remove the timeslots for the ``schedule`` component. - old: Instruction to replace. - new: Instruction to replace with. + old: 'Instruction' to replace. + new: 'Instruction' to replace with. """ self._remove_timeslots(time, old) self._add_timeslots(time, new) def replace(self, - old: ScheduleComponent, - new: ScheduleComponent, + old: Union['Schedule', 'Instruction'], + new: Union['Schedule', 'Instruction'], inplace: bool = False, ) -> 'Schedule': """Return a schedule with the ``old`` instruction replaced with a ``new`` @@ -737,7 +743,7 @@ def draw(self, dt: float = 1, style=None, show_framechange_channels=show_framechange_channels, draw_title=draw_title) - def __eq__(self, other: ScheduleComponent) -> bool: + def __eq__(self, other: Union['Schedule', 'Instruction']) -> bool: """Test if two ScheduleComponents are equal. Equality is checked by verifying there is an equal instruction at every time @@ -774,11 +780,11 @@ def __eq__(self, other: ScheduleComponent) -> bool: return True - def __add__(self, other: ScheduleComponent) -> 'Schedule': + def __add__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': """Return a new schedule with ``other`` inserted within ``self`` at ``start_time``.""" return self.append(other) - def __or__(self, other: ScheduleComponent) -> 'Schedule': + def __or__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': """Return a new schedule which is the union of `self` and `other`.""" return self.insert(0, other) @@ -864,7 +870,8 @@ def bind_parameters(self, else: # assuming no other parametrized instructions predefined = self.parameters - sub_params = {k: v for k, v in named_parameters.items() if k in predefined} + sub_params = {k: v for k, v in named_parameters.items() + if k in predefined} schedules.append(param_sched(**sub_params)) # construct evaluated schedules diff --git a/qiskit/pulse/transforms.py b/qiskit/pulse/transforms.py index 8d49135932c0..d415301ff727 100644 --- a/qiskit/pulse/transforms.py +++ b/qiskit/pulse/transforms.py @@ -16,18 +16,18 @@ import warnings from collections import defaultdict from typing import Callable -from typing import List, Optional, Iterable +from typing import List, Optional, Iterable, Union import numpy as np -from qiskit.pulse import channels as chans, exceptions, instructions, interfaces +from qiskit.pulse import channels as chans, exceptions, instructions from qiskit.pulse.exceptions import PulseError from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap from qiskit.pulse.instructions import directives from qiskit.pulse.schedule import Schedule -def align_measures(schedules: Iterable[interfaces.ScheduleComponent], +def align_measures(schedules: Iterable[Union['Schedule', instructions.Instruction]], inst_map: Optional[InstructionScheduleMap] = None, cal_gate: str = 'u3', max_calibration_duration: Optional[int] = None, @@ -178,7 +178,7 @@ def get_max_calibration_duration(inst_map, cal_gate): return new_schedules -def add_implicit_acquires(schedule: interfaces.ScheduleComponent, +def add_implicit_acquires(schedule: Union['Schedule', instructions.Instruction], meas_map: List[List[int]] ) -> Schedule: """Return a new schedule with implicit acquires from the measurement mapping replaced by @@ -317,7 +317,7 @@ def compress_pulses(schedules: List[Schedule]) -> List[Schedule]: def _push_left_append(this: Schedule, - other: interfaces.ScheduleComponent, + other: Union['Schedule', instructions.Instruction], ) -> Schedule: r"""Return ``this`` with ``other`` inserted at the maximum time over all channels shared between ```this`` and ``other``. @@ -366,8 +366,8 @@ def align_left(schedule: Schedule) -> Schedule: return aligned -def _push_right_prepend(this: interfaces.ScheduleComponent, - other: interfaces.ScheduleComponent, +def _push_right_prepend(this: Union['Schedule', instructions.Instruction], + other: Union['Schedule', instructions.Instruction], ) -> Schedule: r"""Return ``this`` with ``other`` inserted at the latest possible time such that ``other`` ends before it overlaps with any of ``this``. diff --git a/qiskit/visualization/pulse_visualization.py b/qiskit/visualization/pulse_visualization.py index cdb085ed7d3b..2a098b0f8604 100644 --- a/qiskit/visualization/pulse_visualization.py +++ b/qiskit/visualization/pulse_visualization.py @@ -17,7 +17,7 @@ """ from typing import Union, Callable, List, Dict, Tuple -from qiskit.pulse import Schedule, Instruction, SamplePulse, Waveform, ScheduleComponent +from qiskit.pulse import Schedule, Instruction, SamplePulse, Waveform from qiskit.pulse.channels import Channel from qiskit.visualization.pulse.qcstyle import PulseStyle, SchedStyle from qiskit.visualization.exceptions import VisualizationError @@ -30,7 +30,7 @@ HAS_MATPLOTLIB = False -def pulse_drawer(data: Union[Waveform, ScheduleComponent], +def pulse_drawer(data: Union[Waveform, Union[Schedule, Instruction]], dt: int = 1, style: Union[PulseStyle, SchedStyle] = None, filename: str = None, From 1fe0755cd2e611e8e9220115ebbd3a33afc19091 Mon Sep 17 00:00:00 2001 From: Wahaj Javed Date: Wed, 21 Oct 2020 20:01:01 +0500 Subject: [PATCH 2/9] Add ScheduleComponent deprecation release note --- .../notes/deprecate-schedule-component-e7ab3654fe4fb8bf.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/deprecate-schedule-component-e7ab3654fe4fb8bf.yaml diff --git a/releasenotes/notes/deprecate-schedule-component-e7ab3654fe4fb8bf.yaml b/releasenotes/notes/deprecate-schedule-component-e7ab3654fe4fb8bf.yaml new file mode 100644 index 000000000000..3d0d6e2adfc1 --- /dev/null +++ b/releasenotes/notes/deprecate-schedule-component-e7ab3654fe4fb8bf.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + The ``ScheduleComponent`` has been deprecated. Anywhere that currently accepts a ``ScheduleComponent`` should instead accept a ``Union[Schedule, Instruction]``.``ch_start_time`` channels argument has been deprecated. Refer to `#5076 ` for more details From ef7465fb90a621115ffb803ae5b0c4d9a06e7bc3 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Tue, 27 Oct 2020 14:55:47 -0300 Subject: [PATCH 3/9] Fix forward references. --- qiskit/pulse/instructions/instruction.py | 29 ++++++++------- qiskit/pulse/schedule.py | 45 +++++++++++++----------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index b4c4c9c1128b..f06d4eaf1dda 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -31,7 +31,6 @@ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError -from qiskit.pulse.schedule import Schedule # pylint: disable=missing-return-doc @@ -129,7 +128,7 @@ def duration(self) -> int: return self._duration @property - def _children(self) -> Tuple[Union[Schedule, 'Instruction']]: + def _children(self) -> Tuple[Union['Schedule', 'Instruction']]: """Instruction has no child nodes.""" return () @@ -177,8 +176,8 @@ def _instructions(self, time: int = 0) -> Iterable[Tuple[int, 'Instruction']]: time: Shifted time of this node due to parent Yields: - Tuple[int, ScheduleComponent]: Tuple containing time `ScheduleComponent` starts - at and the flattened `ScheduleComponent` + Tuple[int, Union['Schedule, 'Instruction']]: Tuple of the form + (start_time, instruction). """ yield (time, self) @@ -186,20 +185,22 @@ def flatten(self) -> 'Instruction': """Return itself as already single instruction.""" return self - def shift(self: Union[Schedule, 'Instruction'], - time: int, name: Optional[str] = None) -> Schedule: + def shift(self: Union['Schedule', 'Instruction'], + time: int, name: Optional[str] = None) -> 'Schedule': """Return a new schedule shifted forward by `time`. Args: time: Time to shift by name: Name of the new schedule. Defaults to name of self """ + from qiskit.pulse.schedule import Schedule + if name is None: name = self.name return Schedule((time, self), name=name) - def insert(self, start_time: int, schedule: Union[Schedule, 'Instruction'], - name: Optional[str] = None) -> Schedule: + def insert(self, start_time: int, schedule: Union['Schedule', 'Instruction'], + name: Optional[str] = None) -> 'Schedule': """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted within ``self`` at ``start_time``. @@ -208,12 +209,14 @@ def insert(self, start_time: int, schedule: Union[Schedule, 'Instruction'], schedule: Schedule to insert name: Name of the new schedule. Defaults to name of self """ + from qiskit.pulse.schedule import Schedule + if name is None: name = self.name return Schedule(self, (start_time, schedule), name=name) - def append(self, schedule: Union[Schedule, 'Instruction'], - name: Optional[str] = None) -> Schedule: + def append(self, schedule: Union['Schedule', 'Instruction'], + name: Optional[str] = None) -> 'Schedule': """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted at the maximum time over all channels shared between ``self`` and ``schedule``. @@ -307,15 +310,15 @@ def __hash__(self) -> int: self._hash = hash((type(self), self.operands, self.name)) return self._hash - def __add__(self, other: Union[Schedule, 'Instruction']) -> Schedule: + def __add__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': """Return a new schedule with `other` inserted within `self` at `start_time`.""" return self.append(other) - def __or__(self, other: Union[Schedule, 'Instruction']) -> Schedule: + def __or__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': """Return a new schedule which is the union of `self` and `other`.""" return self.insert(0, other) - def __lshift__(self, time: int) -> Schedule: + def __lshift__(self, time: int) -> 'Schedule': """Return a new schedule which is shifted forward by `time`.""" return self.shift(time) diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index 9ecf6bdf8977..94f620e83a16 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -24,6 +24,7 @@ from typing import List, Tuple, Iterable, Union, Dict, Callable, Set, Optional from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType +from qiskit.pulse import instructions as instructions_ # pylint: disable=cyclic-import, unused-import from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError from qiskit.util import is_main_process @@ -45,8 +46,8 @@ class Schedule(abc.ABC): prefix = 'sched' def __init__(self, - *schedules: Union[Union['Schedule', 'Instruction'], - Tuple[int, Union['Schedule', 'Instruction']]], + *schedules: Union[Union['Schedule', 'instructions_.Instruction'], + Tuple[int, Union['Schedule', 'instructions_.Instruction']]], name: Optional[str] = None): """Create an empty schedule. @@ -105,7 +106,7 @@ def channels(self) -> Tuple[Channel]: return tuple(self._timeslots.keys()) @property - def _children(self) -> Tuple[Tuple[int, Union['Schedule', 'Instruction']], ...]: + def _children(self) -> Tuple[Tuple[int, Union['Schedule', 'instructions_.Instruction']], ...]: """Return the child``NamedValues``s of this ``Schedule`` in the order they were added to the schedule. @@ -121,7 +122,7 @@ def instructions(self): """Get the time-ordered instructions from self. ReturnType: - Tuple[Tuple[int, 'Instruction'], ...] + Tuple[Tuple[int, 'instructions_.Instruction'], ...] """ def key(time_inst_pair): @@ -242,7 +243,7 @@ def _mutable_shift(self, # pylint: disable=arguments-differ def insert(self, start_time: int, - schedule: Union['Schedule', 'Instruction'], + schedule: Union['Schedule', 'instructions_.Instruction'], name: Optional[str] = None, inplace: bool = False ) -> 'Schedule': @@ -261,7 +262,7 @@ def insert(self, def _mutable_insert(self, start_time: int, - schedule: Union['Schedule', 'Instruction'] + schedule: Union['Schedule', 'instructions_.Instruction'] ) -> 'Schedule': """Mutably insert `schedule` into `self` at `start_time`. @@ -275,7 +276,7 @@ def _mutable_insert(self, def _immutable_insert(self, start_time: int, - schedule: Union['Schedule', 'Instruction'], + schedule: Union['Schedule', 'instructions_.Instruction'], name: Optional[str] = None, ) -> 'Schedule': """Return a new schedule with ``schedule`` inserted into ``self`` at ``start_time``. @@ -292,7 +293,7 @@ def _immutable_insert(self, return new_sched # pylint: disable=arguments-differ - def append(self, schedule: Union['Schedule', 'Instruction'], + def append(self, schedule: Union['Schedule', 'instructions_.Instruction'], name: Optional[str] = None, inplace: bool = False) -> 'Schedule': r"""Return a new schedule with ``schedule`` inserted at the maximum time over @@ -389,7 +390,7 @@ def _apply_filter(self, filter_func: Callable, new_sched_name: str) -> 'Schedule def _construct_filter(self, *filter_funcs: List[Callable], channels: Optional[Iterable[Channel]] = None, - instruction_types: Optional[Iterable['Instruction']] = None, + instruction_types: Optional[Iterable['instructions_.Instruction']] = None, time_ranges: Optional[Iterable[Tuple[int, int]]] = None, intervals: Optional[Iterable[Interval]] = None) -> Callable: """Returns a boolean-valued function with input type ``(int, ScheduleComponent)`` that @@ -469,7 +470,9 @@ def interval_filter(time_inst) -> bool: # return function returning true iff all filters are passed return lambda x: all([filter_func(x) for filter_func in filter_func_list]) - def _add_timeslots(self, time: int, schedule: Union['Schedule', 'Instruction']) -> None: + def _add_timeslots(self, + time: int, + schedule: Union['Schedule', 'instructions_.Instruction']) -> None: """Update all time tracking within this schedule based on the given schedule. Args: @@ -516,7 +519,9 @@ def _add_timeslots(self, time: int, schedule: Union['Schedule', 'Instruction']) _check_nonnegative_timeslot(self._timeslots) - def _remove_timeslots(self, time: int, schedule: Union['Schedule', 'Instruction']): + def _remove_timeslots(self, + time: int, + schedule: Union['Schedule', 'instructions_.Instruction']): """Delete the timeslots if present for the respective schedule component. Args: @@ -554,21 +559,21 @@ def _remove_timeslots(self, time: int, schedule: Union['Schedule', 'Instruction' def _replace_timeslots(self, time: int, - old: Union['Schedule', 'Instruction'], - new: Union['Schedule', 'Instruction']): + old: Union['Schedule', 'instructions_.Instruction'], + new: Union['Schedule', 'instructions_.Instruction']): """Replace the timeslots of ``old`` if present with the timeslots of ``new``. Args: time: The time to remove the timeslots for the ``schedule`` component. - old: 'Instruction' to replace. - new: 'Instruction' to replace with. + old: Instruction to replace. + new: Instruction to replace with. """ self._remove_timeslots(time, old) self._add_timeslots(time, new) def replace(self, - old: Union['Schedule', 'Instruction'], - new: Union['Schedule', 'Instruction'], + old: Union['Schedule', 'instructions_.Instruction'], + new: Union['Schedule', 'instructions_.Instruction'], inplace: bool = False, ) -> 'Schedule': """Return a schedule with the ``old`` instruction replaced with a ``new`` @@ -743,7 +748,7 @@ def draw(self, dt: float = 1, style=None, show_framechange_channels=show_framechange_channels, draw_title=draw_title) - def __eq__(self, other: Union['Schedule', 'Instruction']) -> bool: + def __eq__(self, other: Union['Schedule', 'instructions_.Instruction']) -> bool: """Test if two ScheduleComponents are equal. Equality is checked by verifying there is an equal instruction at every time @@ -780,11 +785,11 @@ def __eq__(self, other: Union['Schedule', 'Instruction']) -> bool: return True - def __add__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': + def __add__(self, other: Union['Schedule', 'instructions_.Instruction']) -> 'Schedule': """Return a new schedule with ``other`` inserted within ``self`` at ``start_time``.""" return self.append(other) - def __or__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': + def __or__(self, other: Union['Schedule', 'instructions_.Instruction']) -> 'Schedule': """Return a new schedule which is the union of `self` and `other`.""" return self.insert(0, other) From 4bc8aa6e2e6d4d1f564754f31b71667dbd01be53 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Tue, 27 Oct 2020 15:18:48 -0300 Subject: [PATCH 4/9] Linting. --- qiskit/pulse/schedule.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index 94f620e83a16..ab5d97d518c2 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -24,7 +24,8 @@ from typing import List, Tuple, Iterable, Union, Dict, Callable, Set, Optional from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType -from qiskit.pulse import instructions as instructions_ # pylint: disable=cyclic-import, unused-import +# pylint: disable=cyclic-import, unused-import +from qiskit.pulse import instructions as instructions_ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError from qiskit.util import is_main_process From 174195a6f0ca6642ee862a857fbeb2971b86ee37 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Tue, 27 Oct 2020 15:51:49 -0300 Subject: [PATCH 5/9] Remove warning causing docs to fail. --- qiskit/pulse/instructions/instruction.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index f06d4eaf1dda..823591f4ae35 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -155,8 +155,6 @@ def ch_start_time( Args: *channels: Supplied channels """ - warnings.warn("``ch_start_time`` channels argument has been deprecated and will be " - "removed in a future release", DeprecationWarning) return 0 def ch_stop_time(self, *channels: List[Channel]) -> int: From 98bd320d782b4f0f50afd77590dcd376b7327b16 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Tue, 27 Oct 2020 16:10:31 -0300 Subject: [PATCH 6/9] remove trailing whitespace. --- qiskit/pulse/schedule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index ab5d97d518c2..1ff1b1558ead 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -25,7 +25,7 @@ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType # pylint: disable=cyclic-import, unused-import -from qiskit.pulse import instructions as instructions_ +from qiskit.pulse import instructions as instructions_ from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError from qiskit.util import is_main_process From 796d8a5e0174c26dba66e1498e4f2951c4c440b8 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Wed, 28 Oct 2020 11:50:18 -0300 Subject: [PATCH 7/9] Remove schedule type annotations in instruction. --- qiskit/pulse/instructions/instruction.py | 57 +++++++++++++++++------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index 823591f4ae35..854dd4c97d18 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -128,7 +128,7 @@ def duration(self) -> int: return self._duration @property - def _children(self) -> Tuple[Union['Schedule', 'Instruction']]: + def _children(self) -> Tuple['Instruction']: """Instruction has no child nodes.""" return () @@ -183,13 +183,16 @@ def flatten(self) -> 'Instruction': """Return itself as already single instruction.""" return self - def shift(self: Union['Schedule', 'Instruction'], - time: int, name: Optional[str] = None) -> 'Schedule': + def shift(self, + time: int, name: Optional[str] = None): """Return a new schedule shifted forward by `time`. Args: time: Time to shift by name: Name of the new schedule. Defaults to name of self + + Returns: + Schedule: The shifted schedule. """ from qiskit.pulse.schedule import Schedule @@ -197,15 +200,18 @@ def shift(self: Union['Schedule', 'Instruction'], name = self.name return Schedule((time, self), name=name) - def insert(self, start_time: int, schedule: Union['Schedule', 'Instruction'], - name: Optional[str] = None) -> 'Schedule': + def insert(self, start_time: int, schedule, + name: Optional[str] = None): """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted within ``self`` at ``start_time``. Args: start_time: Time to insert the schedule schedule - schedule: Schedule to insert + schedule (Union['Schedule', 'Instruction']): Schedule or instruction to insert name: Name of the new schedule. Defaults to name of self + + Returns: + Schedule: A new schedule with ``schedule`` inserted with this instruction at t=0. """ from qiskit.pulse.schedule import Schedule @@ -213,14 +219,17 @@ def insert(self, start_time: int, schedule: Union['Schedule', 'Instruction'], name = self.name return Schedule(self, (start_time, schedule), name=name) - def append(self, schedule: Union['Schedule', 'Instruction'], - name: Optional[str] = None) -> 'Schedule': + def append(self, schedule, + name: Optional[str] = None): """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted at the maximum time over all channels shared between ``self`` and ``schedule``. Args: - schedule: schedule to be appended + schedule (Union['Schedule', 'Instruction']): Schedule or instruction to be appended name: Name of the new schedule. Defaults to name of self + + Returns: + Schedule: A new schedule with ``schedule`` a this instruction at t=0. """ common_channels = set(self.channels) & set(schedule.channels) time = self.ch_stop_time(*common_channels) @@ -308,16 +317,34 @@ def __hash__(self) -> int: self._hash = hash((type(self), self.operands, self.name)) return self._hash - def __add__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': - """Return a new schedule with `other` inserted within `self` at `start_time`.""" + def __add__(self, other): + """Return a new schedule with `other` inserted within `self` at `start_time`. + + Args: + other (Union['Schedule', 'Instruction']): Schedule or instruction to be appended + + Returns: + Schedule: A new schedule with ``schedule`` appended after this instruction at t=0. + """ return self.append(other) - def __or__(self, other: Union['Schedule', 'Instruction']) -> 'Schedule': - """Return a new schedule which is the union of `self` and `other`.""" + def __or__(self, other): + """Return a new schedule which is the union of `self` and `other`. + + Args: + other (Union['Schedule', 'Instruction']): Schedule or instruction to union with + + Returns: + Schedule: A new schedule with ``schedule`` inserted with this instruction at t=0 + """ return self.insert(0, other) - def __lshift__(self, time: int) -> 'Schedule': - """Return a new schedule which is shifted forward by `time`.""" + def __lshift__(self, time: int): + """Return a new schedule which is shifted forward by `time`. + + Returns: + Schedule: The shifted schedule + """ return self.shift(time) def __repr__(self) -> str: From 7d157184dcc3943d36641a92827ed3303261bd98 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Wed, 28 Oct 2020 11:53:23 -0300 Subject: [PATCH 8/9] Update Instruction type hint. --- qiskit/pulse/instructions/instruction.py | 2 +- qiskit/pulse/schedule.py | 38 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index 854dd4c97d18..e2f798ce551b 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -25,7 +25,7 @@ from abc import ABC -from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union +from typing import Callable, Dict, Iterable, List, Optional, Tuple import numpy as np from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index 1ff1b1558ead..36475a193b61 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -25,7 +25,7 @@ from qiskit.circuit.parameterexpression import ParameterExpression, ParameterValueType # pylint: disable=cyclic-import, unused-import -from qiskit.pulse import instructions as instructions_ +from qiskit.pulse.instructions import Instruction from qiskit.pulse.channels import Channel from qiskit.pulse.exceptions import PulseError from qiskit.util import is_main_process @@ -47,8 +47,8 @@ class Schedule(abc.ABC): prefix = 'sched' def __init__(self, - *schedules: Union[Union['Schedule', 'instructions_.Instruction'], - Tuple[int, Union['Schedule', 'instructions_.Instruction']]], + *schedules: Union[Union['Schedule', Instruction], + Tuple[int, Union['Schedule', Instruction]]], name: Optional[str] = None): """Create an empty schedule. @@ -107,7 +107,7 @@ def channels(self) -> Tuple[Channel]: return tuple(self._timeslots.keys()) @property - def _children(self) -> Tuple[Tuple[int, Union['Schedule', 'instructions_.Instruction']], ...]: + def _children(self) -> Tuple[Tuple[int, Union['Schedule', Instruction]], ...]: """Return the child``NamedValues``s of this ``Schedule`` in the order they were added to the schedule. @@ -123,7 +123,7 @@ def instructions(self): """Get the time-ordered instructions from self. ReturnType: - Tuple[Tuple[int, 'instructions_.Instruction'], ...] + Tuple[Tuple[int, Instruction], ...] """ def key(time_inst_pair): @@ -244,7 +244,7 @@ def _mutable_shift(self, # pylint: disable=arguments-differ def insert(self, start_time: int, - schedule: Union['Schedule', 'instructions_.Instruction'], + schedule: Union['Schedule', Instruction], name: Optional[str] = None, inplace: bool = False ) -> 'Schedule': @@ -263,7 +263,7 @@ def insert(self, def _mutable_insert(self, start_time: int, - schedule: Union['Schedule', 'instructions_.Instruction'] + schedule: Union['Schedule', Instruction] ) -> 'Schedule': """Mutably insert `schedule` into `self` at `start_time`. @@ -277,7 +277,7 @@ def _mutable_insert(self, def _immutable_insert(self, start_time: int, - schedule: Union['Schedule', 'instructions_.Instruction'], + schedule: Union['Schedule', Instruction], name: Optional[str] = None, ) -> 'Schedule': """Return a new schedule with ``schedule`` inserted into ``self`` at ``start_time``. @@ -294,7 +294,7 @@ def _immutable_insert(self, return new_sched # pylint: disable=arguments-differ - def append(self, schedule: Union['Schedule', 'instructions_.Instruction'], + def append(self, schedule: Union['Schedule', Instruction], name: Optional[str] = None, inplace: bool = False) -> 'Schedule': r"""Return a new schedule with ``schedule`` inserted at the maximum time over @@ -391,7 +391,7 @@ def _apply_filter(self, filter_func: Callable, new_sched_name: str) -> 'Schedule def _construct_filter(self, *filter_funcs: List[Callable], channels: Optional[Iterable[Channel]] = None, - instruction_types: Optional[Iterable['instructions_.Instruction']] = None, + instruction_types: Optional[Iterable[Instruction]] = None, time_ranges: Optional[Iterable[Tuple[int, int]]] = None, intervals: Optional[Iterable[Interval]] = None) -> Callable: """Returns a boolean-valued function with input type ``(int, ScheduleComponent)`` that @@ -473,7 +473,7 @@ def interval_filter(time_inst) -> bool: def _add_timeslots(self, time: int, - schedule: Union['Schedule', 'instructions_.Instruction']) -> None: + schedule: Union['Schedule', Instruction]) -> None: """Update all time tracking within this schedule based on the given schedule. Args: @@ -522,7 +522,7 @@ def _add_timeslots(self, def _remove_timeslots(self, time: int, - schedule: Union['Schedule', 'instructions_.Instruction']): + schedule: Union['Schedule', Instruction]): """Delete the timeslots if present for the respective schedule component. Args: @@ -560,8 +560,8 @@ def _remove_timeslots(self, def _replace_timeslots(self, time: int, - old: Union['Schedule', 'instructions_.Instruction'], - new: Union['Schedule', 'instructions_.Instruction']): + old: Union['Schedule', Instruction], + new: Union['Schedule', Instruction]): """Replace the timeslots of ``old`` if present with the timeslots of ``new``. Args: @@ -573,8 +573,8 @@ def _replace_timeslots(self, self._add_timeslots(time, new) def replace(self, - old: Union['Schedule', 'instructions_.Instruction'], - new: Union['Schedule', 'instructions_.Instruction'], + old: Union['Schedule', Instruction], + new: Union['Schedule', Instruction], inplace: bool = False, ) -> 'Schedule': """Return a schedule with the ``old`` instruction replaced with a ``new`` @@ -749,7 +749,7 @@ def draw(self, dt: float = 1, style=None, show_framechange_channels=show_framechange_channels, draw_title=draw_title) - def __eq__(self, other: Union['Schedule', 'instructions_.Instruction']) -> bool: + def __eq__(self, other: Union['Schedule', Instruction]) -> bool: """Test if two ScheduleComponents are equal. Equality is checked by verifying there is an equal instruction at every time @@ -786,11 +786,11 @@ def __eq__(self, other: Union['Schedule', 'instructions_.Instruction']) -> bool: return True - def __add__(self, other: Union['Schedule', 'instructions_.Instruction']) -> 'Schedule': + def __add__(self, other: Union['Schedule', Instruction]) -> 'Schedule': """Return a new schedule with ``other`` inserted within ``self`` at ``start_time``.""" return self.append(other) - def __or__(self, other: Union['Schedule', 'instructions_.Instruction']) -> 'Schedule': + def __or__(self, other: Union['Schedule', Instruction]) -> 'Schedule': """Return a new schedule which is the union of `self` and `other`.""" return self.insert(0, other) From 7fa40c5d37f38d146ca383cea7d0321356aa28e9 Mon Sep 17 00:00:00 2001 From: Thomas Alexander Date: Wed, 28 Oct 2020 12:38:58 -0300 Subject: [PATCH 9/9] Linting --- qiskit/pulse/instructions/instruction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index e2f798ce551b..1f415425d1ba 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -190,7 +190,7 @@ def shift(self, Args: time: Time to shift by name: Name of the new schedule. Defaults to name of self - + Returns: Schedule: The shifted schedule. """