From f022654fbe592e2b17f6229fd44a57a44a4bfe90 Mon Sep 17 00:00:00 2001 From: pollyshaw Date: Mon, 20 Jun 2022 22:45:28 +0100 Subject: [PATCH] Fixes #7078: Put slots in new tuple in acquire --- qiskit/pulse/instructions/acquire.py | 5 +++++ qiskit/pulse/instructions/instruction.py | 5 +++++ qiskit/pulse/schedule.py | 10 +++++++--- test/python/pulse/test_schedule.py | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/qiskit/pulse/instructions/acquire.py b/qiskit/pulse/instructions/acquire.py index a7abdd33ccf9..4e91723f00da 100644 --- a/qiskit/pulse/instructions/acquire.py +++ b/qiskit/pulse/instructions/acquire.py @@ -92,6 +92,11 @@ def channels(self) -> Tuple[AcquireChannel]: """Returns the channels that this schedule uses.""" return (self.channel,) + @property + def slots(self) -> Tuple[Union[MemorySlot, RegisterSlot]]: + """Returns the slots that this schedule uses.""" + return tuple(self.operands[ind] for ind in (2, 3) if self.operands[ind] is not None) + @property def duration(self) -> Union[int, ParameterExpression]: """Duration of this instruction.""" diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py index 5ddffab05e82..0585f6dcfa4b 100644 --- a/qiskit/pulse/instructions/instruction.py +++ b/qiskit/pulse/instructions/instruction.py @@ -86,6 +86,11 @@ def start_time(self) -> int: """Relative begin time of this instruction.""" return 0 + @property + def slots(self) -> Tuple[Channel]: + """Returns any slots that this schedule uses""" + return () + @property def stop_time(self) -> int: """Relative end time of this instruction.""" diff --git a/qiskit/pulse/schedule.py b/qiskit/pulse/schedule.py index 843e6030ebf3..687463d9cf90 100644 --- a/qiskit/pulse/schedule.py +++ b/qiskit/pulse/schedule.py @@ -523,7 +523,9 @@ def _add_timeslots(self, time: int, schedule: "ScheduleComponent") -> None: other_timeslots = _get_timeslots(schedule) self._duration = max(self._duration, time + schedule.duration) - for channel in schedule.channels: + for channel in schedule.channels + ( + schedule.slots if isinstance(schedule, Instruction) else () + ): if channel not in self._timeslots: if time == 0: self._timeslots[channel] = copy.copy(other_timeslots[channel]) @@ -575,7 +577,9 @@ def _remove_timeslots(self, time: int, schedule: "ScheduleComponent"): if not isinstance(time, int): raise PulseError("Schedule start time must be an integer.") - for channel in schedule.channels: + for channel in schedule.channels + ( + schedule.slots if isinstance(schedule, Instruction) else () + ): if channel not in self._timeslots: raise PulseError(f"The channel {channel} is not present in the schedule") @@ -1495,7 +1499,7 @@ def _get_timeslots(schedule: "ScheduleComponent") -> TimeSlots: if isinstance(schedule, Instruction): duration = schedule.duration instruction_duration_validation(duration) - timeslots = {channel: [(0, duration)] for channel in schedule.channels} + timeslots = {channel: [(0, duration)] for channel in schedule.channels + schedule.slots} elif isinstance(schedule, Schedule): timeslots = schedule.timeslots else: diff --git a/test/python/pulse/test_schedule.py b/test/python/pulse/test_schedule.py index 296f73fac63f..e8f6a2f5a84f 100644 --- a/test/python/pulse/test_schedule.py +++ b/test/python/pulse/test_schedule.py @@ -332,7 +332,7 @@ def test_schedule_with_acquire_on_single_qubit(self): ) self.assertEqual(len(sched_single.instructions), 2) - self.assertEqual(len(sched_single.channels), 2) + self.assertEqual(len(sched_single.channels), 6) def test_parametric_commands_in_sched(self): """Test that schedules can be built with parametric commands."""