-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix Target.instruction_supported
when target.num_qubits == None
#13655
Conversation
…um_qubits==None (restore pre-Rust-migration behavior)
One or more of the following people are relevant to this code:
|
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.
LGTM but before I can approve it, I have one question. Would it be easier to just discard the qargs
argument at the beginning the way it was done in Python? You could avoid the mutable reference by just re-defining the variable, for example:
// Handle case where num_qubits is None by always checking globally supported operations
// I don't think it has to be mut, but in case it's needed.
let mut qargs: Option<Qargs> = if self.num_qubits.is_none() {
None
} else {
qargs
};
I do see why this would be less clean but it would avoid having to check the same condition multiple times.
Sure, I was in between the two approaches, and I don't really have a strong preference, so I can totally change it. |
Pull Request Test Coverage Report for Build 12750239425Details
💛 - 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.
LGTM, I wanted to add that this was being done in py_instruction_supported
already, but when I split off these functions to have a rust-native parallel, the condition got lost for the rust-native one.
Summary
This PR fixes a small bug found in
Target.instruction_supported
, wheretarget.num_qubits == None
would causeTarget.instruction_supported
to always evaluate toFalse
. This was handled in the original Python implementation by artificially overwritingqargs
, but this would require a mutable variable in Rust, so I just added an additional condition to account for this case.Details and comments
Bug discovered through #12850.