Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run ConsolidateBlocks to build more blocks in init stage
Right now when we're running the consolidate blocks pass during the init stage we were not consolidating all 2q blocks found. This was because the pass was not being called with the target's information and it wasn't aware when the gates in a block were outside of the target. To avoid potentially unecessary work the ConsolidateBlocks pass has some logic to avoid collecting into a block if it doesn't think that the unitary decomposition can decrease the 2q gate count, basically trying to avoid the case where the synthesis output would be more expensive than original circuit gates. However if the gates are outside of the target it can't estimate the synthesis cost and should be consolidating the block. The logic for this exists in the pass, but it only works if you specify the target so it knows that there are gates in the block outside the target. As part of this a bug around handling gates outside basis in the pass was fixed. If gates were encountered that had no matrix defined the pass would previously have errored trying to create a unitary gate for the block in some cases. In general the logic around this pass is lacking in several cases (see issue Qiskit#11659) and it would be better to estimate the error of the block and determine if the estimated error from the output of different synthesis alternatives is better or not. This is easy to do if we do consolidation and synthesis in a single step. But for this situation of running consolidation during init stage and synthesis much later during the translation stage this is hard to accomplish because we lose the context of the original block if we consolidate. That is why we should consider changing the init stage's use of `ConsolidateBlocks` to set `force_consolidate=True` which will create a `UnitaryGate` out of all 2q blocks found regardless of the estimated number of KAK gates needed based on the unitary matrix's coordinates in the weyl chamber. Doing this would fix issues like Qiskit#13344 because we'll synthesisze the unitary in that case. Where it's less clear we want to do this though is cases where the target has different 2q gates than the KAK gate synthesis knows how to work with. Take the example of Qiskit#13344, if the target had global supported gates of `[cp, u, cx]` or something like that and the angle was not zero then forcing consolidation would change a single cp into possibly 3 cx gates. So this commit does not set `force_consolidate=True` and we can discuss the best way to handle that in a separate commit (either on this PR or a new one).
- Loading branch information