Skip to content

Commit 654df7e

Browse files
lcapellutoeggerdjmtreinishmergify[bot]
authored
Command/Inst refactor: Pulses and Play (Qiskit#3936)
* Deprecate PulseCommands, create new Play Instruction-implementation. The Play instruction takes a Pulse and a PulseChannel. Pulse is a new class within the pulse library that is very close to the deprecated PulseCommand abstract class. The PulseCommand implementations (SamplePulse and the ParametricPulse subclasses) have been moved to the pulse library as well, subclassing from Pulse, and all valid arguments to Play. * Update import statements in Pulse * Fill in the implementation of some IP work like __call__ * Fill in and update documentation, complete import paths * fixup cyclic imports * IP updates to assemble_schedules for supporting Play instruction * Give all pulses a name arg and update reno note * Continue pulse_instruction conversion support for Play * Add support for Play in assemble schedules, fix style * Attempt to fix build error * Add missing name field to Constant pulse * To support __call__ from Pulse, I need to import Play, which means I can't import Pulse from Play (for typehints) for the timebeing * Fixup bugs introduced in SamplePulse * Update tests with new API * Add tests and fixup missing name passing * Fixup tests, remove deprecation warning from assemble execution, add hash and eq methods to pulses * Fixup docs * Update functional_pulse import path and Instruction type ref * try again with the type hints * Was missing updates to PulseCommand that needed to be migrated with the new Pulse class * Was missing docstring type documentation for unresolvable type * Was missing removal of PulseStyle in parametric pulses * The changes from the sphinx warrnings pass hadn't been moved with the migrated ParametricPulses module. Moved the drag pulse docstring over finally * Fix spacing in drag pulse docstring * The docs should finally build now * Update qiskit/pulse/instructions/play.py Co-Authored-By: eggerdj <38065505+eggerdj@users.noreply.github.com> * Update qiskit/pulse/pulse_lib/sample_pulse.py Co-Authored-By: eggerdj <38065505+eggerdj@users.noreply.github.com> * Apply suggestions from code review Co-Authored-By: eggerdj <38065505+eggerdj@users.noreply.github.com> * Documentation improvements * Test change because linux python35 is failing * Update releasenotes/notes/unify-instructions-and-commands-aaa6d8724b8a29d3.yaml Co-Authored-By: eggerdj <38065505+eggerdj@users.noreply.github.com> * Fix plotting Play instruction * style, line length * Attempt to fix failing test by comparing names directly * Handle all instruction types in add_instruction * Remove unused import * Update releasenotes/notes/unify-instructions-and-commands-aaa6d8724b8a29d3.yaml Co-Authored-By: Matthew Treinish <mtreinish@kortar.org> * Separate note about Play feature into two notes: Play feature and Pulse movement Co-authored-by: eggerdj <38065505+eggerdj@users.noreply.github.com> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 8dbefe9 commit 654df7e

24 files changed

+918
-619
lines changed

qiskit/assembler/assemble_schedules.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
from typing import Any, Dict, List, Tuple
1818

1919
from qiskit.exceptions import QiskitError
20-
from qiskit.pulse import Schedule, Delay, Acquire
20+
from qiskit.pulse import Schedule, Acquire, Delay, Play
21+
from qiskit.pulse.pulse_lib import ParametricPulse, SamplePulse
2122
from qiskit.pulse.commands import (Command, PulseInstruction, AcquireInstruction,
22-
DelayInstruction, SamplePulse, ParametricInstruction)
23+
DelayInstruction, ParametricInstruction)
2324
from qiskit.qobj import (PulseQobj, QobjHeader, QobjExperimentHeader,
2425
PulseQobjInstruction, PulseQobjExperimentConfig,
2526
PulseQobjExperiment, PulseQobjConfig, PulseLibraryItem)
@@ -170,15 +171,31 @@ def _assemble_instructions(
170171
acquire_instruction_map = defaultdict(list)
171172
for time, instruction in schedule.instructions:
172173

173-
if isinstance(instruction, ParametricInstruction):
174+
if isinstance(instruction, Play) and isinstance(instruction.pulse, ParametricPulse):
175+
pulse_shape = ParametricPulseShapes(type(instruction.pulse)).name
176+
if pulse_shape not in run_config.parametric_pulses:
177+
instruction = Play(instruction.pulse.get_sample_pulse(),
178+
instruction.channel,
179+
name=instruction.name)
180+
181+
if isinstance(instruction, ParametricInstruction): # deprecated
174182
pulse_shape = ParametricPulseShapes(type(instruction.command)).name
175183
if pulse_shape not in run_config.parametric_pulses:
176184
# Convert to SamplePulse if the backend does not support it
177185
instruction = PulseInstruction(instruction.command.get_sample_pulse(),
178186
instruction.channels[0],
179187
name=instruction.name)
180188

181-
if isinstance(instruction, PulseInstruction):
189+
if isinstance(instruction, Play) and isinstance(instruction.pulse, SamplePulse):
190+
name = instruction.pulse.name
191+
if instruction.pulse != user_pulselib.get(name):
192+
name = "{0}-{1:x}".format(name, hash(instruction.pulse.samples.tostring()))
193+
instruction = Play(SamplePulse(name=name, samples=instruction.pulse.samples),
194+
channel=instruction.channel,
195+
name=instruction.name)
196+
user_pulselib[name] = instruction.pulse
197+
198+
if isinstance(instruction, PulseInstruction): # deprecated
182199
name = instruction.command.name
183200
if name in user_pulselib and instruction.command != user_pulselib[name]:
184201
name = "{0}-{1:x}".format(name, hash(instruction.command.samples.tostring()))

qiskit/pulse/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@
132132

133133
from .channels import (DriveChannel, MeasureChannel, AcquireChannel,
134134
ControlChannel, RegisterSlot, MemorySlot)
135-
from .commands import (AcquireInstruction, FrameChange,
136-
PersistentValue, SamplePulse, ParametricPulse,
137-
ParametricInstruction, Gaussian,
138-
GaussianSquare, Drag, ConstantPulse, functional_pulse)
135+
from .commands import AcquireInstruction, FrameChange, PersistentValue
139136
from .configuration import LoConfig, LoRange, Kernel, Discriminator
140137
from .exceptions import PulseError
141138
from .instruction_schedule_map import InstructionScheduleMap
142-
from .instructions import Acquire, Instruction, Delay, ShiftPhase, Snapshot, SetFrequency
139+
from .instructions import Acquire, Instruction, Delay, Play, ShiftPhase, Snapshot, SetFrequency
143140
from .interfaces import ScheduleComponent
141+
from .pulse_lib import SamplePulse, Gaussian, GaussianSquare, Drag, ConstantPulse, ParametricPulse
142+
from .pulse_lib.samplers.decorators import functional_pulse
144143
from .schedule import Schedule

qiskit/pulse/commands/delay.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
"""Delay instruction. Deprecated path."""
1616
import warnings
1717

18+
from ..channels import Channel
1819
from ..instructions import Delay
1920
from ..instructions import Instruction
2021

2122

2223
class DelayInstruction(Instruction):
2324
"""Deprecated."""
2425

25-
def __init__(self, command: Delay, channel: Delay, name: str = None):
26+
def __init__(self, command: Delay, channel: Channel, name: str = None):
2627
"""Create a delay instruction from a delay command.
2728
2829
Args:

0 commit comments

Comments
 (0)