-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable simplifying 1q runs and 2q blocks in transpile() without target (
#9222) * Enable simplifying 1q runs and 2q blocks in transpile() without target This commit fixes an issue when transpile() was called with optimization enabled (optimization levels 1, 2, and 3) and no target (or basis gates) specified then 1q run or 2q block optimization was run. This would result in long series of gates that could be simplified being left in the output circuit. To address this, for 1q optimization the Optimize1qGatesDecomposition pass (which is run at all 3 optimization levels) is updated so that if no target is specified we just try all decomposers as the default heuristic for the best output is the shortest sequence length (in the absense of error rates from the target) and if any output gate is valid that will either remove the 1q sequence if it's an identity sequence, or likely be a single gate. As no basis is specified this behavior is fine since the calculations are quick and any output basis will match the constraints the user provided the transpiler. For optimization level 3 with it's 2q blcok optimization with the UnitarySynthesis pass it is a bit more involved though. The cost of doing the unitary synthesis is higher, the number of possible decompositions is larger, and we don't have a good heuristic measure of which would perform best without a target specified and it's not feasible to just try all supported basis by the synthesis module. This means for a non-identity 2 qubit block the output will be a UnitaryGate (which without a target specified is a valid output). However, to address the case when an identity block is present in the circuit this can be removed with very little overhead. To accomplish this the ConsolidateBlocks pass is updated to check if an identified 2 qubit block is equal the identity matrix and if so will remove that block from the circuit. Fixes #9217 * Fix docs build * Fix handling of 1q decomposer logic with no basis gates This commit fixes an oversight in the previous commit for the 1q decomposer pass when no basis gates are specified. Previously we were setting the basis list to be the set of all the gates in the supported euler basis for the decomposer. This had the unintended side effect of breaking the heuristic for the decomposer as it would treat any 1q gate outside of the supported euler basis as needing to be translated. This was not the desired behavior as any gate is valid. This fixes the logic to just treat no basis explicitly as everything being valid output and weight the heuristic error only. * Remove debug prints * Remove unnecessary conditional 1q identity matrix creation * Split out release notes for 1q and 2q cases Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
944536c
commit fd85047
Showing
8 changed files
with
124 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
24 changes: 24 additions & 0 deletions
24
releasenotes/notes/fix-identity-simplification-no-target-62cd8614044a0fe9.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed an issue with the :func:`~.transpile` function when run with | ||
``optimization_level`` set to ``1``, ``2``, or ``3`` and no | ||
``backend``, ``basis_gates``, or ``target`` argument specified. If | ||
the input circuit had runs of single qubit gates which could be simplified | ||
the output circuit would not be as optimized as possible as those runs | ||
of single qubit gates would not have been removed. This could have been | ||
corrected previously by specifying either the ``backend``, ``basis_gates``, | ||
or ``target`` arguments on the :func:`~.transpile` call, but now the output | ||
will be as simplified as it can be without knowing the target gates allowed. | ||
Fixed `#9217 <https://github.com/Qiskit/qiskit-terra/issues/9217>`__ | ||
- | | ||
Fixed an issue with the :func:`~.transpile` function when run with | ||
``optimization_level=3`` and no ``backend``, ``basis_gates``, or ``target`` | ||
argument specified. If the input circuit contained any 2 qubit blocks which | ||
were equivalent to an identity matrix the output circuit would not be as | ||
optimized as possible and and would still contain that identity block. | ||
This could have been corrected previously by specifying either the | ||
``backend``, ``basis_gates``, or ``target`` arguments on the | ||
:func:`~.transpile` call, but now the output will be as simplified as it | ||
can be without knowing the target gates allowed. | ||
Fixed `#9217 <https://github.com/Qiskit/qiskit-terra/issues/9217>`__ |
This file contains 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
This file contains 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
This file contains 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
This file contains 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