8000 Minor fixes/improvements to some MCX synthesis methods by alexanderivrii · Pull Request #14093 · Qiskit/qiskit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Minor fixes/improvements to some MCX synthesis methods #14093

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 30 commits into from
Mar 27, 2025

Conversation

alexanderivrii
Copy link
Member

Summary

This fixes some minor efficiencies to the existing MCX synthesis methods: synth_mcx_n_dirty_i15 and synth_mcx_1_clean_b95.

For synth_mcx_n_dirty_i15: in the special case of synthesizing a 3-controlled X-gate, the function used to require 1 additional dirty ancilla qubit, however the actual dedicated synthesis algorithm did not use it. So, on the one hand, the synthesized circuit contained one unused qubit, and, on the other hand, the corresponding synthesis plugin was not applicable even when it could have been.

For synth_mcx_1_clean_b95: the implementation was missing one simple optimization described in the paper. Two of the 4 MCX gates used in the decomposition can be synthesized up to relative phase, with these relative phase contributions canceling each other out. This produces circuits with 16 fewer CX-gates (note that the new synthesis algorithm in #13922 is better still). In addition, for performance, the function creates a quantum circuit with fewer layers of wrappings.

Very technically both of the changes above might be considered breaking changes, however we believe that the chances of actually breaking some code are very very slim and it's not worth to go through the usual deprecation process.

@alexanderivrii alexanderivrii requested a review from a team as a code owner March 25, 2025 15:51
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@alexanderivrii alexanderivrii added this to the 2.1.0 milestone Mar 25, 2025
@coveralls
Copy link
coveralls commented Mar 25, 2025

Pull Request Test Coverage Report for Build 14105001172

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

  • 33 of 33 (100.0%) changed or added relevant lines in 2 files are covered.
  • 103 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.009%) to 88.081%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 94.79%
crates/qasm2/src/expr.rs 1 94.23%
qiskit/circuit/controlledgate.py 1 94.62%
crates/qasm2/src/lex.rs 4 91.73%
qiskit/synthesis/multi_controlled/mcx_synthesis.py 4 98.54%
crates/qasm2/src/parse.rs 6 97.61%
qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py 6 95.8%
qiskit/transpiler/target.py 16 94.22%
crates/accelerate/src/target_transpiler/mod.rs 64 82.03%
Totals Coverage Status
Change from base Build 14062175152: 0.009%
Covered Lines: 72755
Relevant Lines: 82600

💛 - Coveralls

@alexanderivrii alexanderivrii changed the title Minor fixes/improvements to sone MCX synthesis methods Minor fixes/improvements to some MCX synthesis methods Mar 26, 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.

Looks great - thanks!
I have some minor comments on the code comments.

since we have optimized synthesis methods for CCX, C3X and C4X I wonder if we would like to check that all MCX synthesis methods use them when the number of controls is less than 5 (and also do not use any ancillas)

circuit.append(s_gate, [target])

# TODO: improve CX count by using action_only=True (based on #9687)
Copy link
Member

Choose a reason for hiding this comment

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

do you perform some optimization here? or just re-write the code? if not, maybe keep this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this is a valid optimization. Theoretically, it does not follow from Lemma 7 from Iten et al.'s paper, but just to make sure I tried all possible combinations of using action_only or relative_phase here and did not find anything that worked. I removed this comment as I don't see what can be left as "to do".

@ShellyGarion ShellyGarion added this pull request to the merge queue Mar 27, 2025
Merged via the queue into Qiskit:main with commit 0bf91a6 Mar 27, 2025
19 checks passed
@eliarbel eliarbel added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Jun 3, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0