Skip to content

Conversation

mtreinish
Copy link
Member

Summary

A bug was introduced into the ConsolidateBlocks pass in #13884 around how the KAK gate name was passed to rust from the Python pass. The consolidate blocks internal logic around whether to consolidate a pass or not is based on the estimate from the selected decomposer of whether the estimated number of gates used to synthesis the unitary would exceed the number of basis gates in the block. To do this the pass counts the gate with the synthesis target name in the block. However, in the case of the decomposer being the TwoQubitBasisDecomposer the name being used for this look wasn't the name of the gate, but instead was an internal sentinel value string "USER_GATE" which is used to handle arbitrary user gate definitions in the decomposer. This led to the consolidate blocks pass missing opportunities for consolidation. This commit fixes the oversight so that the name we use for making this determination is the actual basis gate name and the pass functions correctly.

Details and comments

Fixes #14413

A bug was introduced into the ConsolidateBlocks pass in Qiskit#13884 around
how the KAK gate name was passed to rust from the Python pass. The
consolidate blocks internal logic around whether to consolidate a pass
or not is based on the estimate from the selected decomposer of whether
the estimated number of gates used to synthesis the unitary would exceed
the number of basis gates in the block. To do this the pass counts the
gate with the synthesis target name in the block. However, in the case
of the decomposer being the TwoQubitBasisDecomposer the name being
used for this look wasn't the name of the gate, but instead was an
internal sentinel value string "USER_GATE" which is used to handle
arbitrary user gate definitions in the decomposer. This led to the
consolidate blocks pass missing opportunities for consolidation. This
commit fixes the oversight so that the name we use for making this
determination is the actual basis gate name and the pass functions
correctly.

Fixes Qiskit#14413
@mtreinish mtreinish added this to the 2.0.2 milestone May 21, 2025
@mtreinish mtreinish requested a review from a team as a code owner May 21, 2025 12:19
@mtreinish mtreinish added priority: high Changelog: Bugfix Include in the "Fixed" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels May 21, 2025
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@mtreinish mtreinish added the stable backport potential The bug might be minimal and/or import enough to be port to stable label May 21, 2025
@ShellyGarion ShellyGarion self-assigned this May 21, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 15161976007

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 5 (80.0%) changed or added relevant lines in 1 file are covered.
  • 14 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.004%) to 88.313%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/optimization/consolidate_blocks.py 4 5 80.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.23%
crates/transpiler/src/passes/unitary_synthesis.rs 1 94.85%
crates/qasm2/src/lex.rs 3 92.73%
crates/circuit/src/symbol_expr.rs 9 75.26%
Totals Coverage Status
Change from base Build 15148086093: -0.004%
Covered Lines: 78361
Relevant Lines: 88731

💛 - Coveralls

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks straightforward and the tests cover all the possible cases I can think of. LGTM. I will not queue the PR in case Shelly has any further comment.

@mtreinish mtreinish enabled auto-merge May 21, 2025 13:37
@mtreinish mtreinish added this pull request to the merge queue May 21, 2025
Merged via the queue into Qiskit:main with commit 4e9231d May 21, 2025
26 checks passed
mergify bot pushed a commit that referenced this pull request May 21, 2025
A bug was introduced into the ConsolidateBlocks pass in #13884 around
how the KAK gate name was passed to rust from the Python pass. The
consolidate blocks internal logic around whether to consolidate a pass
or not is based on the estimate from the selected decomposer of whether
the estimated number of gates used to synthesis the unitary would exceed
the number of basis gates in the block. To do this the pass counts the
gate with the synthesis target name in the block. However, in the case
of the decomposer being the TwoQubitBasisDecomposer the name being
used for this look wasn't the name of the gate, but instead was an
internal sentinel value string "USER_GATE" which is used to handle
arbitrary user gate definitions in the decomposer. This led to the
consolidate blocks pass missing opportunities for consolidation. This
commit fixes the oversight so that the name we use for making this
determination is the actual basis gate name and the pass functions
correctly.

Fixes #14413

(cherry picked from commit 4e9231d)
github-merge-queue bot pushed a commit that referenced this pull request May 21, 2025
…14424)

A bug was introduced into the ConsolidateBlocks pass in #13884 around
how the KAK gate name was passed to rust from the Python pass. The
consolidate blocks internal logic around whether to consolidate a pass
or not is based on the estimate from the selected decomposer of whether
the estimated number of gates used to synthesis the unitary would exceed
the number of basis gates in the block. To do this the pass counts the
gate with the synthesis target name in the block. However, in the case
of the decomposer being the TwoQubitBasisDecomposer the name being
used for this look wasn't the name of the gate, but instead was an
internal sentinel value string "USER_GATE" which is used to handle
arbitrary user gate definitions in the decomposer. This led to the
consolidate blocks pass missing opportunities for consolidation. This
commit fixes the oversight so that the name we use for making this
determination is the actual basis gate name and the pass functions
correctly.

Fixes #14413

(cherry picked from commit 4e9231d)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@mtreinish mtreinish deleted the fix-consolidate branch May 22, 2025 21:27
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
A bug was introduced into the ConsolidateBlocks pass in Qiskit#13884 around
how the KAK gate name was passed to rust from the Python pass. The
consolidate blocks internal logic around whether to consolidate a pass
or not is based on the estimate from the selected decomposer of whether
the estimated number of gates used to synthesis the unitary would exceed
the number of basis gates in the block. To do this the pass counts the
gate with the synthesis target name in the block. However, in the case
of the decomposer being the TwoQubitBasisDecomposer the name being
used for this look wasn't the name of the gate, but instead was an
internal sentinel value string "USER_GATE" which is used to handle
arbitrary user gate definitions in the decomposer. This led to the
consolidate blocks pass missing opportunities for consolidation. This
commit fixes the oversight so that the name we use for making this
determination is the actual basis gate name and the pass functions
correctly.

Fixes Qiskit#14413
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: transpiler Issues and PRs related to Transpiler priority: high stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transpilation result of RZZ gate by Qiskit 2.0 is less optimal compared with Qiskit 1.4
5 participants