Skip to main contentIBM Quantum Documentation

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.
Reference(name, *extra_keys)Pulse compiler directive that refers to a subroutine.
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.
RelativeBarrier(*channels[, name])Pulse RelativeBarrier directive.
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.
TimeBlockade(duration, channel[, name])Pulse TimeBlockade directive.

These are all instances of the same base class:

Instruction

class qiskit.pulse.instructions.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 (str | None) – Optional display name for this instruction.

Pulse Library

qiskit.pulse.library

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

A pulse programmer can choose from one of several Pulse Models such as Waveform and SymbolicPulse to create a pulse program. The Waveform model directly stores the waveform data points in each class instance. This model provides the most flexibility to express arbitrary waveforms and allows a rapid prototyping of new control techniques. However, this model is typically memory inefficient and might be hard to scale to large-size quantum processors. A user can directly instantiate the Waveform class with samples argument which is usually a complex numpy array or any kind of array-like data.

In contrast, the SymbolicPulse model only stores the function and its parameters that generate the waveform in a class instance. It thus provides greater memory efficiency at the price of less flexibility in the waveform. This model also defines a small set of pulse subclasses in Parametric Pulse Representation which are commonly used in superconducting quantum processors. An instance of these subclasses can be serialized in the QPY Format while keeping the memory-efficient parametric representation of waveforms. Note that Waveform object can be generated from an instance of a SymbolicPulse which will set values for the parameters and sample the parametric expression to create the Waveform.

Pulse Models

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.
SymbolicPulse(pulse_type, duration[, ...])The pulse representation model with parameters and symbolic expressions.

Parametric Pulse Representation

Constant(duration, amp[, angle, name, ...])A simple constant pulse, with an amplitude value and a duration:
Drag(duration, amp, sigma, beta[, angle, ...])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[, angle, ...])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.
GaussianSquareDrag(duration, amp, sigma, beta)A square pulse with a Drag shaped rise and fall
gaussian_square_echo(duration, amp, sigma[, ...])An echoed Gaussian square pulse with an active tone overlaid on it.
GaussianDeriv(duration, amp, sigma[, angle, ...])An unnormalized Gaussian derivative pulse.
Sin(duration, amp, phase[, freq, angle, ...])A sinusoidal pulse.
Cos(duration, amp, phase[, freq, angle, ...])A cosine pulse.
Sawtooth(duration, amp, phase[, freq, ...])A sawtooth pulse.
Triangle(duration, amp, phase[, freq, ...])A triangle wave pulse.
Square(duration, amp, phase[, freq, angle, ...])A square wave pulse.
Sech(duration, amp, sigma[, angle, name, ...])An unnormalized sech pulse.
SechDeriv(duration, amp, sigma[, angle, ...])An unnormalized sech derivative pulse.

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(*args, **kwargs)Drive channels transmit signals to qubits which enact gate operations.
MeasureChannel(*args, **kwargs)Measure channels transmit measurement stimulus pulses for readout.
AcquireChannel(*args, **kwargs)Acquire channels are used to collect data.
ControlChannel(*args, **kwargs)Control channels provide supplementary control over the qubit to the drive channel.
RegisterSlot(*args, **kwargs)Classical resister slot channels represent classical registers (low-latency classical memory).
MemorySlot(*args, **kwargs)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 qiskit.pulse.channels.Channel(*args, **kwargs)

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 – 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, ...])Time-ordered sequence of instructions with alignment context.

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 qiskit.pulse.transforms.AlignmentKind(context_params)

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

qiskit.pulse.transforms.add_implicit_acquires(schedule, meas_map)

GitHub

Return a new schedule with implicit acquires from the measurement mapping replaced by explicit ones.

Warning

Since new acquires are being added, Memory Slots will be set to match the qubit index. This may overwrite your specification.

Parameters

Returns

A Schedule with the additional acquisition instructions.

Return type

Schedule

align_measures

qiskit.pulse.transforms.align_measures(schedules, inst_map=None, cal_gate='u3', max_calibration_duration=None, align_time=None, align_all=True)

GitHub

Return new schedules where measurements occur at the same physical time.

This transformation will align the first Acquire on every channel to occur at the same time.

Minimum measurement wait time (to allow for calibration pulses) is enforced and may be set with max_calibration_duration.

By default only instructions containing a AcquireChannel or MeasureChannel will be shifted. If you wish to keep the relative timing of all instructions in the schedule set align_all=True.

This method assumes that MeasureChannel(i) and AcquireChannel(i) correspond to the same qubit and the acquire/play instructions should be shifted together on these channels.

from qiskit import pulse
from qiskit.pulse import transforms
 
d0 = pulse.DriveChannel(0)
m0 = pulse.MeasureChannel(0)
a0 = pulse.AcquireChannel(0)
mem0 = pulse.MemorySlot(0)
 
sched = pulse.Schedule()
sched.append(pulse.Play(pulse.Constant(10, 0.5), d0), inplace=True)
sched.append(pulse.Play(pulse.Constant(10, 1.), m0).shift(sched.duration), inplace=True)
sched.append(pulse.Acquire(20, a0, mem0).shift(sched.duration), inplace=True)
 
sched_shifted = sched << 20
 
aligned_sched, aligned_sched_shifted = transforms.align_measures([sched, sched_shifted])
 
assert aligned_sched == aligned_sched_shifted

If it is desired to only shift acquisition and measurement stimulus instructions set the flag align_all=False:

aligned_sched, aligned_sched_shifted = transforms.align_measures(
    [sched, sched_shifted],
    align_all=False,
)
 
assert aligned_sched != aligned_sched_shifted

Parameters

  • schedules (Iterable[ScheduleComponent]) – Collection of schedules to be aligned together
  • inst_map (InstructionScheduleMap | None) – Mapping of circuit operations to pulse schedules
  • cal_gate (str) – The name of the gate to inspect for the calibration time
  • max_calibration_duration (int | None) – If provided, inst_map and cal_gate will be ignored
  • align_time (int | None) – If provided, this will be used as final align time.
  • align_all (bool | None) – Shift all instructions in the schedule such that they maintain their relative alignment with the shifted acquisition instruction. If False only the acquisition and measurement pulse instructions will be shifted.

Returns

The input list of schedules transformed to have their measurements aligned.

Raises

PulseError – If the provided alignment time is negative.

Return type

list[Schedule]

block_to_schedule

qiskit.pulse.transforms.block_to_schedule(block)

GitHub

Convert ScheduleBlock to Schedule.

Parameters

block (ScheduleBlock) – A ScheduleBlock to convert.

Returns

Scheduled pulse program.

Raises

  • UnassignedDurationError – When any instruction duration is not assigned.
  • PulseError – When the alignment context duration is shorter than the schedule duration.

Return type

Schedule

Note

This transform may insert barriers in between contexts.

compress_pulses

qiskit.pulse.transforms.compress_pulses(schedules)

GitHub

Optimization pass to replace identical pulses.

Parameters

schedules (list[qiskit.pulse.schedule.Schedule]) – Schedules to compress.

Returns

Compressed schedules.

Return type

list[qiskit.pulse.schedule.Schedule]

flatten

qiskit.pulse.transforms.flatten(program)

GitHub

Flatten (inline) any called nodes into a Schedule tree with no nested children.

Parameters

program (Schedule) – Pulse program to remove nested structure.

Returns

Flatten pulse program.

Raises

PulseError – When invalid data format is given.

Return type

Schedule

inline_subroutines

qiskit.pulse.transforms.inline_subroutines(program)

GitHub

Recursively remove call instructions and inline the respective subroutine instructions.

Assigned parameter values, which are stored in the parameter table, are also applied. The subroutine is copied before the parameter assignment to avoid mutation problem.

Parameters

program (Schedule |ScheduleBlock) – A program which may contain the subroutine, i.e. Call instruction.

Returns

A schedule without subroutine.

Raises

PulseError – When input program is not valid data format.

Return type

Schedule | ScheduleBlock

pad

qiskit.pulse.transforms.pad(schedule, channels=None, until=None, inplace=False, pad_with=None)

GitHub

Pad the input Schedule with Delay``s on all unoccupied timeslots until ``schedule.duration or until if not None.

Parameters

  • schedule (Schedule) – Schedule to pad.
  • channels (Iterable[chans.Channel] | None) – Channels to pad. Defaults to all channels in schedule if not provided. If the supplied channel is not a member of schedule it will be added.
  • until (int | None) – Time to pad until. Defaults to schedule.duration if not provided.
  • inplace (bool) – Pad this schedule by mutating rather than returning a new schedule.
  • pad_with (Type[instructions.Instruction] | None) – Pulse Instruction subclass to be used for padding. Default to Delay instruction.

Returns

The padded schedule.

Raises

PulseError – When non pulse instruction is set to pad_with.

Return type

Schedule

remove_directives

qiskit.pulse.transforms.remove_directives(schedule)

GitHub

Remove directives.

Parameters

schedule (Schedule) – A schedule to remove compiler directives.

Returns

A schedule without directives.

Return type

Schedule

remove_trivial_barriers

qiskit.pulse.transforms.remove_trivial_barriers(schedule)

GitHub

Remove trivial barriers with 0 or 1 channels.

Parameters

schedule (Schedule) – A schedule to remove trivial barriers.

Returns

A schedule without trivial barriers

Return type

schedule

DAG

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

block_to_dag

qiskit.pulse.transforms.block_to_dag(block)

GitHub

Convert schedule block instruction into DAG.

ScheduleBlock can be represented as a DAG as needed. For example, equality of two programs are efficiently checked on DAG representation.

from qiskit import pulse
 
my_gaussian0 = pulse.Gaussian(100, 0.5, 20)
my_gaussian1 = pulse.Gaussian(100, 0.3, 10)
 
with pulse.build() as sched1:
    with pulse.align_left():
        pulse.play(my_gaussian0, pulse.DriveChannel(0))
        pulse.shift_phase(1.57, pulse.DriveChannel(2))
        pulse.play(my_gaussian1, pulse.DriveChannel(1))
 
with pulse.build() as sched2:
    with pulse.align_left():
        pulse.shift_phase(1.57, pulse.DriveChannel(2))
        pulse.play(my_gaussian1, pulse.DriveChannel(1))
        pulse.play(my_gaussian0, pulse.DriveChannel(0))

Here the sched1 `` and ``sched2 are different implementations of the same program, but it is difficult to confirm on the list representation.

Another example is instruction optimization.

from qiskit import pulse
 
with pulse.build() as sched:
    with pulse.align_left():
        pulse.shift_phase(1.57, pulse.DriveChannel(1))
        pulse.play(my_gaussian0, pulse.DriveChannel(0))
        pulse.shift_phase(-1.57, pulse.DriveChannel(1))

In above program two shift_phase instructions can be cancelled out because they are consecutive on the same drive channel. This can be easily found on the DAG representation.

Parameters

block ("ScheduleBlock") – A schedule block to be converted.

Returns

Instructions in DAG representation.

Raises

PulseError – When the context is invalid subclass.

Return type

rx.PyDAG

Composite transform

A sequence of transformations to generate a target code.

target_qobj_transform

qiskit.pulse.transforms.target_qobj_transform(sched, remove_directives=True)

GitHub

A basic pulse program transformation for OpenPulse API execution.

Parameters

Returns

Transformed program for execution.

Return type

Schedule


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-1.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 pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.play(pulse.Constant(100, 1.0), d0)
 
pulse_prog.draw()
../_images/pulse-2.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 used like a normal Qiskit schedule.

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 Backend 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:

from math import pi
from qiskit.compiler import schedule
from qiskit.circuit import QuantumCircuit
 
from qiskit import pulse
from qiskit.providers.fake_provider import GenericBackendV2
 
backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True)
 
d2 = pulse.DriveChannel(2)
 
qc = QuantumCircuit(2)
# Hadamard
qc.rz(pi/2, 0)
qc.sx(0)
qc.rz(pi/2, 0)
 
qc.cx(0, 1)
 
bell_sched = schedule(qc, backend)
 
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_sched)
        pulse.play(pulse.Constant(bell_sched.duration, 0.02), d2)
        pulse.barrier(0, 1, 2)
        registers = pulse.measure_all()
 
decoupled_bell_prep_and_measure.draw()
../_images/pulse-3.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.compiler import schedule
 
from qiskit import pulse, QuantumCircuit
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
qc = QuantumCircuit(2, 2)
qc.cx(0, 1)
 
with pulse.build(backend) as pulse_prog:
    # Create a pulse.
    gaussian_pulse = pulse.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 schedule for a quantum circuit thereby inserting into
        # the pulse schedule.
        qc = QuantumCircuit(2, 2)
        qc.cx(0, 1)
        qc_sched = schedule(qc, backend)
        pulse.call(qc_sched)
 
 
        # 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

qiskit.pulse.builder.build(backend=None, schedule=None, name=None, default_alignment='left')

GitHub

Create a context manager for launching the imperative pulse builder DSL.

To enter a building context and starting building a pulse program:

from qiskit import transpile, pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.play(pulse.Constant(100, 0.5), d0)

While the output program pulse_prog cannot be executed as we are using a mock backend. If a real backend is being used, executing the program is done with:

backend.run(transpile(pulse_prog, backend))

Parameters

  • backend (Backend) – A Qiskit backend. If not supplied certain builder functionality will be unavailable.
  • schedule (ScheduleBlock | None) – A pulse ScheduleBlock in which your pulse program will be built.
  • name (str | None) – Name of pulse program to be built.
  • default_alignment (str |AlignmentKind | None) – Default scheduling alignment for builder. One of left, right, sequential or an alignment context.

Returns

A new builder context which has the active builder initialized.

Return type

ContextManager[ScheduleBlock]

Channels

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

from qiskit import pulse
from qiskit.providers.fake_provider import GenericBackendV2
 
backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
 
with pulse.build(backend) as drive_sched:
    d0 = pulse.drive_channel(0)
    print(d0)
DriveChannel(0)

acquire_channel

qiskit.pulse.builder.acquire_channel(qubit)

GitHub

Return AcquireChannel for qubit on the active builder backend.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend):
    assert pulse.acquire_channel(0) == pulse.AcquireChannel(0)
Note

Requires the active builder context to have a backend set.

Return type

AcquireChannel

control_channels

qiskit.pulse.builder.control_channels(*qubits)

GitHub

Return ControlChannel for qubit on the active builder backend.

Return the secondary drive channel for the given qubit – typically utilized for controlling multi-qubit interactions.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
with pulse.build(backend):
    assert pulse.control_channels(0, 1) == [pulse.ControlChannel(0)]
Note

Requires the active builder context to have a backend set.

Parameters

qubits (Iterable[int]) – Tuple or list of ordered qubits of the form (control_qubit, target_qubit).

Returns

List of control channels associated with the supplied ordered list of qubits.

Return type

list[qiskit.pulse.channels.ControlChannel]

drive_channel

qiskit.pulse.builder.drive_channel(qubit)

GitHub

Return DriveChannel for qubit on the active builder backend.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend):
    assert pulse.drive_channel(0) == pulse.DriveChannel(0)
Note

Requires the active builder context to have a backend set.

Return type

DriveChannel

measure_channel

qiskit.pulse.builder.measure_channel(qubit)

GitHub

Return MeasureChannel for qubit on the active builder backend.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend):
    assert pulse.measure_channel(0) == pulse.MeasureChannel(0)
Note

Requires the active builder context to have a backend set.

Return type

MeasureChannel

Instructions

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

from qiskit import pulse
from qiskit.providers.fake_provider import GenericBackendV2
 
backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
 
with pulse.build(backend) as drive_sched:
    d0 = pulse.drive_channel(0)
    a0 = pulse.acquire_channel(0)
 
    pulse.play(pulse.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.Gaussian(20, 1.0, 3.0), d0)
        pulse.play(pulse.Gaussian(20, -1.0, 3.0), d0)
 
    pulse.call(temp_sched)
    pulse.acquire(30, a0, pulse.MemorySlot(0))
 
drive_sched.draw()
../_images/pulse-4.png

acquire

qiskit.pulse.builder.acquire(duration, qubit_or_channel, register, **metadata)

GitHub

Acquire for a duration on a channel and store the result in a register.

Examples:

from qiskit import pulse
 
acq0 = pulse.AcquireChannel(0)
mem0 = pulse.MemorySlot(0)
 
with pulse.build() as pulse_prog:
    pulse.acquire(100, acq0, mem0)
 
    # measurement metadata
    kernel = pulse.configuration.Kernel('linear_discriminator')
    pulse.acquire(100, acq0, mem0, kernel=kernel)
Note

The type of data acquire will depend on the execution meas_level.

Parameters

  • duration (int) – Duration to acquire data for
  • qubit_or_channel (int | chans.AcquireChannel) – Either the qubit to acquire data for or the specific AcquireChannel to acquire on.
  • register (StorageLocation) – Location to store measured result.
  • metadata (Unpack[_MetaDataType]) – Additional metadata for measurement. See Acquire for more information.

Raises

exceptions.PulseError – If the register type is not supported.

barrier

qiskit.pulse.builder.barrier(*channels_or_qubits, name=None)

GitHub

Barrier directive for a set of channels and qubits.

This directive prevents the compiler from moving instructions across the barrier. Consider the case where we want to enforce that one pulse happens after another on separate channels, this can be done with:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(1)
 
with pulse.build(backend) as barrier_pulse_prog:
    pulse.play(pulse.Constant(10, 1.0), d0)
    pulse.barrier(d0, d1)
    pulse.play(pulse.Constant(10, 1.0), d1)

Of course this could have been accomplished with:

from qiskit.pulse import transforms
 
with pulse.build(backend) as aligned_pulse_prog:
    with pulse.align_sequential():
        pulse.play(pulse.Constant(10, 1.0), d0)
        pulse.play(pulse.Constant(10, 1.0), d1)
 
barrier_pulse_prog = transforms.target_qobj_transform(barrier_pulse_prog)
aligned_pulse_prog = transforms.target_qobj_transform(aligned_pulse_prog)
 
assert barrier_pulse_prog == aligned_pulse_prog

The barrier allows the pulse compiler to take care of more advanced scheduling alignment operations across channels. For example in the case where we are calling an outside circuit or schedule and want to align a pulse at the end of one call:

import math
from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
d0 = pulse.DriveChannel(0)
 
with pulse.build(backend) as pulse_prog:
    with pulse.align_right():
        pulse.call(backend.defaults().instruction_schedule_map.get('u1', (1,)))
        # Barrier qubit 1 and d0.
        pulse.barrier(1, d0)
        # Due to barrier this will play before the gate on qubit 1.
        pulse.play(pulse.Constant(10, 1.0), d0)
        # This will end at the same time as the pulse above due to
        # the barrier.
        pulse.call(backend.defaults().instruction_schedule_map.get('u1', (1,)))
Note

Requires the active builder context to have a backend set if qubits are barriered on.

Parameters

  • channels_or_qubits (chans.Channel | int) – Channels or qubits to barrier.
  • name (str | None) – Name for the barrier

call

qiskit.pulse.builder.call(target, name=None, value_dict=None, **kw_params)

GitHub

Call the subroutine within the currently active builder context with arbitrary parameters which will be assigned to the target program.

Note

If the target program is a ScheduleBlock, then a Reference instruction will be created and appended to the current context. The target program will be immediately assigned to the current scope as a subroutine. If the target program is Schedule, it will be wrapped by the Call instruction and appended to the current context to avoid a mixed representation of ScheduleBlock and Schedule. If the target program is a QuantumCircuit it will be scheduled and the new Schedule will be added as a Call instruction.

Examples

  1. Calling a schedule block (recommended)
from qiskit import circuit, pulse
from qiskit.providers.fake_provider import GenericBackendV2
 
backend = GenericBackendV2(num_qubits=5, calibrate_instructions=True)
 
with pulse.build() as x_sched:
    pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
 
with pulse.build() as pulse_prog:
    pulse.call(x_sched)
 
print(pulse_prog)
ScheduleBlock(
    ScheduleBlock(
        Play(
            Gaussian(duration=160, amp=(0.1+0j), sigma=40),
            DriveChannel(0)
        ),
        name="block0",
        transform=AlignLeft()
    ),
    name="block1",
    transform=AlignLeft()
)

The actual program is stored in the reference table attached to the schedule.

print(pulse_prog.references)
ReferenceManager:
  - ('block0', '634b3b50bd684e26a673af1fbd2d6c81'): ScheduleBlock(Play(Gaussian(...

In addition, you can call a parameterized target program with parameter assignment.

amp = circuit.Parameter("amp")
 
with pulse.build() as subroutine:
    pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(0))
 
with pulse.build() as pulse_prog:
    pulse.call(subroutine, amp=0.1)
    pulse.call(subroutine, amp=0.3)
 
print(pulse_prog)
ScheduleBlock(
    ScheduleBlock(
        Play(
            Gaussian(duration=160, amp=(0.1+0j), sigma=40),
            DriveChannel(0)
        ),
        name="block2",
        transform=AlignLeft()
    ),
    ScheduleBlock(
        Play(
            Gaussian(duration=160, amp=(0.3+0j), sigma=40),
            DriveChannel(0)
        ),
        name="block2",
        transform=AlignLeft()
    ),
    name="block3",
    transform=AlignLeft()
)

If there is a name collision between parameters, you can distinguish them by specifying each parameter object in a python dictionary. For example,

amp1 = circuit.Parameter('amp')
amp2 = circuit.Parameter('amp')
 
with pulse.build() as subroutine:
    pulse.play(pulse.Gaussian(160, amp1, 40), pulse.DriveChannel(0))
    pulse.play(pulse.Gaussian(160, amp2, 40), pulse.DriveChannel(1))
 
with pulse.build() as pulse_prog:
    pulse.call(subroutine, value_dict={amp1: 0.1, amp2: 0.3})
 
print(pulse_prog)
ScheduleBlock(
    ScheduleBlock(
        Play(Gaussian(duration=160, amp=(0.1+0j), sigma=40), DriveChannel(0)),
        Play(Gaussian(duration=160, amp=(0.3+0j), sigma=40), DriveChannel(1)),
        name="block4",
        transform=AlignLeft()
    ),
    name="block5",
    transform=AlignLeft()
)
  1. Calling a schedule
x_sched = backend.instruction_schedule_map.get("x", (0,))
 
with pulse.build(backend) as pulse_prog:
    pulse.call(x_sched)
 
print(pulse_prog)
ScheduleBlock(
    Call(
        Schedule(
            (
                0,
                Play(
                    Drag(
                        duration=160,
                        amp=(0.18989731546729305+0j),
                        sigma=40,
                        beta=-1.201258305015517,
                        name='drag_86a8'
                    ),
                    DriveChannel(0),
                    name='drag_86a8'
                )
            ),
            name="x"
        ),
        name='x'
    ),
    name="block6",
    transform=AlignLeft()
)

Currently, the backend calibrated gates are provided in the form of Schedule. The parameter assignment mechanism is available also for schedules. However, the called schedule is not treated as a reference.

Parameters

  • target (Schedule |ScheduleBlock | None) – Target circuit or pulse schedule to call.
  • name (str | None) – Optional. A unique name of subroutine if defined. When the name is explicitly provided, one cannot call different schedule blocks with the same name.
  • value_dict (dict[ParameterValueType, ParameterValueType] | None) – Optional. Parameters assigned to the target program. If this dictionary is provided, the target program is copied and then stored in the main built schedule and its parameters are assigned to the given values. This dictionary is keyed on Parameter objects, allowing parameter name collision to be avoided.
  • kw_params (ParameterValueType) – Alternative way to provide parameters. Since this is keyed on the string parameter name, the parameters having the same name are all updated together. If you want to avoid name collision, use value_dict with Parameter objects instead.

delay

qiskit.pulse.builder.delay(duration, channel, name=None)

GitHub

Delay on a channel for a duration.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.delay(10, d0)

Parameters

  • duration (int) – Number of cycles to delay for on channel.
  • channel (chans.Channel) – Channel to delay on.
  • name (str | None) – Name of the instruction.

play

qiskit.pulse.builder.play(pulse, channel, name=None)

GitHub

Play a pulse on a channel.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.play(pulse.Constant(10, 1.0), d0)

Parameters

  • pulse (library.Pulse | np.ndarray) – Pulse to play.
  • channel (chans.PulseChannel) – Channel to play pulse on.
  • name (str | None) – Name of the pulse.

reference

qiskit.pulse.builder.reference(name, *extra_keys)

GitHub

Refer to undefined subroutine by string keys.

A Reference instruction is implicitly created and a schedule can be separately registered to the reference at a later stage.

from qiskit import pulse
 
with pulse.build() as main_prog:
    pulse.reference("x_gate", "q0")
 
with pulse.build() as subroutine:
    pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
 
main_prog.assign_references(subroutine_dict={("x_gate", "q0"): subroutine})

Parameters

  • name (str) – Name of subroutine.
  • extra_keys (str) – Helper keys to uniquely specify the subroutine.

set_frequency

qiskit.pulse.builder.set_frequency(frequency, channel, name=None)

GitHub

Set the frequency of a pulse channel.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.set_frequency(1e9, d0)

Parameters

  • frequency (float) – Frequency in Hz to set channel to.
  • channel (chans.PulseChannel) – Channel to set frequency of.
  • name (str | None) – Name of the instruction.

set_phase

qiskit.pulse.builder.set_phase(phase, channel, name=None)

GitHub

Set the phase of a pulse channel.

Examples:

import math
 
from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.set_phase(math.pi, d0)

Parameters

  • phase (float) – Phase in radians to set channel carrier signal to.
  • channel (chans.PulseChannel) – Channel to set phase of.
  • name (str | None) – Name of the instruction.

shift_frequency

qiskit.pulse.builder.shift_frequency(frequency, channel, name=None)

GitHub

Shift the frequency of a pulse channel.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.shift_frequency(1e9, d0)

Parameters

  • frequency (float) – Frequency in Hz to shift channel frequency by.
  • channel (chans.PulseChannel) – Channel to shift frequency of.
  • name (str | None) – Name of the instruction.

shift_phase

qiskit.pulse.builder.shift_phase(phase, channel, name=None)

GitHub

Shift the phase of a pulse channel.

Examples:

import math
 
from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    pulse.shift_phase(math.pi, d0)

Parameters

  • phase (float) – Phase in radians to shift channel carrier signal by.
  • channel (chans.PulseChannel) – Channel to shift phase of.
  • name (str | None) – Name of the instruction.

snapshot

qiskit.pulse.builder.snapshot(label, snapshot_type='statevector')

GitHub

Simulator snapshot.

Examples:

from qiskit import pulse
 
with pulse.build() as pulse_prog:
    pulse.snapshot('first', 'statevector')

Parameters

  • label (str) – Label for snapshot.
  • snapshot_type (str) – Type of 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-5.png

align_equispaced

qiskit.pulse.builder.align_equispaced(duration)

GitHub

Equispaced alignment pulse scheduling context.

Pulse instructions within this context are scheduled with the same interval spacing such that the total length of the context block is duration. If the total free duration cannot be evenly divided by the number of instructions within the context, the modulo is split and then prepended and appended to the returned schedule. Delay instructions are automatically inserted in between pulses.

This context is convenient to write a schedule for periodical dynamic decoupling or the Hahn echo sequence.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
x90 = pulse.Gaussian(10, 0.1, 3)
x180 = pulse.Gaussian(10, 0.2, 3)
 
with pulse.build() as hahn_echo:
    with pulse.align_equispaced(duration=100):
        pulse.play(x90, d0)
        pulse.play(x180, d0)
        pulse.play(x90, d0)
 
hahn_echo.draw()
../_images/pulse-6.png

Parameters

duration (int |ParameterExpression) – Duration of this context. This should be larger than the schedule duration.

Yields

None

Return type

Generator[None, None, None]

Notes

The scheduling is performed for sub-schedules within the context rather than channel-wise. If you want to apply the equispaced context for each channel, you should use the context independently for channels.

align_func

qiskit.pulse.builder.align_func(duration, func)

GitHub

Callback defined alignment pulse scheduling context.

Pulse instructions within this context are scheduled at the location specified by arbitrary callback function position that takes integer index and returns the associated fractional location within [0, 1]. Delay instruction is automatically inserted in between pulses.

This context may be convenient to write a schedule of arbitrary dynamical decoupling sequences such as Uhrig dynamical decoupling.

Examples:

import numpy as np
from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
x90 = pulse.Gaussian(10, 0.1, 3)
x180 = pulse.Gaussian(10, 0.2, 3)
 
def udd10_pos(j):
    return np.sin(np.pi*j/(2*10 + 2))**2
 
with pulse.build() as udd_sched:
    pulse.play(x90, d0)
    with pulse.align_func(duration=300, func=udd10_pos):
        for _ in range(10):
            pulse.play(x180, d0)
    pulse.play(x90, d0)
 
udd_sched.draw()
../_images/pulse-7.png

Parameters

  • duration (int |ParameterExpression) – Duration of context. This should be larger than the schedule duration.
  • func (Callable[[int], float]) – A function that takes an index of sub-schedule and returns the fractional coordinate of of that sub-schedule. The returned value should be defined within [0, 1]. The pulse index starts from 1.

Yields

None

Return type

Generator[None, None, None]

Notes

The scheduling is performed for sub-schedules within the context rather than channel-wise. If you want to apply the numerical context for each channel, you need to apply the context independently to channels.

align_left

qiskit.pulse.builder.align_left()

GitHub

Left alignment pulse scheduling context.

Pulse instructions within this context are scheduled as early as possible by shifting them left to the earliest available time.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(1)
 
with pulse.build() as pulse_prog:
    with pulse.align_left():
        # this pulse will start at t=0
        pulse.play(pulse.Constant(100, 1.0), d0)
        # this pulse will start at t=0
        pulse.play(pulse.Constant(20, 1.0), d1)
pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
 
assert pulse_prog.ch_start_time(d0) == pulse_prog.ch_start_time(d1)

Yields

None

Return type

Generator[None, None, None]

align_right

qiskit.pulse.builder.align_right()

GitHub

Right alignment pulse scheduling context.

Pulse instructions within this context are scheduled as late as possible by shifting them right to the latest available time.

Examples:

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 = pulse.transforms.block_to_schedule(pulse_prog)
 
assert pulse_prog.ch_stop_time(d0) == pulse_prog.ch_stop_time(d1)

Yields

None

Return type

Generator[None, None, None]

align_sequential

qiskit.pulse.builder.align_sequential()

GitHub

Sequential alignment pulse scheduling context.

Pulse instructions within this context are scheduled sequentially in time such that no two instructions will be played at the same time.

Examples:

from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(1)
 
with pulse.build() as pulse_prog:
    with pulse.align_sequential():
        # this pulse will start at t=0
        pulse.play(pulse.Constant(100, 1.0), d0)
        # this pulse will also start at t=100
        pulse.play(pulse.Constant(20, 1.0), d1)
pulse_prog = pulse.transforms.block_to_schedule(pulse_prog)
 
assert pulse_prog.ch_stop_time(d0) == pulse_prog.ch_start_time(d1)

Yields

None

Return type

Generator[None, None, None]

frequency_offset

qiskit.pulse.builder.frequency_offset(frequency, *channels, compensate_phase=False)

GitHub

Shift the frequency of inputs channels on entry into context and undo on exit.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
d0 = pulse.DriveChannel(0)
 
with pulse.build(backend) as pulse_prog:
    # shift frequency by 1GHz
    with pulse.frequency_offset(1e9, d0):
        pulse.play(pulse.Constant(10, 1.0), d0)
 
assert len(pulse_prog.instructions) == 3
 
with pulse.build(backend) as pulse_prog:
    # Shift frequency by 1GHz.
    # Undo accumulated phase in the shifted frequency frame
    # when exiting the context.
    with pulse.frequency_offset(1e9, d0, compensate_phase=True):
        pulse.play(pulse.Constant(10, 1.0), d0)
 
assert len(pulse_prog.instructions) == 4

Parameters

  • frequency (float) – Amount of frequency offset in Hz.
  • channels (PulseChannel) – Channels to offset frequency of.
  • compensate_phase (bool) – Compensate for accumulated phase accumulated with respect to the channels’ frame at its initial frequency.

Yields

None

Return type

Generator[None, None, None]

phase_offset

qiskit.pulse.builder.phase_offset(phase, *channels)

GitHub

Shift the phase of input channels on entry into context and undo on exit.

Examples:

import math
 
from qiskit import pulse
 
d0 = pulse.DriveChannel(0)
 
with pulse.build() as pulse_prog:
    with pulse.phase_offset(math.pi, d0):
        pulse.play(pulse.Constant(10, 1.0), d0)
 
assert len(pulse_prog.instructions) == 3

Parameters

  • phase (float) – Amount of phase offset in radians.
  • channels (PulseChannel) – Channels to offset phase of.

Yields

None

Return type

Generator[None, None, None]

Macros

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

from qiskit import pulse
from qiskit.providers.fake_provider import GenericBackendV2
 
backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
 
with pulse.build(backend) as measure_sched:
    mem_slot = pulse.measure(0)
    print(mem_slot)
MemorySlot(0)

measure

qiskit.pulse.builder.measure(qubits, registers=None)

GitHub

Measure a qubit within the currently active builder context.

At the pulse level a measurement is composed of both a stimulus pulse and an acquisition instruction which tells the systems measurement unit to acquire data and process it. We provide this measurement macro to automate the process for you, but if desired full control is still available with acquire() and play().

To use the measurement it is as simple as specifying the qubit you wish to measure:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
qubit = 0
 
with pulse.build(backend) as pulse_prog:
    # Do something to the qubit.
    qubit_drive_chan = pulse.drive_channel(0)
    pulse.play(pulse.Constant(100, 1.0), qubit_drive_chan)
    # Measure the qubit.
    reg = pulse.measure(qubit)

For now it is not possible to do much with the handle to reg but in the future we will support using this handle to a result register to build up ones program. It is also possible to supply this register:

with pulse.build(backend) as pulse_prog:
    pulse.play(pulse.Constant(100, 1.0), qubit_drive_chan)
    # Measure the qubit.
    mem0 = pulse.MemorySlot(0)
    reg = pulse.measure(qubit, mem0)
 
assert reg == mem0
Note

Requires the active builder context to have a backend set.

Parameters

  • qubits (list[int] | int) – Physical qubit to measure.
  • registers (list[StorageLocation] | StorageLocation) – Register to store result in. If not selected the current behavior is to return the MemorySlot with the same index as qubit. This register will be returned.

Returns

The register the qubit measurement result will be stored in.

Return type

list[StorageLocation] | StorageLocation

measure_all

qiskit.pulse.builder.measure_all()

GitHub

Measure all qubits within the currently active builder context.

A simple macro function to measure all of the qubits in the device at the same time. This is useful for handling device meas_map and single measurement constraints.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend) as pulse_prog:
    # Measure all qubits and return associated registers.
    regs = pulse.measure_all()
Note

Requires the active builder context to have a backend set.

Returns

The registers the qubit measurement results will be stored in.

Return type

list[qiskit.pulse.channels.MemorySlot]

delay_qubits

qiskit.pulse.builder.delay_qubits(duration, *qubits)

GitHub

Insert delays on all the channels.Channels that correspond to the input qubits at the same time.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse3Q
 
backend = FakeOpenPulse3Q()
 
with pulse.build(backend) as pulse_prog:
    # Delay for 100 cycles on qubits 0, 1 and 2.
    regs = pulse.delay_qubits(100, 0, 1, 2)
Note

Requires the active builder context to have a backend set.

Parameters

  • duration (int) – Duration to delay for.
  • qubits (int) – Physical qubits to delay on. Delays will be inserted based on the channels returned by pulse.qubit_channels().

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.providers.fake_provider import GenericBackendV2
 
backend = GenericBackendV2(num_qubits=2, calibrate_instructions=True)
 
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

qiskit.pulse.builder.active_backend()

GitHub

Get the backend of the currently active builder context.

Returns

The active backend in the currently active

builder context.

Return type

Backend

Raises

exceptions.BackendNotSet – If the builder does not have a backend set.

num_qubits

qiskit.pulse.builder.num_qubits()

GitHub

Return number of qubits in the currently active backend.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend):
    print(pulse.num_qubits())
2
Note

Requires the active builder context to have a backend set.

Return type

int

qubit_channels

qiskit.pulse.builder.qubit_channels(qubit)

GitHub

Returns the set of channels associated with a qubit.

Examples:

from qiskit import pulse
from qiskit.providers.fake_provider import FakeOpenPulse2Q
 
backend = FakeOpenPulse2Q()
 
with pulse.build(backend):
    print(pulse.qubit_channels(0))
{MeasureChannel(0), ControlChannel(0), DriveChannel(0), AcquireChannel(0), ControlChannel(1)}
Note

Requires the active builder context to have a backend set.

Note

A channel may still be associated with another qubit in this list such as in the case where significant crosstalk exists.

Return type

set[qiskit.pulse.channels.Channel]

samples_to_seconds

qiskit.pulse.builder.samples_to_seconds(samples)

GitHub

Obtain the time in seconds that will elapse for the input number of samples on the active backend.

Parameters

samples (int | np.ndarray) – Number of samples to convert to time in seconds.

Returns

The time that elapses in samples.

Return type

float | np.ndarray

seconds_to_samples

qiskit.pulse.builder.seconds_to_samples(seconds)

GitHub

Obtain the number of samples that will elapse in seconds on the active backend.

Rounds down.

Parameters

seconds (float | np.ndarray) – Time in seconds to convert to samples.

Returns

The number of samples for the time to elapse

Return type

int | np.ndarray


Configuration

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

Exceptions

PulseError

exception qiskit.pulse.PulseError(*message)

GitHub

Errors raised by the pulse module.

Set the error message.

BackendNotSet

exception qiskit.pulse.BackendNotSet(*message)

GitHub

Raised if the builder context does not have a backend.

Set the error message.

NoActiveBuilder

exception qiskit.pulse.NoActiveBuilder(*message)

GitHub

Raised if no builder context is active.

Set the error message.

UnassignedDurationError

exception qiskit.pulse.UnassignedDurationError(*message)

GitHub

Raised if instruction duration is unassigned.

Set the error message.

UnassignedReferenceError

exception qiskit.pulse.UnassignedReferenceError(*message)

GitHub

Raised if subroutine is unassigned.

Set the error message.

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