Skip to content

QPY dump and load in Rust#15749

Open
gadial wants to merge 5 commits intoQiskit:mainfrom
gadial:full_rust_qpy_flow
Open

QPY dump and load in Rust#15749
gadial wants to merge 5 commits intoQiskit:mainfrom
gadial:full_rust_qpy_flow

Conversation

@gadial
Copy link
Copy Markdown
Contributor

@gadial gadial commented Mar 4, 2026

Summary

This PR adds implementations of the qpy module dump and load functions with Rust, making it possible to have a full QPY flow directly in Rust without Python.

Details and comments

This PR adds a top level QPYFile struct to the rust QPY framework, handling the general file metadata and the the circuits. A new file, interface.rs, handles the actual dump and load functions. We have python wrappers that are called from python's interface.py for supported versions.

Since we still don't have a pure rust QuantumCircuit, the rust functions dump_qpy and load_qpy still have Python remnants in their I/O. In particular, load_qpy returns python circuits (as Py<PyAny>) and dump_qpy accepts the QuantumCircuitData struct which is used as a transition layer from python's QuantumCircuit.

The circuit offset table, present in QPY17, is actually not required at all since all the size data for a given circuit is included in its serialization. Moreover, computing the circuit offset table is not trivial in the binrw framework. So to avoid complicating our data structures with a field that will become obsolete in QPY18, I added another struct, QPY17File. When converting QPYFile to QPY17File the circuits are serialized, the offset table is correctly calculated, and then QPY17File can also be written using the standard binrw macros.

@gadial gadial requested a review from a team as a code owner March 4, 2026 11:59
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @mtreinish

@gadial gadial marked this pull request as draft March 4, 2026 11:59
@gadial gadial marked this pull request as ready for review March 5, 2026 09:42
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @mtreinish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

3 participants