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 for multiple controlled parametrized gates #10758

Merged
merged 2 commits into from
Sep 7, 2023

Conversation

ElePT
Copy link
Contributor

@ElePT ElePT commented Sep 1, 2023

Summary

I have recently found out that if a circuit contains multiple instances of parametrized controlled gates of the same class
(not custom, for example, multiple ccrx, ccry....), the parameter values from the first instance were used to build the gate definitions of subsequent instances. This happened because they were all detected as the same custom_operation because of the shared gate class name.

The "fast" way I have found to address the issue has been to modify _write_instruction to account for the uuids of all controlled gates, to make sure they are not lumped into the same definition even if their parameter values are different. This is, however, not ideal because we might (will) be unnecessarily storing identical controlled gate definitions.

Given that the parameter values are actually correctly stored in the controlled gate payload (they are just never used because the definition is already bound to the values of the first gate), I think that an alternative could be to store an "unbound" version of the operation definition during write, and then assign the right parameter values to every instance during read, or keep it as-is and replace the incorrect values with the correct values. However, it looked a bit artificial and couldn't come up with a nice implementation.

Details and comments

Fixes #10735. Let me know if you think I should reconsider the implementation, as you can see, I am not too sure.

@ElePT ElePT requested a review from a team as a code owner September 1, 2023 14:01
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @mtreinish
  • @nkanazawa1989

@1ucian0 1ucian0 added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Sep 5, 2023
@1ucian0 1ucian0 added this to the 0.25.2 milestone Sep 5, 2023
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Sorry for the delay - this looks good to me, thanks. I was worried at first that it would cause us to write out different descriptions of all our standard controlled gate (like cx), but that's not true because it only affects gates that are exact instances of ControlledGate.

@jakelishman jakelishman added this pull request to the merge queue Sep 7, 2023
@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization labels Sep 7, 2023
Merged via the queue into Qiskit:main with commit ebb1197 Sep 7, 2023
14 checks passed
mergify bot pushed a commit that referenced this pull request Sep 7, 2023
* Add exception for controlled gate

* Add reno

(cherry picked from commit ebb1197)
github-merge-queue bot pushed a commit that referenced this pull request Sep 8, 2023
* Add exception for controlled gate

* Add reno

(cherry picked from commit ebb1197)

Co-authored-by: Elena Peña Tapia <[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 mod: qpy Related to QPY serialization 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 fails to serialize certain parametrized instructions
4 participants