qiskit-documentation/docs/api/qiskit/0.24/qiskit.pulse.Schedule.mdx

404 lines
23 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Schedule
description: API reference for qiskit.pulse.Schedule
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.pulse.Schedule
---
<span id="qiskit-pulse-schedule" />
# qiskit.pulse.Schedule
<Class id="qiskit.pulse.Schedule" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.16/qiskit/pulse/schedule.py" signature="Schedule(*schedules, name=None)" modifiers="class">
A quantum program *schedule* with exact time constraints for its instructions, operating over all input signal *channels* and supporting special syntaxes for building.
Create an empty schedule.
**Parameters**
* **\*schedules** Child Schedules of this parent Schedule. May either be passed as the list of schedules, or a list of `(start_time, schedule)` pairs.
* **name** (`Optional`\[`str`]) Name of this schedule. Defaults to an autogenerated string if not provided.
### \_\_init\_\_
<Function id="qiskit.pulse.Schedule.__init__" signature="__init__(*schedules, name=None)">
Create an empty schedule.
**Parameters**
* **\*schedules** Child Schedules of this parent Schedule. May either be passed as the list of schedules, or a list of `(start_time, schedule)` pairs.
* **name** (`Optional`\[`str`]) Name of this schedule. Defaults to an autogenerated string if not provided.
</Function>
## Methods
| | |
| ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`__init__`](#qiskit.pulse.Schedule.__init__ "qiskit.pulse.Schedule.__init__")(\*schedules\[, name]) | Create an empty schedule. |
| [`append`](#qiskit.pulse.Schedule.append "qiskit.pulse.Schedule.append")(schedule\[, name, inplace]) | Return a new schedule with `schedule` inserted at the maximum time over all channels shared between `self` and `schedule`. |
| [`assign_parameters`](#qiskit.pulse.Schedule.assign_parameters "qiskit.pulse.Schedule.assign_parameters")(value\_dict) | Assign the parameters in this schedule according to the input. |
| [`ch_duration`](#qiskit.pulse.Schedule.ch_duration "qiskit.pulse.Schedule.ch_duration")(\*channels) | Return the time of the end of the last instruction over the supplied channels. |
| [`ch_start_time`](#qiskit.pulse.Schedule.ch_start_time "qiskit.pulse.Schedule.ch_start_time")(\*channels) | Return the time of the start of the first instruction over the supplied channels. |
| [`ch_stop_time`](#qiskit.pulse.Schedule.ch_stop_time "qiskit.pulse.Schedule.ch_stop_time")(\*channels) | Return maximum start time over supplied channels. |
| [`draw`](#qiskit.pulse.Schedule.draw "qiskit.pulse.Schedule.draw")(\[dt, style, filename, interp\_method, …]) | Plot the schedule. |
| [`exclude`](#qiskit.pulse.Schedule.exclude "qiskit.pulse.Schedule.exclude")(\*filter\_funcs\[, channels, …]) | Return a Schedule with only the instructions from this Schedule *failing* at least one of the provided filters. This method is the complement of `self.filter`, so that::. |
| [`filter`](#qiskit.pulse.Schedule.filter "qiskit.pulse.Schedule.filter")(\*filter\_funcs\[, channels, …]) | Return a new `Schedule` with only the instructions from this `Schedule` which pass though the provided filters; i.e. an instruction will be retained iff every function in `filter_funcs` returns `True`, the instruction occurs on a channel type contained in `channels`, the instruction type is contained in `instruction_types`, and the period over which the instruction operates is *fully* contained in one specified in `time_ranges` or `intervals`. |
| [`flatten`](#qiskit.pulse.Schedule.flatten "qiskit.pulse.Schedule.flatten")() | Return a new schedule which is the flattened schedule contained all `instructions`. |
| [`insert`](#qiskit.pulse.Schedule.insert "qiskit.pulse.Schedule.insert")(start\_time, schedule\[, name, inplace]) | Return a new schedule with `schedule` inserted into `self` at `start_time`. |
| [`replace`](#qiskit.pulse.Schedule.replace "qiskit.pulse.Schedule.replace")(old, new\[, inplace]) | Return a schedule with the `old` instruction replaced with a `new` instruction. |
| [`shift`](#qiskit.pulse.Schedule.shift "qiskit.pulse.Schedule.shift")(time\[, name, inplace]) | Return a schedule shifted forward by `time`. |
## Attributes
| | |
| ------------------------------------------------------------------------------------------ | -------------------------------------------- |
| [`channels`](#qiskit.pulse.Schedule.channels "qiskit.pulse.Schedule.channels") | Returns channels that this schedule uses. |
| [`duration`](#qiskit.pulse.Schedule.duration "qiskit.pulse.Schedule.duration") | Duration of this schedule component. |
| `instances_counter` | |
| [`instructions`](#qiskit.pulse.Schedule.instructions "qiskit.pulse.Schedule.instructions") | Get the time-ordered instructions from self. |
| [`name`](#qiskit.pulse.Schedule.name "qiskit.pulse.Schedule.name") | Name of ScheduleComponent. |
| `prefix` | |
| [`start_time`](#qiskit.pulse.Schedule.start_time "qiskit.pulse.Schedule.start_time") | Starting time of this schedule component. |
| [`stop_time`](#qiskit.pulse.Schedule.stop_time "qiskit.pulse.Schedule.stop_time") | Stopping time of this schedule component. |
| [`timeslots`](#qiskit.pulse.Schedule.timeslots "qiskit.pulse.Schedule.timeslots") | Time keeping attribute. |
### append
<Function id="qiskit.pulse.Schedule.append" signature="append(schedule, name=None, inplace=False)">
Return a new schedule with `schedule` inserted at the maximum time over all channels shared between `self` and `schedule`.
$$
t = \textrm{max}(\texttt{x.stop_time} |\texttt{x} \in
\texttt{self.channels} \cap \texttt{schedule.channels})
$$
**Parameters**
* **schedule** (`ScheduleComponent`) Schedule to be appended.
* **name** (`Optional`\[`str`]) Name of the new `Schedule`. Defaults to name of `self`.
* **inplace** (`bool`) Perform operation inplace on this schedule. Otherwise return a new `Schedule`.
**Return type**
`Schedule`
</Function>
### assign\_parameters
<Function id="qiskit.pulse.Schedule.assign_parameters" signature="assign_parameters(value_dict)">
Assign the parameters in this schedule according to the input.
**Parameters**
**value\_dict** (`Dict`\[`ParameterExpression`, `Union`\[`ParameterExpression`, `float`, `int`]]) A mapping from Parameters to either numeric values or another Parameter expression.
**Return type**
`Schedule`
**Returns**
Schedule with updated parameters (a new one if not inplace, otherwise self).
</Function>
### ch\_duration
<Function id="qiskit.pulse.Schedule.ch_duration" signature="ch_duration(*channels)">
Return the time of the end of the last instruction over the supplied channels.
**Parameters**
**\*channels** Channels within `self` to include.
**Return type**
`int`
</Function>
### ch\_start\_time
<Function id="qiskit.pulse.Schedule.ch_start_time" signature="ch_start_time(*channels)">
Return the time of the start of the first instruction over the supplied channels.
**Parameters**
**\*channels** Channels within `self` to include.
**Return type**
`int`
</Function>
### ch\_stop\_time
<Function id="qiskit.pulse.Schedule.ch_stop_time" signature="ch_stop_time(*channels)">
Return maximum start time over supplied channels.
**Parameters**
**\*channels** Channels within `self` to include.
**Return type**
`int`
</Function>
### channels
<Attribute id="qiskit.pulse.Schedule.channels">
Returns channels that this schedule uses.
**Return type**
`Tuple`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel")]
</Attribute>
### draw
<Function id="qiskit.pulse.Schedule.draw" signature="draw(dt=1, style=None, filename=None, interp_method=None, scale=None, channel_scales=None, plot_all=False, plot_range=None, interactive=False, table=False, label=False, framechange=True, channels=None, show_framechange_channels=True)">
Plot the schedule.
**Parameters**
* **dt** (`float`) Time interval of samples.
* **style** (*Optional\[*[*SchedStyle*](qiskit.visualization.pulse.qcstyle#schedstyle "qiskit.visualization.pulse.qcstyle.SchedStyle")*]*) A style sheet to configure plot appearance.
* **filename** (`Optional`\[`str`]) Name required to save pulse image.
* **interp\_method** (`Optional`\[`Callable`]) A function for interpolation.
* **scale** (`Optional`\[`float`]) Relative visual scaling of waveform amplitudes, see Additional Information.
* **channel\_scales** (`Optional`\[`Dict`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel"), `float`]]) Channel independent scaling as a dictionary of `Channel` object.
* **plot\_all** (`bool`) Plot empty channels.
* **plot\_range** (`Optional`\[`Tuple`\[`float`]]) A tuple of time range to plot.
* **interactive** (`bool`) When set true show the circuit in a new window (this depends on the matplotlib backend being used supporting this).
* **table** (`bool`) Draw event table for supported commands.
* **label** (`bool`) Label individual instructions.
* **framechange** (`bool`) Add framechange indicators.
* **channels** (`Optional`\[`List`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel")]]) A list of Channels to plot.
* **show\_framechange\_channels** (`bool`) Plot channels with only framechanges.
**Additional Information:**
If you want to manually rescale the waveform amplitude of channels one by one, you can set `channel_scales` argument instead of `scale`. The `channel_scales` should be given as a python dictionary:
```python
channel_scales = {pulse.DriveChannels(0): 10.0,
pulse.MeasureChannels(0): 5.0}
```
When the channel to plot is not included in the `channel_scales` dictionary, scaling factor of that channel is overwritten by the value of `scale` argument. In default, waveform amplitude is normalized by the maximum amplitude of the channel. The scaling factor is displayed under the channel name alias.
**Returns**
A matplotlib figure object of the pulse schedule.
**Return type**
matplotlib.Figure
</Function>
### duration
<Attribute id="qiskit.pulse.Schedule.duration">
Duration of this schedule component.
**Return type**
`int`
</Attribute>
### exclude
<Function id="qiskit.pulse.Schedule.exclude" signature="exclude(*filter_funcs, channels=None, instruction_types=None, time_ranges=None, intervals=None)">
Return a Schedule with only the instructions from this Schedule *failing* at least one of the provided filters. This method is the complement of `self.filter`, so that:
```python
self.filter(args) | self.exclude(args) == self
```
**Parameters**
* **filter\_funcs** (`List`\[`Callable`]) A list of Callables which take a (int, ScheduleComponent) tuple and return a bool.
* **channels** (`Optional`\[`Iterable`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel")]]) For example, `[DriveChannel(0), AcquireChannel(0)]`.
* **instruction\_types** (*Optional\[Iterable\[Type\[*[*qiskit.pulse.Instruction*](qiskit.pulse.Instruction "qiskit.pulse.Instruction")*]]]*) For example, `[PulseInstruction, AcquireInstruction]`.
* **time\_ranges** (`Optional`\[`Iterable`\[`Tuple`\[`int`, `int`]]]) For example, `[(0, 5), (6, 10)]`.
* **intervals** (`Optional`\[`Iterable`\[`Tuple`\[`int`, `int`]]]) For example, `[(0, 5), (6, 10)]`.
**Return type**
`Schedule`
</Function>
### filter
<Function id="qiskit.pulse.Schedule.filter" signature="filter(*filter_funcs, channels=None, instruction_types=None, time_ranges=None, intervals=None)">
Return a new `Schedule` with only the instructions from this `Schedule` which pass though the provided filters; i.e. an instruction will be retained iff every function in `filter_funcs` returns `True`, the instruction occurs on a channel type contained in `channels`, the instruction type is contained in `instruction_types`, and the period over which the instruction operates is *fully* contained in one specified in `time_ranges` or `intervals`.
If no arguments are provided, `self` is returned.
**Parameters**
* **filter\_funcs** (`List`\[`Callable`]) A list of Callables which take a (int, ScheduleComponent) tuple and return a bool.
* **channels** (`Optional`\[`Iterable`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel")]]) For example, `[DriveChannel(0), AcquireChannel(0)]`.
* **instruction\_types** (*Optional\[Iterable\[Type\[*[*qiskit.pulse.Instruction*](qiskit.pulse.Instruction "qiskit.pulse.Instruction")*]]]*) For example, `[PulseInstruction, AcquireInstruction]`.
* **time\_ranges** (`Optional`\[`Iterable`\[`Tuple`\[`int`, `int`]]]) For example, `[(0, 5), (6, 10)]`.
* **intervals** (`Optional`\[`Iterable`\[`Tuple`\[`int`, `int`]]]) For example, `[(0, 5), (6, 10)]`.
**Return type**
`Schedule`
</Function>
### flatten
<Function id="qiskit.pulse.Schedule.flatten" signature="flatten()">
Return a new schedule which is the flattened schedule contained all `instructions`.
**Return type**
`Schedule`
</Function>
### insert
<Function id="qiskit.pulse.Schedule.insert" signature="insert(start_time, schedule, name=None, inplace=False)">
Return a new schedule with `schedule` inserted into `self` at `start_time`.
**Parameters**
* **start\_time** (`int`) Time to insert the schedule.
* **schedule** (`ScheduleComponent`) Schedule to insert.
* **name** (`Optional`\[`str`]) Name of the new schedule. Defaults to the name of self.
* **inplace** (`bool`) Perform operation inplace on this schedule. Otherwise return a new `Schedule`.
**Return type**
`Schedule`
</Function>
### instructions
<Attribute id="qiskit.pulse.Schedule.instructions">
Get the time-ordered instructions from self.
**ReturnType:**
Tuple\[Tuple\[int, Instruction], …]
</Attribute>
### name
<Attribute id="qiskit.pulse.Schedule.name">
Name of ScheduleComponent.
**Return type**
`str`
</Attribute>
### replace
<Function id="qiskit.pulse.Schedule.replace" signature="replace(old, new, inplace=False)">
Return a schedule with the `old` instruction replaced with a `new` instruction.
The replacment matching is based on an instruction equality check.
```python
from qiskit import pulse
d0 = pulse.DriveChannel(0)
sched = pulse.Schedule()
old = pulse.Play(pulse.Constant(100, 1.0), d0)
new = pulse.Play(pulse.Constant(100, 0.1), d0)
sched += old
sched = sched.replace(old, new)
assert sched == pulse.Schedule(new)
```
Only matches at the top-level of the schedule tree. If you wish to perform this replacement over all instructions in the schedule tree. Flatten the schedule prior to running:
```python
.. jupyter-execute::
```
> sched = pulse.Schedule()
>
> sched += pulse.Schedule(old)
>
> sched = sched.flatten()
>
> sched = sched.replace(old, new)
>
> assert sched == pulse.Schedule(new)
**Parameters**
* **old** (`ScheduleComponent`) Instruction to replace.
* **new** (`ScheduleComponent`) Instruction to replace with.
* **inplace** (`bool`) Replace instruction by mutably modifying this `Schedule`.
**Return type**
`Schedule`
**Returns**
The modified schedule with `old` replaced by `new`.
**Raises**
[**PulseError**](qiskit.pulse.PulseError "qiskit.pulse.PulseError") If the `Schedule` after replacements will has a timing overlap.
</Function>
### shift
<Function id="qiskit.pulse.Schedule.shift" signature="shift(time, name=None, inplace=False)">
Return a schedule shifted forward by `time`.
**Parameters**
* **time** (`int`) Time to shift by.
* **name** (`Optional`\[`str`]) Name of the new schedule. Defaults to the name of self.
* **inplace** (`bool`) Perform operation inplace on this schedule. Otherwise return a new `Schedule`.
**Return type**
`Schedule`
</Function>
### start\_time
<Attribute id="qiskit.pulse.Schedule.start_time">
Starting time of this schedule component.
**Return type**
`int`
</Attribute>
### stop\_time
<Attribute id="qiskit.pulse.Schedule.stop_time">
Stopping time of this schedule component.
**Return type**
`int`
</Attribute>
### timeslots
<Attribute id="qiskit.pulse.Schedule.timeslots">
Time keeping attribute.
**Return type**
`Dict`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel"), `List`\[`Tuple`\[`int`, `int`]]]
</Attribute>
</Class>