Skip to content

Conversation

alexanderivrii
Copy link
Member

@alexanderivrii alexanderivrii commented May 22, 2025

Summary

This PR adds a Clifford+T optimization pass (see #14225 (review)). For now all it does is merging pairs of consecutive T-gates into S-gates, and pairs of consecutive Tdg-gates into Sdg-gates.

Despite its simplicity, it's already quite useful on circuits generated by the Solovay-Kitaev algorithm (which we call with ["t", "tdg", "h"] basis set) reducing the overall T-count by approximately 5%-10%.

Longer-term the internals of this pass will be completely rewritten based on better algorithms available.

Details and comments

One can think of this as a placeholder for Clifford+T optimization algorithms that we are planning to implement.

I thought that CommutativeCancellation could merge consecutive Rz and T-rotations (exploiting commutativity), however it does not do that. And I could not find any other Qiskit pass that can do this for us.

ToDo: add this to the optimization stage of the Clifford+T pipeline.

@alexanderivrii alexanderivrii added this to the 2.1.0 milestone May 22, 2025
@alexanderivrii alexanderivrii requested a review from a team as a code owner May 22, 2025 13:57
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented May 22, 2025

Pull Request Test Coverage Report for Build 15293708241

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

  • 31 of 31 (100.0%) changed or added relevant lines in 4 files are covered.
  • 676 unchanged lines in 27 files lost coverage.
  • Overall coverage decreased (-0.5%) to 87.827%

Files with Coverage Reduction New Missed Lines %
crates/circuit/src/symbol_expr.rs 1 75.39%
crates/qasm2/src/expr.rs 1 94.23%
crates/quantum_info/src/convert_2q_block_matrix.rs 1 92.65%
crates/transpiler/src/passes/optimize_1q_gates_decomposition.rs 1 90.8%
crates/transpiler/src/passes/unitary_synthesis.rs 1 94.85%
crates/cext/src/circuit.rs 2 81.16%
qiskit/circuit/library/generalized_gates/gms.py 2 94.44%
crates/quantum_info/src/versor_u2.rs 3 81.85%
qiskit/circuit/library/generalized_gates/diagonal.py 3 95.16%
qiskit/circuit/library/generalized_gates/permutation.py 4 92.73%
Totals Coverage Status
Change from base Build 15188294429: -0.5%
Covered Lines: 79820
Relevant Lines: 90883

💛 - Coveralls

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

This is a small PR and we should definitely think how to extend it in the future. It's specifically useful after the SK decomposition.
One suggestion for he future is to handle Rz gates with proper angles (as well as Rx and Ry).

- |
Added a new :class:`.OptimizeCliffordT` transpiler optimization pass that
merges pairs of consecutive ``T``-gates into ``S``-gates and pairs of
consecutive ``Tdg``-gates into ``Sdg``-gates.
Copy link
Member

Choose a reason for hiding this comment

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

perhaps it's worth to explain that this is useful after SK? and provide some example?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in cb37227

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

LGTM. thanks!

@ShellyGarion ShellyGarion added Changelog: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels May 28, 2025
@ShellyGarion ShellyGarion added this pull request to the merge queue May 28, 2025
Merged via the queue into Qiskit:main with commit 4782b9c May 28, 2025
28 checks passed
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
* CliffordT optimization

* Adding OptimizeCliffordT to the Clifford+T pipeline

* improving release notes based on review comments
@ShellyGarion ShellyGarion added the fault tolerance related to fault tolerance compilation label Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog fault tolerance related to fault tolerance compilation mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants