Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

qiskit.circuit.qpy_serialization.load

load(file_obj) GitHub(opens in a new tab)

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

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?