Skip to content
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

Better MCX Decomposition with logarithmic Toffoli Depth #13922

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

patelvyom
Copy link

Summary

Implement four new multi-controlled-x synthesis functions: synth_mcx_1_clean_kg24, synth_mcx_1_dirty_kg24, synth_mcx_2_clean_kg24, synth_mcx_2_dirty_kg24 as discussed in #13913.

Details and comments

Once implementations are confirmed, these should be added to the HLS transpiler synthesis plugin.

@patelvyom patelvyom requested a review from a team as a code owner February 25, 2025 06:05
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Feb 25, 2025
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

@CLAassistant
Copy link

CLAassistant commented Feb 25, 2025

CLA assistant check
All committers have signed the CLA.

@ShellyGarion
Copy link
Member

@patelvyom - thank you very much for your contribution to qiskit. You've made a great start!
Could you please follow the contribution guidelines? https://github.com/Qiskit/qiskit/blob/main/CONTRIBUTING.md
In particular, the style and lint: https://github.com/Qiskit/qiskit/blob/main/CONTRIBUTING.md#style-and-lint
and adding tests: https://github.com/Qiskit/qiskit/blob/main/CONTRIBUTING.md#testing

@coveralls
Copy link

coveralls commented Feb 25, 2025

Pull Request Test Coverage Report for Build 13569874316

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

  • 100 of 101 (99.01%) changed or added relevant lines in 2 files are covered.
  • 477 unchanged lines in 27 files lost coverage.
  • Overall coverage decreased (-0.1%) to 87.876%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/synthesis/multi_controlled/mcx_synthesis.py 97 98 98.98%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 94.39%
crates/qasm2/src/expr.rs 1 94.23%
qiskit/pulse/builder.py 1 85.31%
qiskit/pulse/instructions/reference.py 1 90.32%
qiskit/user_config.py 1 86.87%
qiskit/circuit/library/arithmetic/integer_comparator.py 4 94.67%
crates/qasm2/src/lex.rs 5 91.98%
qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py 5 92.09%
qiskit/qpy/binary_io/value.py 5 86.26%
qiskit/circuit/library/arithmetic/linear_pauli_rotations.py 6 89.04%
Totals Coverage Status
Change from base Build 13512719904: -0.1%
Covered Lines: 77631
Relevant Lines: 88342

💛 - Coveralls

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Getting the style/norm of a project is a bit of work, so in addition to Shelly's provided links here are some more detailed infos (I didn't have a look at the logic itself yet 🙂).

@patelvyom
Copy link
Author

@ShellyGarion Existing MCX decompositions have test cases defined in test/python/transpiler/test_high_level_synthesis.py. Should I also add test cases in test_high_level_synthesis.py? That would require me to add new entries in the HLS plugin.

Also, I believe all style and linter-related errors have been fixed.

@ShellyGarion
Copy link
Member

ShellyGarion commented Feb 26, 2025

@ShellyGarion Existing MCX decompositions have test cases defined in test/python/transpiler/test_high_level_synthesis.py. Should I also add test cases in test_high_level_synthesis.py? That would require me to add new entries in the HLS plugin.

Also, I believe all style and linter-related errors have been fixed.

Could you please add a new test file of the synthesis methods called test_mcx_synthesis.py to the qiskit synthesis tests here?
Please check that the gate is synthesized correctly, and that you get the expected bound on the number of CX gates and/or depth.

Unfortunately, it seems that our mcx synthesis tests are somewhat hidden inside the circuit library tests (which we should refactor in the future). See for example these tests:

def test_mcxvchain_dirty_ancilla_cx_count(self, num_ctrl_qubits):

def test_mcxvchain_clean_ancilla_cx_count(self, num_ctrl_qubits):

def test_mcxrecursive_clean_ancilla_cx_count(self, num_ctrl_qubits):

def test_mcx_gates(self, num_ctrl_qubits):

@patelvyom
Copy link
Author

I've added the required tests. I couldn't add tests for checking depth for the 2 ancilla cases because the constant factors in O(log(n)) fluctuate a lot across num_ctrl_qubits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants