-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Update the code for decomposing MCX and MCPhase gates, so that the number of CX gates won't grow exponentially #11993
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 8497005635Warning: 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
💛 - Coveralls |
This code handles the two cases of
|
After completing this PR, we will be able to write a code to efficiently synthesize any multi-controlled 1-qubit unitary using Euler's decomposition in quadratic number of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ShellyGarion, this leads to a significant reduction in the number of CX-gates when decomposing MCX and MCP gates. This looks good to me, with a minor nitpick about the wording in release notes. I am also wondering if this should be labeled as "new feature" rather than "bug fix".
Another question: it seems that the old method actually produced fewer CX-gates for small values of num_qubits
(e.g., 5 gates instead of 6 with 2 controls). I think it would make sense to use the new method only when it's better.
Fix the decomposition of the gates :class:`.MCXGate` and :class:`.MCPhaseGate`, | ||
so that the number of :class:`.CXGate` will grow quadratically in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's slightly better to say "replace the decomposition" instead of "fix the decomposition" since the previous decomposition was technically correct. Maybe you also want to explicitly mention that this is the decomposition without ancilla qubits.
Thanks @alexanderivrii ! that's a good catch, it's due to this: qiskit/qiskit/circuit/library/standard_gates/x.py Line 1098 in f81e5a8
Since we don't rely on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Shelly for doing the updates. Having qiskit transpiler produce efficient circuits for MCX gates will make many people happy.
Summary
close #11823
see the discussion in #5872
Update the code for decomposing
MCX
andMCPhase
gates, so that the number ofCX
gates won't grow exponentiallyDetails and comments
The current code for synthesizing
MCX
andMCPhase
gates (without ancillas) is based on Gray decomposition and hence the number ofCX
gates grows exponentially in the number of qubitsn
.We already have a code for
MCRZ
synthesis in linear number of CXs (~16*n
) based on https://arxiv.org/abs/2302.06377.In this PR, we add code for
MCPhase
synthesis in quadratic number of CXs (~8*n^2
), and then to extend it toMCX
.Here is a comparison of the
CX
count in the current and new Qiskit code: