Skip to content

Port QPY serialization to Rust #13131

Open
@mtreinish

Description

What should we add?

Now that we have most of the circuit model in Rust it should be possible to port the QPY into Rust. We have enough of the data model in Rust now to iterate over the circuit data in rust and generate the payload as we go. There are still places where there will be python interaction, mainly around custom gates and pulse/calibrations. But we can just call out to Python functions as necessary to handle that.

The actual QPY format is packed structs with network endianess and it is pretty natural to express this in rust. The payloads defined in: https://github.com/Qiskit/qiskit/blob/main/qiskit/qpy/formats.py would be expressed as something like:

#[repr(packed)]
struct FileHeader {
    preface: [c_char; 6],
    qpy_version: c_uchar,
    major_version: c_uchar,
    minor_version: c_uchar,
    patch_version: c_uchar,
    num_programs: c_ulonglong
}

in rust.

Although we'll have to use something like the byteorder crate: https://docs.rs/byteorder/latest/byteorder/ to specify the endianess when reading or writing the QPY payload. Although it might be easier to use something like serde to handle the serialization for us and then just work with rust native structs: https://serde.rs/data-format.html

Activity

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

Metadata

Assignees

No one assigned

    Labels

    RustThis PR or issue is related to Rust code in the repositorymod: qpyRelated to QPY serializationtype: feature requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions