-
Notifications
You must be signed in to change notification settings - Fork 33
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
Calculate complementary polynomial for QSP using flip convolution. #930
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
I'll add in the rest of the tests (I initially forgot to make this PR as a draft - there are a few things I'm planning to add/clean up). I just noticed that while the 4th order polynomials fit with 1e-5 tolerance, the larger order polynomials have a much looser tolerance which is not great. (A 10th order gave me an error in the 1e-3 range). We might need to address this sooner rather than later. |
Update: I was able to get the error below 1e-7 by tweaking some parameters. (I used a different miniization method than was used by the authors of the paper, and I set the gradient to be calculated by a 3 point estimation when the default was 2). The issue that I'm facing now is that the tests that check for all real coefficents are giving a higher error on the unit circle check. The calculation seems to be a bit different depending on if we want only real coefficients. According to the [authors' github] (https://github.com/Danimhn/GQSP-Code/blob/main/FindingQ.ipynb), the flip convolution is performed differently for real and complex polynomials. It appears that the minimizer they used (and I assume also the minimizer I am using) won't work for complex numbers. As a result, they deconstruct the real and imaginary components (which is why two different methods are being used). My understanding is that there can be multiple Q polynomials for any given P (which would mean that for an all-real P, we can have both a complex Q and an all-real Q). Please correct me if this is wrong. Tomorrow, I plan to look into this further and see if I can bring the error down for the real coefficients. If so, then after some minor cleanup, I should be ready to send this out. |
I also found that the test_generalized_real_qsp_with_symbolic_signal_matrix fails with the new qsp method. The test will run 10 random polynomials of each degree. Oddly enough, most of them pass the test (within a tolerance of 1e-5). However, 1 of these polynomials will produce an error in the 1e-1 range. This seems to only happen with 10th degree polynomials. This one does not seem to be a precision issue like the others, but seems to be a bug. However, I can't find anything obvious in the symbolic_qsp_matrix method that could cause the error. The P and Q polynomial pairs pass the unit circle check just before the matrix is made. |
Could you add an issue? You can extract the failing The "symbolic gqsp" checker only computes an upper-bound on the error, which may be larger than the actual error (not sure by how much). Qualtran/qualtran/bloqs/qsp/generalized_qsp_test.py Lines 296 to 297 in abfbfab
|
There are two small followups I will be adding after this PR is submitted:
|
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 good! Mostly docstring+type-hint nits. Also please fix the rng
comment, best practice is to use np.random.Generator
.
As a note: I ran some checks to see if normalizing P before running the tests on fast_complementary_polynomial would give us more accurate results. From my checks, it performs slightly worse than not being normalized. This tells me that the precision problem is not related to normalization. |
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.
@anurudhp @Epsilon1024 Can we merge this and continue improvements in follow-up PRs? Maybe open an issue to track the potential improvements?
Calculate complementary polynomial using Eq. 60 of the paper