-
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
Adding permutation synthesis algorithm for LNN #9082
Conversation
Pull Request Test Coverage Report for Build 3490868680
💛 - Coveralls |
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 the following people are requested to review this: |
…vity and has depth guaranteed by the algorithm
Co-authored-by: Nir Gavrielov <[email protected]>
71aee2f
to
7d65299
Compare
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.
LGTM, thanks!
Oh, also I realized I think we're not adding this new function to the doc tree anywhere we probably should add it so we're publishing the documentation for this algorithm. |
@mtreinish, thanks for the comments, it took me quite a number of attempts to get the docstrings working, but now all seems to be good. |
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 for making the updates, in my previous review. Looking through the code again I caught one potential inefficiency which should be easy to fix. Other than that I think this probably good to go.
swap_list = [] | ||
for i, val in enumerate(permutation): | ||
if val != i: | ||
j = permutation.index(i) |
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 would avoid using the index()
call here, it basically is an O(n)
lookup on each iteration making this loop scale quadratically. If you need to get the index of i
from permutation, I would build a map outside the loop that can do this look up in constant time. That way this function is O(2n)
instead of O(n**2)
.
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.
This is a good point. For the record, this function existed before, I have moved it to permutation_utils.py
without any modifications. But I agree that it would be nice to make it more efficient. Hmm, it might be just a tiny bit trickier than what you have suggested, as the permutation (and hence also index()
) changes throughout the loop, but it's clear that a linear algorithm should be possible.
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.
And that was very easy, done in 15f1228.
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.
LGTM, thanks for the quick update.
* Adding permutation synthesis algorithm for LNN * release notes * Checking that the synthesized permutation adheres to the LNN connectivity and has depth guaranteed by the algorithm * Adding tests for 15 qubits Co-authored-by: Nir Gavrielov <[email protected]> * fixing assert * improving description message for _get_ordered_swap * applying suggestions from code review * minor * attempt to fix docstring * Another attempt to fix docsting * another attempt to fix docstring * temporarily simplifying docstring to see if this passes docs build * adding blank line * another attempt * Restoring docstring * removing extra line * speeding up _get_ordered_swap based on review comments Co-authored-by: Nir Gavrielov <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
This commit add the depth-efficient synthesis algorithm for
Permutation
over the linear nearest-neighbor architecture (LNN) following the paper https://arxiv.org/abs/quant-ph/0701194, chapter 6. This is the second task in #9036.Any permutation can be synthesized over LNN using a network of SWAP gates with depth at most
n
and size at mostn(n-1)/2
(where both depth and size are measured with respect to SWAPs), or equivalently with depth at most3n
and size at most3n(n-1)/2
(measured with respect to CNOTs).Additional (minor) changes include improving the documentation of what a "permutation pattern" is, and moving
_get_ordered_swaps
toqiskit/synthesis/permutation/permutation_utils.py
(andtest_get_ordered_swap
totest/python/circuit/library/test_permutation.py
.The next step (that would be handled in a follow-up PR) is to add a high-level synthesis plugin for
Permutation
(this may also require changingPermutation
fromQuantumCircuit
toGate
).Co-authored with https://github.com/NirGavrielov (Nir Gavrielov).