@@ -759,6 +759,20 @@ def append_instruction(instruction: instructions.Instruction):
759759def num_qubits () -> int :
760760 """Return number of qubits in the currently active backend.
761761
762+ Examples:
763+
764+ .. code-block:: python
765+
766+ from qiskit import pulse
767+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
768+ backend = FakeOpenPulse2Q()
769+ with pulse.build(backend):
770+ print(pulse.num_qubits())
771+
772+ .. code-block:: text
773+
774+ 2
775+
762776 .. note:: Requires the active builder context to have a backend set.
763777 """
764778 if isinstance (active_backend (), BackendV2 ):
@@ -803,6 +817,20 @@ def samples_to_seconds(samples: int | np.ndarray) -> float | np.ndarray:
803817def qubit_channels (qubit : int ) -> set [chans .Channel ]:
804818 """Returns the set of channels associated with a qubit.
805819
820+ Examples:
821+
822+ .. code-block:: python
823+
824+ from qiskit import pulse
825+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
826+ backend = FakeOpenPulse2Q()
827+ with pulse.build(backend):
828+ print(pulse.qubit_channels(0))
829+
830+ .. code-block:: text
831+
832+ {MeasureChannel(0), ControlChannel(0), DriveChannel(0), AcquireChannel(0), ControlChannel(1)}
833+
806834 .. note:: Requires the active builder context to have a backend set.
807835
808836 .. note:: A channel may still be associated with another qubit in this list
@@ -1168,6 +1196,33 @@ def frequency_offset(
11681196) -> Generator [None , None , None ]:
11691197 """Shift the frequency of inputs channels on entry into context and undo on exit.
11701198
1199+ Examples:
1200+
1201+ .. code-block:: python
1202+
1203+ from qiskit import pulse
1204+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1205+
1206+ backend = FakeOpenPulse2Q()
1207+ d0 = pulse.DriveChannel(0)
1208+
1209+ with pulse.build(backend) as pulse_prog:
1210+ # shift frequency by 1GHz
1211+ with pulse.frequency_offset(1e9, d0):
1212+ pulse.play(pulse.Constant(10, 1.0), d0)
1213+
1214+ assert len(pulse_prog.instructions) == 3
1215+
1216+ with pulse.build(backend) as pulse_prog:
1217+ # Shift frequency by 1GHz.
1218+ # Undo accumulated phase in the shifted frequency frame
1219+ # when exiting the context.
1220+ with pulse.frequency_offset(1e9, d0, compensate_phase=True):
1221+ pulse.play(pulse.Constant(10, 1.0), d0)
1222+
1223+ assert len(pulse_prog.instructions) == 4
1224+
1225+
11711226 Args:
11721227 frequency: Amount of frequency offset in Hz.
11731228 channels: Channels to offset frequency of.
@@ -1205,6 +1260,18 @@ def frequency_offset(
12051260def drive_channel (qubit : int ) -> chans .DriveChannel :
12061261 """Return ``DriveChannel`` for ``qubit`` on the active builder backend.
12071262
1263+ Examples:
1264+
1265+ .. code-block:: python
1266+
1267+ from qiskit import pulse
1268+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1269+
1270+ backend = FakeOpenPulse2Q()
1271+
1272+ with pulse.build(backend):
1273+ assert pulse.drive_channel(0) == pulse.DriveChannel(0)
1274+
12081275 .. note:: Requires the active builder context to have a backend set.
12091276 """
12101277 # backendV2
@@ -1217,6 +1284,18 @@ def drive_channel(qubit: int) -> chans.DriveChannel:
12171284def measure_channel (qubit : int ) -> chans .MeasureChannel :
12181285 """Return ``MeasureChannel`` for ``qubit`` on the active builder backend.
12191286
1287+ Examples:
1288+
1289+ .. code-block:: python
1290+
1291+ from qiskit import pulse
1292+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1293+
1294+ backend = FakeOpenPulse2Q()
1295+
1296+ with pulse.build(backend):
1297+ assert pulse.measure_channel(0) == pulse.MeasureChannel(0)
1298+
12201299 .. note:: Requires the active builder context to have a backend set.
12211300 """
12221301 # backendV2
@@ -1229,6 +1308,18 @@ def measure_channel(qubit: int) -> chans.MeasureChannel:
12291308def acquire_channel (qubit : int ) -> chans .AcquireChannel :
12301309 """Return ``AcquireChannel`` for ``qubit`` on the active builder backend.
12311310
1311+ Examples:
1312+
1313+ .. code-block:: python
1314+
1315+ from qiskit import pulse
1316+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1317+
1318+ backend = FakeOpenPulse2Q()
1319+
1320+ with pulse.build(backend):
1321+ assert pulse.acquire_channel(0) == pulse.AcquireChannel(0)
1322+
12321323 .. note:: Requires the active builder context to have a backend set.
12331324 """
12341325 # backendV2
@@ -1244,6 +1335,18 @@ def control_channels(*qubits: Iterable[int]) -> list[chans.ControlChannel]:
12441335 Return the secondary drive channel for the given qubit -- typically
12451336 utilized for controlling multi-qubit interactions.
12461337
1338+ Examples:
1339+
1340+ .. code-block:: python
1341+
1342+ from qiskit import pulse
1343+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1344+
1345+ backend = FakeOpenPulse2Q()
1346+
1347+ with pulse.build(backend):
1348+ assert pulse.control_channels(0, 1) == [pulse.ControlChannel(0)]
1349+
12471350 .. note:: Requires the active builder context to have a backend set.
12481351
12491352 Args:
@@ -1736,10 +1839,7 @@ def barrier(*channels_or_qubits: chans.Channel | int, name: str | None = None):
17361839 the barrier. Consider the case where we want to enforce that one pulse
17371840 happens after another on separate channels, this can be done with:
17381841
1739- .. plot::
1740- :include-source:
1741- :nofigs:
1742- :context: reset
1842+ .. code-block:: python
17431843
17441844 from qiskit import pulse
17451845 from qiskit.providers.fake_provider import FakeOpenPulse2Q
@@ -1756,10 +1856,7 @@ def barrier(*channels_or_qubits: chans.Channel | int, name: str | None = None):
17561856
17571857 Of course this could have been accomplished with:
17581858
1759- .. plot::
1760- :include-source:
1761- :nofigs:
1762- :context:
1859+ .. code-block:: python
17631860
17641861 from qiskit.pulse import transforms
17651862
@@ -1821,6 +1918,29 @@ def macro(func: Callable):
18211918 behave as if the function code was embedded inline in the parent builder context
18221919 after parameter substitution.
18231920
1921+ Examples:
1922+
1923+ .. code-block:: python
1924+
1925+ from qiskit import pulse
1926+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
1927+
1928+ @pulse.macro
1929+ def measure(qubit: int):
1930+ pulse.play(pulse.GaussianSquare(16384, 256, 15872), pulse.measure_channel(qubit))
1931+ mem_slot = pulse.MemorySlot(qubit)
1932+ pulse.acquire(16384, pulse.acquire_channel(qubit), mem_slot)
1933+
1934+ return mem_slot
1935+
1936+ backend = FakeOpenPulse2Q()
1937+
1938+ with pulse.build(backend=backend) as sched:
1939+ mem_slot = measure(0)
1940+ print(f"Qubit measured into {mem_slot}")
1941+
1942+ sched.draw()
1943+
18241944 Args:
18251945 func: The Python function to enable as a builder macro. There are no
18261946 requirements on the signature of the function, any calls to pulse
@@ -1942,6 +2062,19 @@ def measure_all() -> list[chans.MemorySlot]:
19422062 same time. This is useful for handling device ``meas_map`` and single
19432063 measurement constraints.
19442064
2065+ Examples:
2066+
2067+ .. code-block:: python
2068+
2069+ from qiskit import pulse
2070+ from qiskit.providers.fake_provider import FakeOpenPulse2Q
2071+
2072+ backend = FakeOpenPulse2Q()
2073+
2074+ with pulse.build(backend) as pulse_prog:
2075+ # Measure all qubits and return associated registers.
2076+ regs = pulse.measure_all()
2077+
19452078 .. note::
19462079 Requires the active builder context to have a backend set.
19472080
@@ -1970,6 +2103,19 @@ def delay_qubits(duration: int, *qubits: int):
19702103 r"""Insert delays on all the :class:`channels.Channel`\s that correspond
19712104 to the input ``qubits`` at the same time.
19722105
2106+ Examples:
2107+
2108+ .. code-block:: python
2109+
2110+ from qiskit import pulse
2111+ from qiskit.providers.fake_provider import FakeOpenPulse3Q
2112+
2113+ backend = FakeOpenPulse3Q()
2114+
2115+ with pulse.build(backend) as pulse_prog:
2116+ # Delay for 100 cycles on qubits 0, 1 and 2.
2117+ regs = pulse.delay_qubits(100, 0, 1, 2)
2118+
19732119 .. note:: Requires the active builder context to have a backend set.
19742120
19752121 Args:
0 commit comments