Rust implementation of the QPY module#14166
Conversation
|
One or more of the following people are relevant to this code:
|
…g for QuantumCircuit parameters)
|
Hi @gadial, this is still in draft mode so I just gave it a brief look. I have a few general questions and comments at this stage:
|
|
Thanks @eliarbel
|
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks Gadi! I I am in favor of merging this PR as is, but I'll defer to Eli to take another look to make sure that all of this comments are addressed.
| .getattr(intern!(py, "__class__"))? | ||
| .getattr(intern!(py, "__name__"))? | ||
| .extract::<String>(), | ||
| OperationRef::PauliProductMeasurement(_) => imports::PAULI_PRODUCT_MEASUREMENT |
There was a problem hiding this comment.
I thought you wanted to change this to avoid going through python.
…tion to avoid treating the main circuit data as mutable during writing
eliarbel
left a comment
There was a problem hiding this comment.
Thanks for all the hard and amazing work Gadi!
I'm happy the get this merged into main so I will go ahead and approve.
@alexanderivrii any more comments?
alexanderivrii
left a comment
There was a problem hiding this comment.
No more immediate comments on my part.
Summary
Adds a rust-based implementation of qpy serialization.
Addresses #13131
Details and comments
We use rust structs along with the
binrwlibrary to specify and write the byte representation of data (this turns out to be somewhat simpler than how it's currently done in python). There are still many python-dependent elements we need to take into consideration:write_circuitandread_circuit(this is being kept until a later PR adds backward compatability)save.In this PR we make the distinction between
packingan object andserializingit:serializingan object means generating a bytes representation for it (aVec<u8>object, aliased toBytesin the module.packingan object means extracting its data fields and generating a corresponding rust struct, taken from theformats.rsfiles. This might involve serializing some of the object's fields, and packing other fields.Our goal is to minimize serialization as much as possible, allowing us to generate a large packed struct reflecting the structure of the qpy file as much as possible before serializing; the code can be further improved to reflect this, although I think this can wait to a future PR.
The main obstacle to minimizing serialization is the relatively ad-hoc manner in which the Python QPY code is written; data is treated as a sequence of bytes until the very last minute, when it is deserialized based on the logic of the current situation. In most cases this translates smoothly to our Rust framework, but not always.
Future Work
Benchmarking results
Taking the ASV benchmarks for qasm3 and using them with qpy (both for dumping and for dumping + loading flow) yields on my local machine