Skip to content
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 QPY deserialization of UCRX, UCRY, and UCRZ gates #7933

Merged
merged 4 commits into from
Apr 14, 2022

Conversation

mtreinish
Copy link
Member

Summary

This commit fixes the deserialization of the UCRX, UCRY, and UCRZ gates.
These gates aren't constructed in the standard way as other gate objects
where the parameters are passed directly as args to the class
constructor. Instead they behave the same as Initialize and the params
are passed as a list to the constructor to make a new gate object. This
commit fixes the handling in deserialization to treat these gates the
same as Initialize so that it can be properly deserialized by
qpy.load().

Details and comments

Fixes #7847

This commit fixes the deserialization of the UCRX, UCRY, and UCRZ gates.
These gates aren't constructed in the standard way as other gate objects
where the parameters are passed directly as args to the class
constructor. Instead they behave the same as Initialize and the params
are passed as a list to the constructor to make a new gate object. This
commit fixes the handling in deserialization to treat these gates the
same as Initialize so that it can be properly deserialized by
qpy.load().

Fixes Qiskit#7847
@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Apr 13, 2022
@mtreinish mtreinish requested review from a team and nkanazawa1989 as code owners April 13, 2022 13:43
@qiskit-bot
Copy link
Collaborator

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:

@mtreinish mtreinish added this to the 0.20.1 milestone Apr 13, 2022
issues:
- |
QPY deserialization with the :func:`.qpy.load` function of a directly
instantiated :class:`~.UCPauliRotGate` object in a circuit will fail
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a long term fix for supporting UCPauliRotGate? And do you know if this gate class is used anywhere in Qiskit, if at all?

Copy link
Member Author

@mtreinish mtreinish Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place I've seen it directly used is by UCRX, UCRY, and UCRZ as the parent class. It's basically just a base class for the axis specific versions to de-duplicate the decomposition of the gate. As to how to fix it the only way I can think to is to bump the qpy version to v5 and add a field to the custom instruction type for UCPauliRotGate to store the rotation angle as an extra field in the payload. There is also the hacky equivalent where we modify _write_instruction to add the rotation axis to the parameter list for a UCPauliRotGate and handle that in a custom path on deserialization but that feels like the wrong way to handle this. Ideally we'd refactor all these classes to store the angle list as a single parameter and then for UCPauliRotGate we have a second parameter for the rotation axis, but that's a larger refactor.

Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coveralls
Copy link

coveralls commented Apr 13, 2022

Pull Request Test Coverage Report for Build 2168569415

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 83.946%

Totals Coverage Status
Change from base Build 2168566900: 0.003%
Covered Lines: 54213
Relevant Lines: 64581

💛 - Coveralls

Copy link
Collaborator

@HuangJunye HuangJunye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to completely fixed this issue for sending the circuit to IBM Cloud / IBM Quantum, we also need to update the QPY version on the respective provider as well, don't we? Qiskit/qiskit-ibm-runtime#250 (comment)

@mtreinish
Copy link
Member Author

In order to completely fixed this issue for sending the circuit to IBM Cloud / IBM Quantum, we also need to update the QPY version on the respective provider as well, don't we? Qiskit/qiskit-ibm-runtime#250 (comment)

Generally, yes to fix an issue in submitting the circuit to the qiskit runtime service you'll need to backport this fix to the qiskit-ibm-runtime package's fork of qpy. However, in this case I don't think it is necessary because deserialization is done server side and the error would occur in the qiskit-runtime service's environment itself and the not the client when it tried to load the qpy file. When the runtime environment updates their qiskit version to 0.20.1 with this fix I would expect it to just start working because there is no change in the file format as part of this fix.

@mtreinish
Copy link
Member Author

Sigh, it looks like @nkanazawa1989's approval isn't enough despite being a codeowner for qpy because the tests for qpy don't live in a path that matches qpy/ in the codeowners file. We should move the tests to fix this in the future.

@jakelishman
Copy link
Member

@Mergifyio requeue

@mergify
Copy link
Contributor

mergify bot commented Apr 14, 2022

requeue

☑️ This pull request is already queued

@jakelishman
Copy link
Member

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Apr 14, 2022

refresh

✅ Pull request refreshed

@mergify mergify bot merged commit 2f182f6 into Qiskit:main Apr 14, 2022
mergify bot pushed a commit that referenced this pull request Apr 14, 2022
This commit fixes the deserialization of the UCRX, UCRY, and UCRZ gates.
These gates aren't constructed in the standard way as other gate objects
where the parameters are passed directly as args to the class
constructor. Instead they behave the same as Initialize and the params
are passed as a list to the constructor to make a new gate object. This
commit fixes the handling in deserialization to treat these gates the
same as Initialize so that it can be properly deserialized by
qpy.load().

Fixes #7847

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 2f182f6)
@jakelishman
Copy link
Member

Oh duh, it wasn't re-evaluating because it didn't have the automerge label.

mergify bot added a commit that referenced this pull request Apr 14, 2022
This commit fixes the deserialization of the UCRX, UCRY, and UCRZ gates.
These gates aren't constructed in the standard way as other gate objects
where the parameters are passed directly as args to the class
constructor. Instead they behave the same as Initialize and the params
are passed as a list to the constructor to make a new gate object. This
commit fixes the handling in deserialization to treat these gates the
same as Initialize so that it can be properly deserialized by
qpy.load().

Fixes #7847

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 2f182f6)

Co-authored-by: Matthew Treinish <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QPY can't serialize UCRZGate
6 participants