Fix UnitarySynthesis
pass bug when target contains global gates (backport #13651)
#13656
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
While working on #12850 I realized that the
UnitarySynthesis
Rust implementation would sometimes append non-2q-gates to the basis set and panic over the dimension mismatch. I had assumed thattarget.operation_names_for_qargs(Some(&qubits))
would only return gates whose number of qubits matchedlen(qubits)
, but this assumption is incorrect. It will return any gate with some overlap with the provided qargs, independently of the number of qubits of the gate. This bug would come up often when the target contained global gates.I believe that the fix is as simple as making sure the 2q basis contains only 2q gates, at least for the cases I found.
Details and comments
This is an automatic backport of pull request #13651 done by [Mergify](https://mergify.com).