Fix qpy
for multiple controlled parametrized gates
#10758
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theuuid
s 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 duringread
, 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.