About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
qiskit.qpy.load
load(file_obj, metadata_deserializer=None)
Load a QPY binary file
This function is used to load a serialized QPY Qiskit program file and create QuantumCircuit
objects or ScheduleBlock
objects from its contents. For example:
from qiskit import qpy
with open('bell.qpy', 'rb') as fd:
circuits = qpy.load(fd)
or with a gzip compressed file:
import gzip
from qiskit import qpy
with gzip.open('bell.qpy.gz', 'rb') as fd:
circuits = qpy.load(fd)
which will read the contents of the qpy and return a list of QuantumCircuit
objects or ScheduleBlock
objects from the file.
Parameters
- file_obj (
BinaryIO
) – A file like object that contains the QPY binary data for a circuit or pulse schedule. - metadata_deserializer (
Optional
[Type
[JSONDecoder
]]) – An optional JSONDecoder class that will be used for thecls
kwarg on the internaljson.load
call used to deserialize the JSON payload used for the.metadata
attribute for any programs in the QPY file. If this is not specified the circuit metadata will be parsed as JSON with the stdlibjson.load()
function using the defaultJSONDecoder
class.
Return type
List
[Union
[QuantumCircuit
, ScheduleBlock
]]
Returns
The list of Qiskit programs contained in the QPY data. A list is always returned, even if there is only 1 program in the QPY data.
Raises
- QiskitError – if
file_obj
is not a valid QPY file - TypeError – When invalid data type is loaded.
Was this page helpful?
Report a bug or request content on GitHub.