Skip to content

Commit

Permalink
Fixes Qiskit#7078: Put slots in new tuple in acquire
Browse files Browse the repository at this point in the history
  • Loading branch information
pollyshaw committed Jul 18, 2022
1 parent d659572 commit f022654
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions qiskit/pulse/instructions/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions qiskit/pulse/instructions/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
10 changes: 7 additions & 3 deletions qiskit/pulse/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/python/pulse/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit f022654

Please sign in to comment.