56 lines
2.3 KiB
Plaintext
56 lines
2.3 KiB
Plaintext
---
|
||
title: load
|
||
description: API reference for qiskit.qpy.load
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: function
|
||
python_api_name: qiskit.qpy.load
|
||
---
|
||
|
||
<span id="qiskit-qpy-load" />
|
||
|
||
# qiskit.qpy.load
|
||
|
||
<Function id="qiskit.qpy.load" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.24/qiskit/qpy/interface.py" signature="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`](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") objects or [`ScheduleBlock`](qiskit.pulse.ScheduleBlock "qiskit.pulse.schedule.ScheduleBlock") objects from its contents. For example:
|
||
|
||
```python
|
||
from qiskit import qpy
|
||
|
||
with open('bell.qpy', 'rb') as fd:
|
||
circuits = qpy.load(fd)
|
||
```
|
||
|
||
or with a gzip compressed file:
|
||
|
||
```python
|
||
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`](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") objects or [`ScheduleBlock`](qiskit.pulse.ScheduleBlock "qiskit.pulse.schedule.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** (*Type\[JSONDecoder] | None*) – 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 `.metadata` attribute for any programs 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**
|
||
|
||
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.
|
||
|
||
**Return type**
|
||
|
||
*List*\[[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit") | [*ScheduleBlock*](qiskit.pulse.ScheduleBlock "qiskit.pulse.schedule.ScheduleBlock")]
|
||
</Function>
|
||
|