-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
updating tests (Shelly)
more tests and cleanup
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 14105001172Warning: 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 |
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.
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) |
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.
do you perform some optimization here? or just re-write the code? if not, maybe keep this comment.
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.
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".
Summary
This fixes some minor efficiencies to the existing MCX synthesis methods:
synth_mcx_n_dirty_i15
andsynth_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.