Skip to content

Conversation

@ShellyGarion
Copy link
Member

@ShellyGarion ShellyGarion commented Dec 28, 2025

Summary

close #15381

The SubstitutePi4Rotations transpiler pass now handles two types of gates:

  • rotation gates: 1-qubit: RX, RY, RZ, P, U1, and 2-qubit: RZZ, RZX, RXX, RYY,
  • controlled-rotation gates: CP, CRZ, CRY, CRX, CU1.

For the rotation gates, when their angle is a multiple of pi/4, they can be converted into {Clifford, T, Tdg} with a single T/Tdg gate. For even multiples, they can be written using only Clifford gates.

For the controlled-rotation gates, when their angle is a multiple of pi/2, they can be converted into {Clifford, T, Tdg} with 3 T/Tdg gates for CP and 2 T/Tdg gates otherwise. For even multiples, they can be written using only Clifford gates.

This PR also aims to reduce the total number of Clifford gates in the decompositions.

Details and comments

Note that since we should also replace 2-qubit gates (and not only 1-qubit gates), we need to construct a new DAG instead of replacing the nodes inplace.

This can make this pass slower compared to the existing code, by a factor 2x.
E.g. for a 20-qubit circuit with 10000 gates, containing a percenentage p of 1-qubit rotation gates, the total time is:

percentage main branch this PR ratio
0.1 0.03 0.07 2.3
0.25 0.05 0.09 1.8
0.5 0.06 0.11 1.8
0.75 0.07 0.15 2.1
0.9 0.08 0.15 1.8

@ShellyGarion ShellyGarion added this to the 2.3.0 milestone Dec 28, 2025
@ShellyGarion ShellyGarion added Changelog: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler fault tolerance related to fault tolerance compilation labels Dec 28, 2025
@ShellyGarion ShellyGarion modified the milestones: 2.3.0, 2.4.0 Dec 28, 2025
@coveralls
Copy link

coveralls commented Dec 28, 2025

Pull Request Test Coverage Report for Build 20696382817

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

  • 69 of 75 (92.0%) changed or added relevant lines in 1 file are covered.
  • 18 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.004%) to 88.314%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/transpiler/src/passes/substitute_pi4_rotations.rs 69 75 92.0%
Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/optimization/substitute_pi4_rotations.py 1 91.67%
crates/qasm2/src/lex.rs 5 92.29%
crates/qasm2/src/parse.rs 12 96.62%
Totals Coverage Status
Change from base Build 20366546417: 0.004%
Covered Lines: 96757
Relevant Lines: 109560

💛 - Coveralls

@ShellyGarion ShellyGarion changed the title [WIP] Extend SubstitutePi4Rotations to 2q gates Extend SubstitutePi4Rotations to 2q gates Jan 1, 2026
@ShellyGarion ShellyGarion marked this pull request as ready for review January 1, 2026 17:07
@ShellyGarion ShellyGarion requested a review from a team as a code owner January 1, 2026 17:07
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

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

Status: Ready

Development

Successfully merging this pull request may close these issues.

Extend SubstitutePi4Rotations to 2q gates

3 participants