Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.

qiskit.qpy.load

load(file_obj, metadata_deserializer=None)

GitHub

Load a QPY binary file

This function is used to load a serialized QPY circuit file and create QuantumCircuit objects from its contents. For example:

from qiskit.circuit import qpy_serialization
 
with open('bell.qpy', 'rb') as fd:
    circuits = qpy_serialization.load(fd)

or with a gzip compressed file:

import gzip
from qiskit.circuit import qpy_serialization
 
with gzip.open('bell.qpy.gz', 'rb') as fd:
    circuits = qpy_serialization.load(fd)

which will read the contents of the qpy and return a list of QuantumCircuit objects from the file.

Parameters

  • file_obj (File) – A file like object that contains the QPY binary data for a circuit
  • metadata_deserializer (JSONDecoder) – An optional JSONDecoder class that will be used for the cls kwarg on the internal json.load call used to deserialize the JSON payload used for the QuantumCircuit.metadata attribute for any circuits in the QPY file. If this is not specified the circuit metadata will be parsed as JSON with the stdlib json.load() function using the default JSONDecoder class.

Returns

List of QuantumCircuit

The list of QuantumCircuit objects contained in the QPY data. A list is always returned, even if there is only 1 circuit in the QPY data.

Return type

list

Raises

QiskitError – if file_obj is not a valid QPY file

Was this page helpful?
Report a bug or request content on GitHub.