-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of ControlledGates in QPY #8055
Conversation
This commit fixes the handling of ControlledGates in QPY. Previously the extra parameters needed to reconstruct a custom controlled gate were not encoded into the QPY payload. Fixing this required a version bump to the QPY format to modify the payload for a custom instruction entry. Once we added to the format the extra data required for a controlled gate, the number of control qubits, the control state, and the base gate object, the deserializer has enough information to recreate the custom ControlledGate objects. However, fixing this exposed another bug with standard library multicontrolled gates where they often didn't contain sufficient data in the payload to reconstruct either. Fixes Qiskit#7999
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
I'm not sure that we want to backport this or not, it ended up being a bit more involved than I originally thought it would be. |
This commit fixes the qpy test failure. This was caused by the omission of the classical condition on a controlled gate when reconstructing the circuit in deserialization. Fixing this oversight fixes the test failures.
Pull Request Test Coverage Report for Build 2518326855
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Matthew. Your QPY update looks good to me though I don't quite follow the model of ControlledGate
. I have impression that currently developers can too freely define new data model without considering the stability of QPY, and sometime we don't have enough bandwidth to track all changes. This is why I started to finalize the data model of pulse object before adding it.
If circuit model developer will continue to add or modify the data structure, perhaps it would be more sustainable to implement __getstate__
and __setstate__
in all circuit instructions and create QPY binary of it as a free-form dictionary with QPY serialized values?
(EDIT)
Perhaps it doesn't work in terms of backward compatibility of data.
Yeah, it's hard to do that from a backwards compatibility standpoint. I also have concerns about how to implement that reliably/securely for arbitrary gate classes. To a certain extent this wasn't actually something new, the data model for circuits is very fractured in general. There are a lot of weird corner cases and classes that behave differently. There is work on trying to standardize it but it's slow moving. In the meantime though we have to deal with all these edge cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Matthew. Overall this looks great but I have some small questions.
"type", | ||
"num_qubits", | ||
"num_clbits", | ||
"custom_definition", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curiosity, is it possible to express this with custom_definition_size
of zero or non-zero rather than having explicit boolean flag along with size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible, this was mostly an artifact from an earlier version of qpy and really isn't needed. I've just been avoiding changing it because it doesn't hurt and makes another incompatible change.
This commit fixes the failing compat test which was incorrectly trying to test ControlledGates with 0.20.2 generation. We should only run the controlled gate tests starting with 0.21.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mtreinish this looks good to me.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Copy Qiskit/qiskit#8055 Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Copy qpy changes from Qiskit/qiskit#8093 Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * Copy Qiskit/qiskit#8200 Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Copy of Qiskit/qiskit#7300 Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com> * Copy of Qiskit/qiskit#8235 Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Summary
This commit fixes the handling of ControlledGates in QPY. Previously the
extra parameters needed to reconstruct a custom controlled gate were not
encoded into the QPY payload. Fixing this required a version bump to the
QPY format to modify the payload for a custom instruction entry. Once we
added to the format the extra data required for a controlled gate, the
number of control qubits, the control state, and the base gate object,
the deserializer has enough information to recreate the custom
ControlledGate objects. However, fixing this exposed another bug with
standard library multicontrolled gates where they often didn't contain
sufficient data in the payload to reconstruct either.
Details and comments
Fixes #7999
TODO: