-
Notifications
You must be signed in to change notification settings - Fork 2.6k
block diagonal optimized quantum shannon decomposition #13688
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
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 15163180521Warning: 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 |
Glancing quickly, I think this PR is implementing a special case of a question something like "is there a subset of target qubits for which the partial trace commutes with I want to stress how little I've thought this through, so I might just be chatting nonsense. |
@jakelishman - We have tried to extend this suggestion to the case of multi-controlled gates, but it seems that the algorithm of Shende et. al. decomposes the unitary gate using uniformly-controlled Rz or Ry gates, and this structure is not preserved in the induction step. Any concrete suggestions would be helpful. |
Comparing QSD to multi-controlled synthesis for 1-qubit gates (see:
|
Comparing QSD to multi-controlled synthesis for 2-qubit gates (see: test_mc_2qubit_opt):
|
Thanks for providing the table (the second last column should read "opt_a2 = True", correct? |
yes, fixed. thanks! |
if not ( | ||
matrix_equal(Operator(self.definition).to_matrix(), self.to_matrix(), atol=1e-7) | ||
): | ||
self.definition = Isometry(self.matrix, 0, 0).definition |
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.
code updated to use Isometry the calculated Operator is different than the original matrix.
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 not ideal as this adds additional overhead and does not guarantee that we always get the better definition based on QSD. However, this is the best we can do for now and this does significantly improve the gate counts when this does work. Thus I am in favor of merging this in the current form, but we should open an issue to investigate and improve numerical decomposition errors in cossin
.
|
||
cmat_def = qs_decomposition(cmat, opt_a1=True, opt_a2=False) | ||
if not matrix_equal(Operator(cmat_def).to_matrix(), cmat, atol=1e-7): | ||
self.definition = Isometry(cmat, 0, 0).definition |
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.
code updated to use Isometry the calculated Operator is different than the original matrix.
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 know what are the typical numerical errors when running the Isometry
code?
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 there are special numerical errors. QSD is done recursively and this is the reason that we get numeric errors. However, Isometry is not iterative. I can add similar tests to Isometry.
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 doing this, this looks good. I have left just one nitpick about the argument _ctrl_index
. Can you also open an issue to investigate/fix numerical errors in the cossin decomposition?
if not ( | ||
matrix_equal(Operator(self.definition).to_matrix(), self.to_matrix(), atol=1e-7) | ||
): | ||
self.definition = Isometry(self.matrix, 0, 0).definition |
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 not ideal as this adds additional overhead and does not guarantee that we always get the better definition based on QSD. However, this is the best we can do for now and this does significantly improve the gate counts when this does work. Thus I am in favor of merging this in the current form, but we should open an issue to investigate and improve numerical decomposition errors in cossin
.
|
||
cmat_def = qs_decomposition(cmat, opt_a1=True, opt_a2=False) | ||
if not matrix_equal(Operator(cmat_def).to_matrix(), cmat, atol=1e-7): | ||
self.definition = Isometry(cmat, 0, 0).definition |
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 know what are the typical numerical errors when running the Isometry
code?
See: #14422 |
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, LGTM!
* add test of block extration wrt qubit * passing tests. Seems mcx synthesis could be more optimal. * replace isometry by qsd in unitary control method * remove qsd tests from test_synthesis * move qsd synthesis tests * fix random seed. update tolerance in matrices differences * formatting, clean tests * extend tollerance in test * add multi-controlled tests * extend tollerance * extend tollerance * reduce number of controls in tests * update docs * add release notes * formtting * update tollerance * update qsd following review * update release notes following review * update tests following review * change tollerance * improve layout following review * fix svd, Co-authoed by: Alexander Ivrii <alexi@il.ibm.com> * raise atol * update atol * remove assertion * remove assertion * update cos_sin_decomp tolerance * update tollerance * linting * if the Operaotr is not the same as the original matrix, we use Isometery instead of QSD * update atol * move import line * update the tests to allow using Isometry * disable cyclic imports * handle ctrl_index following review --------- Co-authored-by: ShellyGarion <shelly@il.ibm.com>
Summary
This PR attempts to detect when the unitary matrix has a block diagonal representation with respect to one of it's qubits at each step of the recursion in the QSD. If this occurs, one may skip the cosine-sine decomposition and therefore reduce the CX gate count. In addition this may help avoid numerical errors the underlying scipy.linalg.cossin function seems to have for block-diagonal input matrices.
Details and comments