-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Applying a slight perturbation for ill-conditioned matrices #13882
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
Applying a slight perturbation for ill-conditioned matrices #13882
Conversation
One or more of the following people are relevant to this code:
|
… adding bugfix release note
if apply_perturbation: | ||
values = [v - 1e-10 for v in values] |
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.
Possibly we want to do values = values - 1e-10
to use the Numpy vectorised subtraction, and to keep values
as an ndarray
?
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.
Indeed! Done in 59a7b3c.
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 seems fine to me now, thanks for digging in to find it.
I've retagged with the wheel test, just to make sure, but assuming that passes on AArch64, let's merge and move on.
@Mergifyio backport main |
✅ Backports have been created
|
AArch64 passed its tests, so I'll merge. |
* Applying a slight perturbation for ill-conditioned matrices * Further improving the fix based on discussion with Jake and Gadi, and adding bugfix release note * Jake's suggestion from code review (cherry picked from commit 69eb2aa)
Summary
Fix two failing tests for the 1.3.3 release:
test.python.quantum_info.operators.channel.test_kraus.TestKraus.test_circuit_init
+ one other very similar test.The problem only occurs on aarch64 (arm linux), however the relevant matrix is ill-conditioned on my mac as well: the choi matrix has many eigenvalues that are negative and close to 0 (the "negative" is likely due to numerical imprecision errors), with the
numpy.linalg.cond
returningnp.inf
.By doing a search on the internet, one of the recommended techniques is to apply regularization, in this case adding a small perturbation to the matrix. Update: as per @jakelishman's suggestion, we can in fact perfectly recover the eigenvalues of the original matrix from the matrix with the perturbation.