Skip to content
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

Ensure bounded values for numpy binomial #5447

Merged
merged 9 commits into from
Apr 3, 2024
Merged

Conversation

mlxd
Copy link
Member

@mlxd mlxd commented Mar 27, 2024

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    test directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context: A user reports errors when running MCM circuits, which fail due to numpy-defined bounds checks in qml.random.binomial which should be 0<= x <=1. This error is due to the input data to binomial being supplied with 1.0000000000000002 from another numpy layer, which triggers this bounds check. This PR rounds towards 1.0 if an associated ValueError is thrown.

Description of the Change: Adds a try-except block to catch and round if the boundary check fails.

Benefits: Ensures continued use of MCM circuits.

Possible Drawbacks: Depending on the occurrence frequency of boundary failures, replacing the try-except block may be better handled by pre-validation against differences between unity and unity+macheps.

Related GitHub Issues:

@mlxd
Copy link
Member Author

mlxd commented Mar 27, 2024

[sc-59583]

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (1a2895d) to head (ff31874).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5447      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         402      402              
  Lines       37541    37252     -289     
==========================================
- Hits        37421    37131     -290     
- Misses        120      121       +1     

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

@mlxd mlxd marked this pull request as ready for review March 27, 2024 20:43
@mlxd mlxd requested a review from a team March 28, 2024 18:33
@Alex-Preciado Alex-Preciado requested review from mudit2812 and removed request for a team April 2, 2024 15:43
@mlxd mlxd enabled auto-merge (squash) April 3, 2024 14:34
Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎸

@mlxd mlxd merged commit 3b0c1b6 into master Apr 3, 2024
40 checks passed
@mlxd mlxd deleted the bugfix/binomial_input_rounding branch April 3, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants