Skip to content

Adjust quantum_order_finder result for power-of-two multiples of the actual order #7272

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pavoljuhas
Copy link
Collaborator

Fix test failure where order of 2 for 7 is returned as 6 instead of 3:

pytest --randomly-seed=2114237555 examples/examples_test.py

…actual order

Fix test failure where order of 2 for 7 is returned as 6 instead of 3:

  pytest --randomly-seed=2114237555 examples/examples_test.py
@pavoljuhas pavoljuhas requested review from vtomole and a team as code owners April 14, 2025 20:27
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.66%. Comparing base (1a75d9f) to head (ef421e5).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7272   +/-   ##
=======================================
  Coverage   98.66%   98.66%           
=======================================
  Files        1106     1106           
  Lines       96042    96043    +1     
=======================================
+ Hits        94758    94763    +5     
+ Misses       1284     1280    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pavoljuhas
Copy link
Collaborator Author

Copy link
Collaborator

@viathor viathor left a 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 this is the right way to fix this.

Why do you think the algorithm returns a power-of-2 multiple of the order?

Order of 2 modulo 7 is 3, so the most likely outputs from the quantum phase estimation (QPE) are 0, 1/3 and 2/3. In the first case, we return None since it's impossible to recover the order from the denominator. In the other two cases, it should be straightforward to recover the order exactly (since it's a prime number, so we cannot run into the problem where numerator and denominator have a common factor).

I have two hypotheses for why the order is erroneously determined to be 6. First, sampling from the quantum circuit actually returns an output other than the most likely one. If this is the case, we can suppress it by making the quantum register larger or by sampling twice and returning the minimum (or better yet GCD) of the two outputs. This could be controlled by a new argument, e.g. num_samples to quantum_order_finder which we'd set to 2 in the offending test.

Second, perhaps there is an off-by-one error in bit counting in the code that interprets the output register of the QPE. Here, QPE would be returning 1/3, but classical post-processing would erroneously interpret it as 1/6. I doubt this is what's happening, because in this case we'd probably see other errors.

@github-actions github-actions bot added the Size: XS <10 lines changed label Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants