Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version


barrier(*channels_or_qubits, name=None)

GitHub(opens in a new tab)

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 as barrier_pulse_prog:, 1.0), d0)
    pulse.barrier(d0, d1), 1.0), d1)

Of course this could have been accomplished with:

from qiskit.pulse import transforms
with as aligned_pulse_prog:
    with pulse.align_sequential():, 1.0), d0), 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
d0 = pulse.DriveChannel(0)
with as pulse_prog:
    with pulse.align_right():
        # Barrier qubit 1 and d0.
        pulse.barrier(1, d0)
        # Due to barrier this will play before the gate on qubit 1., 1.0), d0)
        # This will end at the same time as the pulse above due to
        # the barrier.

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


  • channels_or_qubits (Union[Channel, int]) – Channels or qubits to barrier.
  • name (Optional[str]) – Name for the barrier
Was this page helpful?
Report a bug or request content on GitHub.