---
title: QpyModel (latest version)
description: API reference for ibm_quantum_schemas.common.QpyModel in the latest version of qiskit-ibm-runtime
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit-ibm-runtime/ibm-quantum-schemas-common-qpy-model
---

# QpyModel

*pydantic model* `QpyModel`

[GitHub](https://github.com/Qiskit/ibm-quantum-schemas/tree/0.10.20260723/ibm_quantum_schemas/common/qpy.py#L244-L311)

Bases: `BaseModel`

A QPY-encoded quantum circuit.

### circuit\_b64

*field*

Type: `str [Required]`

Base-64 encoded data of the QPY serialization of a single quantum circuit.

**Validated by**

- `cross_validate_qpy_version`

### qpy\_version

*field*

Type: `int [Required]`

The QPY encoding version.

**Constraints**

- **ge** = 10

**Validated by**

- `cross_validate_qpy_version`

### cross\_validate\_qpy\_version

*validator* `cross_validate_qpy_version`

[GitHub](https://github.com/Qiskit/ibm-quantum-schemas/tree/0.10.20260723/ibm_quantum_schemas/common/qpy.py#L255-L268)

Check that the reported version matches the encoded version.

### from\_quantum\_circuit

*classmethod* `from_quantum_circuit(circuit, qpy_version=17)`

[GitHub](https://github.com/Qiskit/ibm-quantum-schemas/tree/0.10.20260723/ibm_quantum_schemas/common/qpy.py#L289-L311)

Create a model instance from a quantum circuit.

The returned instance owns a reference to the provided circuit. This instance may be returned by [`to_quantum_circuit()`](#ibm_quantum_schemas.common.QpyModel.to_quantum_circuit "ibm_quantum_schemas.common.QpyModel.to_quantum_circuit") depending on the value of `use_cached`. Users of this class are responsible for managing cached instances of the circuit and possible side-effects of their mutations.

**Parameters**

- **circuit** ([*QuantumCircuit*](/docs/api/qiskit/qiskit.circuit.QuantumCircuit)) – The circuit to encode into the model.
- **qpy\_version** (*int*) – The QPY version to encode with.

**Returns**

A new model instance.

**Return type**

*Self*

### to\_quantum\_circuit

`to_quantum_circuit(use_cached=False)`

[GitHub](https://github.com/Qiskit/ibm-quantum-schemas/tree/0.10.20260723/ibm_quantum_schemas/common/qpy.py#L270-L287)

Return a decoded quantum circuit instance.

When `use_cached` is false, or when no cached version exists, [`circuit_b64`](#ibm_quantum_schemas.common.QpyModel.circuit_b64 "ibm_quantum_schemas.common.QpyModel.circuit_b64") is decoded and loaded into a new instance. Users of this class are responsible for managing cached instances of the circuit and possible side-effects of their mutations.

**Parameters**

**use\_cached** (*bool*) – Whether to return the cached instance (if it exists).

**Returns**

A quantum circuit.

**Return type**

[*QuantumCircuit*](/docs/api/qiskit/qiskit.circuit.QuantumCircuit)
