Fix Barrier broadcast arguments#11113
Merged
Merged
Conversation
Collaborator
|
One or more of the the following people are requested to review this:
|
This commit fixes an issue with the Barrier class's broadcast_arguments() method. Previously the Barrier class was overriding broadcast_arguments(), however this custom implementation resulted in an identical output to the Instruction's implementation (its parent class) but stripped out all the error checking to determine if the arguments aligned with the size of the instruction. This could result in creating a corrupt circuit that had a mismatch between the barrier width and the number of qargs. For example: ``` circuit = QuantumCircuit(1) circuit.append(Barrier(42), [0]) ``` would not error despite trying to add a 42 qubit barrier on qubit 0. This would result in weird errors such as invalid qpy generation that are confusing to debug. This commit fixes this by deleting the broadcast_arguments() implementation for Barrier so it will just depend on the inherited implementation from Instruction which will return an identical result but check the instruction is valid.
d5f4f9d to
3256ec4
Compare
jakelishman
approved these changes
Oct 25, 2023
Member
jakelishman
left a comment
There was a problem hiding this comment.
Seems generally sensible. I remember talking about this over a year ago, but I'm not really sure why argument broadcasting rules should be a property of Instruction instances at all. Removing a special case just seems like a good idea to me.
Pull Request Test Coverage Report for Build 6644833211
💛 - Coveralls |
mergify Bot
pushed a commit
that referenced
this pull request
Oct 25, 2023
This commit fixes an issue with the Barrier class's broadcast_arguments() method. Previously the Barrier class was overriding broadcast_arguments(), however this custom implementation resulted in an identical output to the Instruction's implementation (its parent class) but stripped out all the error checking to determine if the arguments aligned with the size of the instruction. This could result in creating a corrupt circuit that had a mismatch between the barrier width and the number of qargs. For example: ``` circuit = QuantumCircuit(1) circuit.append(Barrier(42), [0]) ``` would not error despite trying to add a 42 qubit barrier on qubit 0. This would result in weird errors such as invalid qpy generation that are confusing to debug. This commit fixes this by deleting the broadcast_arguments() implementation for Barrier so it will just depend on the inherited implementation from Instruction which will return an identical result but check the instruction is valid. (cherry picked from commit 5df2439)
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Oct 26, 2023
This commit fixes an issue with the Barrier class's broadcast_arguments() method. Previously the Barrier class was overriding broadcast_arguments(), however this custom implementation resulted in an identical output to the Instruction's implementation (its parent class) but stripped out all the error checking to determine if the arguments aligned with the size of the instruction. This could result in creating a corrupt circuit that had a mismatch between the barrier width and the number of qargs. For example: ``` circuit = QuantumCircuit(1) circuit.append(Barrier(42), [0]) ``` would not error despite trying to add a 42 qubit barrier on qubit 0. This would result in weird errors such as invalid qpy generation that are confusing to debug. This commit fixes this by deleting the broadcast_arguments() implementation for Barrier so it will just depend on the inherited implementation from Instruction which will return an identical result but check the instruction is valid. (cherry picked from commit 5df2439) Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This commit fixes an issue with the Barrier class's broadcast_arguments() method. Previously the Barrier class was overriding broadcast_arguments(), however this custom implementation resulted in an identical output to the Instruction's implementation (its parent class) but stripped out all the error checking to determine if the arguments aligned with the size of the instruction. This could result in creating a corrupt circuit that had a mismatch between the barrier width and the number of qargs. For example:
would not error despite trying to add a 42 qubit barrier on qubit 0. This would result in weird errors such as invalid qpy generation that are confusing to debug. This commit fixes this by deleting the broadcast_arguments() implementation for Barrier so it will just depend on the inherited implementation from Instruction which will return an identical result but check the instruction is valid.
Details and comments