Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK. Go to the latest version

Pulse

qiskit.pulse

Qiskit-Pulse is a pulse-level quantum programming kit. This lower level of programming offers the user more control than programming with QuantumCircuits.

Extracting the greatest performance from quantum hardware requires real-time pulse-level instructions. Pulse answers that need: it enables the quantum physicist user to specify the exact time dynamics of an experiment. It is especially powerful for error mitigation techniques.

The input is given as arbitrary, time-ordered signals (see: Instructions) scheduled in parallel over multiple virtual hardware or simulator resources (see: Channels). The system also allows the user to recover the time dynamics of the measured output.

This is sufficient to allow the quantum physicist to explore and correct for noise in a quantum system.


Instructions

qiskit.pulse.instructions

The instructions module holds the various Instructions which are supported by Qiskit Pulse. Instructions have operands, which typically include at least one Channel specifying where the instruction will be applied.

Every instruction has a duration, whether explicitly included as an operand or implicitly defined. For instance, a ShiftPhase instruction can be instantiated with operands phase and channel, for some float phase and a Channel channel:

ShiftPhase(phase, channel)

The duration of this instruction is implicitly zero. On the other hand, the Delay instruction takes an explicit duration:

Delay(duration, channel)

An instruction can be added to a Schedule, which is a sequence of scheduled Pulse Instruction s over many channels. Instruction s and Schedule s implement the same interface.

Acquire(duration, channel[, mem_slot, …])The Acquire instruction is used to trigger the ADC associated with a particular qubit; e.g.
Call(subroutine[, value_dict, name])Pulse Call instruction.
Delay(duration, channel[, name])A blocking instruction with no other effect.
Play(pulse, channel[, name])This instruction is responsible for applying a pulse on a channel.
SetFrequency(frequency, channel[, name])Set the channel frequency.
ShiftFrequency(frequency, channel[, name])Shift the channel frequency away from the current frequency.
SetPhase(phase, channel[, name])The set phase instruction sets the phase of the proceeding pulses on that channel to phase radians.
ShiftPhase(phase, channel[, name])The shift phase instruction updates the modulation phase of proceeding pulses played on the same Channel.
Snapshot(label[, snapshot_type, name])An instruction targeted for simulators, to capture a moment in the simulation.

These are all instances of the same base class:

Instruction

class Instruction(operands, name=None)

GitHub

The smallest schedulable unit: a single instruction. It has a fixed duration and specified channels.

Instruction initializer.

Parameters

  • operands (Tuple) – The argument list.
  • name (Optional[str]) – Optional display name for this instruction.

Raises

  • PulseError – If duration is negative.
  • PulseError – If the input channels are not all of type Channel.

Pulse Library (waveforms )

qiskit.pulse.library

This library provides Pulse users with convenient methods to build Pulse waveforms.

Arbitrary waveforms can be described with Waveforms.

The discrete module will generate Waveforms for common waveform envelopes.

The parametric pulses, Gaussian, GaussianSquare, Drag and Constant will generate parameterized descriptions of those pulses, which can greatly reduce the size of the job sent to the backend.

discreteModule for builtin discrete pulses.
Waveform(samples[, name, epsilon, …])A pulse specified completely by complex-valued samples; each sample is played for the duration of the backend cycle-time, dt.
Constant(duration, amp[, name, limit_amplitude])A simple constant pulse, with an amplitude value and a duration:
Drag(duration, amp, sigma, beta[, name, …])The Derivative Removal by Adiabatic Gate (DRAG) pulse is a standard Gaussian pulse with an additional Gaussian derivative component and lifting applied.
Gaussian(duration, amp, sigma[, name, …])A lifted and truncated pulse envelope shaped according to the Gaussian function whose mean is centered at the center of the pulse (duration / 2):
GaussianSquare(duration, amp, sigma[, …])A square pulse with a Gaussian shaped risefall on both sides lifted such that its first sample is zero.

Channels

qiskit.pulse.channels

Pulse is meant to be agnostic to the underlying hardware implementation, while still allowing low-level control. Therefore, our signal channels are virtual hardware channels. The backend which executes our programs is responsible for mapping these virtual channels to the proper physical channel within the quantum control hardware.

Channels are characterized by their type and their index. Channels include:

Novel channel types can often utilize the ControlChannel, but if this is not sufficient, new channel types can be created. Then, they must be supported in the PulseQobj schema and the assembler. Channels are characterized by their type and their index. See each channel type below to learn more.

DriveChannel(index)Drive channels transmit signals to qubits which enact gate operations.
MeasureChannel(index)Measure channels transmit measurement stimulus pulses for readout.
AcquireChannel(index)Acquire channels are used to collect data.
ControlChannel(index)Control channels provide supplementary control over the qubit to the drive channel.
RegisterSlot(index)Classical resister slot channels represent classical registers (low-latency classical memory).
MemorySlot(index)Memory slot channels represent classical memory storage.
SnapshotChannel(*args, **kwargs)Snapshot channels are used to specify instructions for simulators.

All channels are children of the same abstract base class:

Channel

class Channel(index)

GitHub

Base class of channels. Channels provide a Qiskit-side label for typical quantum control hardware signal channels. The final label -> physical channel mapping is the responsibility of the hardware backend. For instance, DriveChannel(0) holds instructions which the backend should map to the signal line driving gate operations on the qubit labeled (indexed) 0.

When serialized channels are identified by their serialized name <prefix><index>. The type of the channel is interpreted from the prefix, and the index often (but not always) maps to the qubit index. All concrete channel classes must have a prefix class attribute (and instances of that class have an index attribute). Base classes which have prefix set to None are prevented from being instantiated.

To implement a new channel inherit from Channel and provide a unique string identifier for the prefix class attribute.

Channel class.

Parameters

index (int) – Index of channel.


Schedules

Schedules are Pulse programs. They describe instruction sequences for the control hardware. The Schedule is one of the most fundamental objects to this pulse-level programming module. A Schedule is a representation of a program in Pulse. Each schedule tracks the time of each instruction occuring in parallel over multiple signal channels.

Schedule(*schedules[, name, metadata])A quantum program schedule with exact time constraints for its instructions, operating over all input signal channels and supporting special syntaxes for building.
ScheduleBlock([name, metadata, …])A ScheduleBlock is a time-ordered sequence of instructions and transform macro to manage their relative timing.

Pulse Transforms

qiskit.pulse.transforms

The pulse transforms provide transformation routines to reallocate and optimize pulse programs for backends.

Alignments

The alignment transforms define alignment policies of instructions in ScheduleBlock. These transformations are called to create Schedules from ScheduleBlocks.

AlignEquispaced(duration)Align instructions with equispaced interval within a specified duration.
AlignFunc(duration, func)Allocate instructions at position specified by callback function.
AlignLeft()Align instructions in as-soon-as-possible manner.
AlignRight()Align instructions in as-late-as-possible manner.
AlignSequential()Align instructions sequentially.

These are all subtypes of the abstract base class AlignmentKind.

AlignmentKind

class AlignmentKind

GitHub

An abstract class for schedule alignment.

Create new context.

Canonicalization

The canonicalization transforms convert schedules to a form amenable for execution on OpenPulse backends.

add_implicit_acquires(schedule, meas_map)Return a new schedule with implicit acquires from the measurement mapping replaced by explicit ones.
align_measures(schedules[, inst_map, …])Return new schedules where measurements occur at the same physical time.
block_to_schedule(block)Convert ScheduleBlock to Schedule.
compress_pulses(schedules)Optimization pass to replace identical pulses.
flatten(program)Flatten (inline) any called nodes into a Schedule tree with no nested children.
inline_subroutines(program)Recursively remove call instructions and inline the respective subroutine instructions.
pad(schedule[, channels, until, inplace])Pad the input Schedule with Delay``s on all unoccupied timeslots until ``schedule.duration or until if not None.
remove_directives(schedule)Remove directives.
remove_trivial_barriers(schedule)Remove trivial barriers with 0 or 1 channels.

DAG

The DAG transforms create DAG representation of input program. This can be used for optimization of instructions and equality checks.

block_to_dag(block)Convert schedule block instruction into DAG.

Composite transform

A sequence of transformations to generate a target code.

target_qobj_transform(sched[, remove_directives])A basic pulse program transformation for OpenPulse API execution.

Pulse Builder

Use the pulse builder DSL to write pulse programs with an imperative syntax.

Warning

The pulse builder interface is still in active development. It may have breaking API changes without deprecation warnings in future releases until otherwise indicated.

The pulse builder provides an imperative API for writing pulse programs with less difficulty than the Schedule API. It contextually constructs a pulse schedule and then emits the schedule for execution. For example, to play a series of pulses on channels is as simple as:

from qiskit import pulse
 
dc = pulse.DriveChannel
d0, d1, d2, d3, d4 = dc(0), dc(1), dc(2), dc(3), dc(4)
 
with pulse.build(name='pulse_programming_in') as pulse_prog:
    pulse.play([1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1], d0)
    pulse.play([1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0], d1)
    pulse.play([1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0], d2)
    pulse.play([1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0], d3)
    pulse.play([1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0], d4)
 
pulse_prog.draw()
../_images/pulse_0_0.png

To begin pulse programming we must first initialize our program builder context with build(), after which we can begin adding program statements. For example, below we write a simple program that play()s a pulse:

from qiskit import execute, pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.play(pulse.Constant(100, 1.0), d0)
 
pulse_prog.draw()
../_images/pulse_1_0.png

The builder initializes a pulse.Schedule, pulse_prog and then begins to construct the program within the context. The output pulse schedule will survive after the context is exited and can be executed like a normal Qiskit schedule using qiskit.execute(pulse_prog, backend).

Pulse programming has a simple imperative style. This leaves the programmer to worry about the raw experimental physics of pulse programming and not constructing cumbersome data structures.

We can optionally pass a BaseBackend to build() to enable enhanced functionality. Below, we prepare a Bell state by automatically compiling the required pulses from their gate-level representations, while simultaneously applying a long decoupling pulse to a neighboring qubit. We terminate the experiment with a measurement to observe the state we prepared. This program which mixes circuits and pulses will be automatically lowered to be run as a pulse program:

import math
 
from qiskit import pulse
from qiskit.test.mock import FakeOpenPulse3Q
 
# TODO: This example should use a real mock backend.
backend = FakeOpenPulse3Q()
 
d2 = pulse.DriveChannel(2)
 
with pulse.build(backend) as bell_prep:
    pulse.u2(0, math.pi, 0)
    pulse.cx(0, 1)
 
with pulse.build(backend) as decoupled_bell_prep_and_measure:
    # We call our bell state preparation schedule constructed above.
    with pulse.align_right():
        pulse.call(bell_prep)
        pulse.play(pulse.Constant(bell_prep.duration, 0.02), d2)
        pulse.barrier(0, 1, 2)
        registers = pulse.measure_all()
 
decoupled_bell_prep_and_measure.draw()
../_images/pulse_2_1.png

With the pulse builder we are able to blend programming on qubits and channels. While the pulse schedule is based on instructions that operate on channels, the pulse builder automatically handles the mapping from qubits to channels for you.

In the example below we demonstrate some more features of the pulse builder:

import math
 
from qiskit import pulse, QuantumCircuit
from qiskit.pulse import library
from qiskit.test.mock import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend) as pulse_prog:
    # Create a pulse.
    gaussian_pulse = library.gaussian(10, 1.0, 2)
    # Get the qubit's corresponding drive channel from the backend.
    d0 = pulse.drive_channel(0)
    d1 = pulse.drive_channel(1)
    # Play a pulse at t=0.
    pulse.play(gaussian_pulse, d0)
    # Play another pulse directly after the previous pulse at t=10.
    pulse.play(gaussian_pulse, d0)
    # The default scheduling behavior is to schedule pulses in parallel
    # across channels. For example, the statement below
    # plays the same pulse on a different channel at t=0.
    pulse.play(gaussian_pulse, d1)
 
    # We also provide pulse scheduling alignment contexts.
    # The default alignment context is align_left.
 
    # The sequential context schedules pulse instructions sequentially in time.
    # This context starts at t=10 due to earlier pulses above.
    with pulse.align_sequential():
        pulse.play(gaussian_pulse, d0)
        # Play another pulse after at t=20.
        pulse.play(gaussian_pulse, d1)
 
        # We can also nest contexts as each instruction is
        # contained in its local scheduling context.
        # The output of a child context is a context-schedule
        # with the internal instructions timing fixed relative to
        # one another. This is schedule is then called in the parent context.
 
        # Context starts at t=30.
        with pulse.align_left():
            # Start at t=30.
            pulse.play(gaussian_pulse, d0)
            # Start at t=30.
            pulse.play(gaussian_pulse, d1)
        # Context ends at t=40.
 
        # Alignment context where all pulse instructions are
        # aligned to the right, ie., as late as possible.
        with pulse.align_right():
            # Shift the phase of a pulse channel.
            pulse.shift_phase(math.pi, d1)
            # Starts at t=40.
            pulse.delay(100, d0)
            # Ends at t=140.
 
            # Starts at t=130.
            pulse.play(gaussian_pulse, d1)
            # Ends at t=140.
 
        # Acquire data for a qubit and store in a memory slot.
        pulse.acquire(100, 0, pulse.MemorySlot(0))
 
        # We also support a variety of macros for common operations.
 
        # Measure all qubits.
        pulse.measure_all()
 
        # Delay on some qubits.
        # This requires knowledge of which channels belong to which qubits.
        # delay for 100 cycles on qubits 0 and 1.
        pulse.delay_qubits(100, 0, 1)
 
        # Call a quantum circuit. The pulse builder lazily constructs a quantum
        # circuit which is then transpiled and scheduled before inserting into
        # a pulse schedule.
        # NOTE: Quantum register indices correspond to physical qubit indices.
        qc = QuantumCircuit(2, 2)
        qc.cx(0, 1)
        pulse.call(qc)
        # Calling a small set of standard gates and decomposing to pulses is
        # also supported with more natural syntax.
        pulse.u3(0, math.pi, 0, 0)
        pulse.cx(0, 1)
 
 
        # It is also be possible to call a preexisting schedule
        tmp_sched = pulse.Schedule()
        tmp_sched += pulse.Play(gaussian_pulse, d0)
        pulse.call(tmp_sched)
 
        # We also support:
 
        # frequency instructions
        pulse.set_frequency(5.0e9, d0)
 
        # phase instructions
        pulse.shift_phase(0.1, d0)
 
        # offset contexts
        with pulse.phase_offset(math.pi, d0):
            pulse.play(gaussian_pulse, d0)

The above is just a small taste of what is possible with the builder. See the rest of the module documentation for more information on its capabilities.

build([backend, schedule, name, …])Create a context manager for launching the imperative pulse builder DSL.

Channels

Methods to return the correct channels for the respective qubit indices.

from qiskit import pulse
from qiskit.test.mock import FakeArmonk
 
backend = FakeArmonk()
 
with pulse.build(backend) as drive_sched:
    d0 = pulse.drive_channel(0)
    print(d0)
DriveChannel(0)
acquire_channel(qubit)Return AcquireChannel for qubit on the active builder backend.
control_channels(*qubits)Return ControlChannel for qubit on the active builder backend.
drive_channel(qubit)Return DriveChannel for qubit on the active builder backend.
measure_channel(qubit)Return MeasureChannel for qubit on the active builder backend.

Instructions

Pulse instructions are available within the builder interface. Here’s an example:

from qiskit import pulse
from qiskit.test.mock import FakeArmonk
 
backend = FakeArmonk()
 
with pulse.build(backend) as drive_sched:
    d0 = pulse.drive_channel(0)
    a0 = pulse.acquire_channel(0)
 
    pulse.play(pulse.library.Constant(10, 1.0), d0)
    pulse.delay(20, d0)
    pulse.shift_phase(3.14/2, d0)
    pulse.set_phase(3.14, d0)
    pulse.shift_frequency(1e7, d0)
    pulse.set_frequency(5e9, d0)
 
    with pulse.build() as temp_sched:
        pulse.play(pulse.library.Gaussian(20, 1.0, 3.0), d0)
        pulse.play(pulse.library.Gaussian(20, -1.0, 3.0), d0)
 
    pulse.call(temp_sched)
    pulse.acquire(30, a0, pulse.MemorySlot(0))
 
drive_sched.draw()
../_images/pulse_5_0.png
acquire(duration, qubit_or_channel, …)Acquire for a duration on a channel and store the result in a register.
barrier(*channels_or_qubits[, name])Barrier directive for a set of channels and qubits.
call(target[, name, value_dict])Call the target within the currently active builder context with arbitrary parameters which will be assigned to the target program.
delay(duration, channel[, name])Delay on a channel for a duration.
play(pulse, channel[, name])Play a pulse on a channel.
set_frequency(frequency, channel[, name])Set the frequency of a pulse channel.
set_phase(phase, channel[, name])Set the phase of a pulse channel.
shift_frequency(frequency, channel[, name])Shift the frequency of a pulse channel.
shift_phase(phase, channel[, name])Shift the phase of a pulse channel.
snapshot(label[, snapshot_type])Simulator snapshot.

Contexts

Builder aware contexts that modify the construction of a pulse program. For example an alignment context like align_right() may be used to align all pulses as late as possible in a pulse program.

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(1)
 
with pulse.build() as pulse_prog:
    with pulse.align_right():
        # this pulse will start at t=0
        pulse.play(pulse.Constant(100, 1.0), d0)
        # this pulse will start at t=80
        pulse.play(pulse.Constant(20, 1.0), d1)
 
pulse_prog.draw()
../_images/pulse_6_0.png
align_equispaced(duration)Equispaced alignment pulse scheduling context.
align_func(duration, func)Callback defined alignment pulse scheduling context.
align_left()Left alignment pulse scheduling context.
align_right()Right alignment pulse scheduling context.
align_sequential()Sequential alignment pulse scheduling context.
circuit_scheduler_settings(**settings)Set the currently active circuit scheduler settings for this context.
frequency_offset(frequency, *channels[, …])Shift the frequency of inputs channels on entry into context and undo on exit.
inline()Deprecated.
pad(*chs)Deprecated.
phase_offset(phase, *channels)Shift the phase of input channels on entry into context and undo on exit.
transpiler_settings(**settings)Set the currently active transpiler settings for this context.

Macros

Macros help you add more complex functionality to your pulse program.

from qiskit import pulse
from qiskit.test.mock import FakeArmonk
 
backend = FakeArmonk()
 
with pulse.build(backend) as measure_sched:
    mem_slot = pulse.measure(0)
    print(mem_slot)
MemorySlot(0)
measure(qubits[, registers])Measure a qubit within the currently active builder context.
measure_all()Measure all qubits within the currently active builder context.
delay_qubits(duration, *qubits)Insert delays on all of the channels.Channels that correspond to the input qubits at the same time.

Circuit Gates

To use circuit level gates within your pulse program call a circuit with call().

Warning

These will be removed in future versions with the release of a circuit builder interface in which it will be possible to calibrate a gate in terms of pulses and use that gate in a circuit.

import math
 
from qiskit import pulse
from qiskit.test.mock import FakeArmonk
 
backend = FakeArmonk()
 
with pulse.build(backend) as u3_sched:
    pulse.u3(math.pi, 0, math.pi, 0)
cx(control, target)Call a CXGate on the input physical qubits.
u1(theta, qubit)Call a U1Gate on the input physical qubit.
u2(phi, lam, qubit)Call a U2Gate on the input physical qubit.
u3(theta, phi, lam, qubit)Call a U3Gate on the input physical qubit.
x(qubit)Call a XGate on the input physical qubit.

Utilities

The utility functions can be used to gather attributes about the backend and modify how the program is built.

from qiskit import pulse
 
from qiskit.test.mock import FakeArmonk
 
backend = FakeArmonk()
 
with pulse.build(backend) as u3_sched:
    print('Number of qubits in backend: {}'.format(pulse.num_qubits()))
 
    samples = 160
    print('There are {} samples in {} seconds'.format(
        samples, pulse.samples_to_seconds(160)))
 
    seconds = 1e-6
    print('There are {} seconds in {} samples.'.format(
        seconds, pulse.seconds_to_samples(1e-6)))
Number of qubits in backend: 1
There are 160 samples in 3.5555555555555554e-08 seconds
There are 1e-06 seconds in 4500 samples.
active_backend()Get the backend of the currently active builder context.
active_transpiler_settings()Return the current active builder context’s transpiler settings.
active_circuit_scheduler_settings()Return the current active builder context’s circuit scheduler settings.
num_qubits()Return number of qubits in the currently active backend.
qubit_channels(qubit)Returns the set of channels associated with a qubit.
samples_to_seconds(samples)Obtain the time in seconds that will elapse for the input number of samples on the active backend.
seconds_to_samples(seconds)Obtain the number of samples that will elapse in seconds on the active backend.

Configuration

InstructionScheduleMap()Mapping from QuantumCircuit qiskit.circuit.Instruction names and qubits to Schedule s. In particular, the mapping is formatted as type::.

Exceptions

PulseError

class PulseError(*message)

GitHub

Errors raised by the pulse module.

Set the error message.

Was this page helpful?
Report a bug or request content on GitHub.