Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add
schmidt_decomposition
function toquantum_info
#10104Add
schmidt_decomposition
function toquantum_info
#10104Changes from 11 commits
121de7f
aa44954
4c63ba2
0bcbe8f
f139fdf
897935d
c633288
017f506
c1102c9
9ba232d
b92f0d2
e4c35f8
e3a8fc2
14bcee6
54b6e6c
a6084c6
29224cc
c613771
000ca7f
ccc364c
7973c99
0e20673
a66ab76
448802a
c2d355d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Could you test to see if you are getting the correct decomposition, not just the return to the original.
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.
Hi @ikkoham. I had already tested that the correct decomposition was being returned, but working on the implementation of these tests made me realize something. As you probably know, the SVD is a unique decomposition but only up to the preservation of the sign parity of the singular vectors. So for example, the state |++⟩ has these two decompositions which are equally valid:
λ|u⟩|v⟩ = 1.0 (1.0 |+⟩) (1.0 |+⟩)
λ|u⟩|v⟩ = 1.0 (-1.0 |+⟩) (-1.0 |+⟩)
The global phase of the reconstructed total state remains the same, but the individual "global" phases of each singular vector can be different as long as they preserve the parity.
The sign selection for the singular vectors depends on the underlying algorithm used for the SVD which, in this case is
numpy.linalg.svd
. This really isn't a big problem, except that for simple cases of separable states (like the ones you can construct from theStatevector.from_label
method), I am always getting singular vectors with the negative sign, so for theself.assertEqual
to work, I am going to have to premultiply some terms by -1 in the test function. Again, there is nothing incorrect about this as long as it is done keeping in mind that the parity must be preserved, my worry is that if someone is going thru the code later on, it might be confusing.What do you think?
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 went ahead and implemented the test as described above, but let me know if you would like to see it implemented in a different way. Thanks!
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. AFAIK, there are no rules or conventions on that point. I'm fine with this implementation. (I'd like to hear other's opinion.)
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.
Hi @ikkoham. I found this very helpful report on the sign ambiguity of the SVD:
https://www.osti.gov/servlets/purl/920802
What they suggest to deal with the sign ambiguity, is:
"...in order to identify the sign of a singular vector, it is suggested that it be similar to the sign of the majority of vectors it is representing."
They propose a function to do this, but the issue is that they only consider real-valued matrices. I am not familiar with how SVD algorithms work, so I don't know if in the case of complex-valued data, the SVD could also return singular vectors with arbitrary phases as long long as the overall sign of the sum term is preserved. If this is the case, the implementation of this function can get complicated.
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.
Instead of checking for equality between individual statevectors perhaps it would be better to just verify that the result does indeed recompose and satisfy all properties as described in your documentation of a Schmidt decomposition.
The question of numerical stability of the decomposition due to the sign issue could be treated in a separate test since it addresses a somewhat distinct issue. I'm not yet familiar with what the best convention might be at the moment so I'd be ok with any convention, which might include unhandled, and clearly documenting the choice.
Also in your current test function it would be better to split it up into several tests along the lines of each commented block you already have.
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.
Hi @ewinston. Thanks for the feedback.