Skip to content

Clifford unitary synthesis plugin #14429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2025

Conversation

alexanderivrii
Copy link
Member

@alexanderivrii alexanderivrii commented May 22, 2025

Summary

This PR implements a new unitary synthesis plugin that checks whether a given unitary gate secretly happens to be a Clifford (such as, for example, an Rx-rotation by $\pi/2$). If so, a circuit implementing this unitary and consisting of only Clifford gates is returned. Otherwise, the unitary gate remains unchanged.

The new plugin is also integrated into the translation stage of the Clifford+T pipeline (see #14225): after collecting runs of single-qubit gates into single-qubit unitaries, we now first run the plugin (attempting to find a sequence of Clifford gates that exactly implement this unitary) and only then run the Solovay-Kitaev approximation algorithm.

Details and comments

In particular, this avoids running the Solovay-Kitaev algorithm on "secretly Clifford" gates (which, for example, includes both S and RX($\pi/2$)). This also allows to strengthen the Clifford tests from #14225: each "secretly Clifford" gate should be synthesized to only Clifford basic gates, which BasisTranslator should then translate to the target basis set. (Note that when the target basis set includes both H and S, the rules in our equivalence library enable to do the translation without introducing T-gates).

In principle we already have a somewhat related CollectCliffords pass in Qiskit, which could replace unitary gates by Clifford objects, which we could then synthesize using HighLevelSynthesis. However, this approach has a fundamental problem: replacing unitary gates by Cliffords discards global phase, thus changing the circuit. The current approach avoids this because the plugin returns an actual circuit (consisting of clifford gates) and explicitly takes care of the global phase to make sure the unitary operator does not change.

@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 06:38
@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 15296217263

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

  • 54 of 55 (98.18%) changed or added relevant lines in 3 files are covered.
  • 718 unchanged lines in 25 files lost coverage.
  • Overall coverage decreased (-0.5%) to 87.834%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/synthesis/clifford_unitary_synth_plugin.py 52 53 98.11%
Files with Coverage Reduction New Missed Lines %
crates/transpiler/src/passes/optimize_1q_gates_decomposition.rs 1 90.8%
crates/cext/src/circuit.rs 2 81.16%
qiskit/circuit/library/generalized_gates/gms.py 2 94.44%
qiskit/circuit/library/generalized_gates/diagonal.py 3 95.16%
qiskit/circuit/library/generalized_gates/permutation.py 4 92.73%
crates/circuit/src/symbol_expr.rs 5 75.02%
qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py 5 92.47%
crates/circuit/src/lib.rs 6 94.96%
crates/qasm2/src/lex.rs 6 91.98%
crates/qasm2/src/parse.rs 6 96.68%
Totals Coverage Status
Change from base Build 15171633158: -0.5%
Covered Lines: 79847
Relevant Lines: 90907

💛 - 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.

I think it's a nice PR. I had a few comments about unifying tests, but other than that it looks good.

@alexanderivrii
Copy link
Member Author

Thanks Shelly, I have improved the tests based on your suggestions: indeed, there was too much code duplication previously.

@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
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 this pull request to the merge queue May 28, 2025
Merged via the queue into Qiskit:main with commit 4f1bb75 May 28, 2025
28 checks passed
@github-project-automation github-project-automation bot moved this from To do to done in Transpiler May 28, 2025
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
* adding unitary synthesis clifford plugin

* updating Clifford+T transpiler pipeline and improving tests

* typo

* pass over tests as suggested by review notes

* another typo
@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
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants