1717
1818.. currentmodule:: qiskit.qpy
1919
20- QPY is a binary serialization format for :class:`~.QuantumCircuit` and
21- :class:`~.ScheduleBlock` objects that is designed to be cross-platform,
22- Python version agnostic, and backwards compatible moving forward. QPY should
23- be used if you need a mechanism to save or copy between systems a
24- :class:`~.QuantumCircuit` or :class:`~.ScheduleBlock` that preserves the full
25- Qiskit object structure (except for custom attributes defined outside of
26- Qiskit code). This differs from other serialization formats like
20+ QPY is a binary serialization format for :class:`~.QuantumCircuit`
21+ objects that is designed to be cross-platform, Python version agnostic,
22+ and backwards compatible moving forward. QPY should be used if you need
23+ a mechanism to save or copy between systems a :class:`~.QuantumCircuit`
24+ that preserves the full Qiskit object structure (except for custom attributes
25+ defined outside of Qiskit code). This differs from other serialization formats like
2726`OpenQASM <https://github.com/openqasm/openqasm>`__ (2.0 or 3.0) which has a
2827different abstraction model and can result in a loss of information contained
2928in the original circuit (or is unable to represent some aspects of the
@@ -170,6 +169,14 @@ def open(*args):
170169 it to QPY setting ``use_symengine=False``. The resulting file can then be loaded by any later
171170 version of Qiskit.
172171
172+ .. note::
173+
174+ Starting with Qiskit version 2.0.0, which removed the Pulse module from the library, QPY provides
175+ limited support for loading payloads that include pulse data. Loading a ``ScheduleBlock`` payload,
176+ a :class:`.QpyError` exception will be raised. Loading a payload for a circuit that contained pulse
177+ gates, the output circuit will contain custom instructions **without** calibration data attached
178+ for each pulse gate, leaving them undefined.
179+
173180QPY format version history
174181--------------------------
175182
@@ -902,7 +909,7 @@ def open(*args):
902909---------
903910
904911Version 7 adds support for :class:`.~Reference` instruction and serialization of
905- a :class:`.~ ScheduleBlock` program while keeping its reference to subroutines::
912+ a `` ScheduleBlock` ` program while keeping its reference to subroutines::
906913
907914 from qiskit import pulse
908915 from qiskit import qpy
@@ -974,12 +981,12 @@ def open(*args):
974981Version 5
975982---------
976983
977- Version 5 changes from :ref:`qpy_version_4` by adding support for :class:`.~ ScheduleBlock`
984+ Version 5 changes from :ref:`qpy_version_4` by adding support for `` ScheduleBlock` `
978985and changing two payloads the INSTRUCTION metadata payload and the CUSTOM_INSTRUCTION block.
979986These now have new fields to better account for :class:`~.ControlledGate` objects in a circuit.
980987In addition, new payload MAP_ITEM is defined to implement the :ref:`qpy_mapping` block.
981988
982- With the support of :class:`.~ ScheduleBlock`, now :class:`~.QuantumCircuit` can be
989+ With the support of `` ScheduleBlock` `, now :class:`~.QuantumCircuit` can be
983990serialized together with :attr:`~.QuantumCircuit.calibrations`, or
984991`Pulse Gates <https://docs.quantum.ibm.com/guides/pulse>`_.
985992In QPY version 5 and above, :ref:`qpy_circuit_calibrations` payload is
@@ -996,7 +1003,7 @@ def open(*args):
9961003immediately follows the file header block to represent the program type stored in the file.
9971004
9981005- When ``type==c``, :class:`~.QuantumCircuit` payload follows
999- - When ``type==s``, :class:`~. ScheduleBlock` payload follows
1006+ - When ``type==s``, `` ScheduleBlock` ` payload follows
10001007
10011008.. note::
10021009
@@ -1009,12 +1016,10 @@ def open(*args):
10091016SCHEDULE_BLOCK
10101017~~~~~~~~~~~~~~
10111018
1012- :class:`~. ScheduleBlock` is first supported in QPY Version 5. This allows
1019+ `` ScheduleBlock` ` is first supported in QPY Version 5. This allows
10131020users to save pulse programs in the QPY binary format as follows:
10141021
1015- .. plot::
1016- :include-source:
1017- :nofigs:
1022+ .. code-block:: python
10181023
10191024 from qiskit import pulse, qpy
10201025
@@ -1027,13 +1032,6 @@ def open(*args):
10271032 with open('schedule.qpy', 'rb') as fd:
10281033 new_schedule = qpy.load(fd)[0]
10291034
1030- .. plot::
1031- :nofigs:
1032-
1033- # This block is hidden from readers. It's cleanup code.
1034- from pathlib import Path
1035- Path("schedule.qpy").unlink()
1036-
10371035Note that circuit and schedule block are serialized and deserialized through
10381036the same QPY interface. Input data type is implicitly analyzed and
10391037no extra option is required to save the schedule block.
@@ -1043,7 +1041,7 @@ def open(*args):
10431041SCHEDULE_BLOCK_HEADER
10441042~~~~~~~~~~~~~~~~~~~~~
10451043
1046- :class:`~. ScheduleBlock` block starts with the following header:
1044+ `` ScheduleBlock` ` block starts with the following header:
10471045
10481046.. code-block:: c
10491047
@@ -1243,8 +1241,8 @@ def open(*args):
12431241and ``num_params`` length of INSTRUCTION_PARAM payload for parameters
12441242associated to the custom instruction.
12451243The ``type`` indicates the class of pulse program which is either, in principle,
1246- :class:`~. ScheduleBlock` or :class:`~.Schedule`. As of QPY Version 5,
1247- only :class:`~. ScheduleBlock` payload is supported.
1244+ `` ScheduleBlock` ` or :class:`~.Schedule`. As of QPY Version 5,
1245+ only `` ScheduleBlock` ` payload is supported.
12481246Finally, :ref:`qpy_schedule_block` payload is packed for each CALIBRATION_DEF entry.
12491247
12501248.. _qpy_instruction_v5:
0 commit comments