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

fix measurements with dynamic wires #1081

Merged
merged 21 commits into from
Mar 11, 2025
Merged

Conversation

josephleekl
Copy link
Contributor

@josephleekl josephleekl commented Mar 6, 2025

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
    tests 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 .github/CHANGELOG.md file, summarizing the
    change, and including a link back to the PR.

  • Ensure that code is properly formatted by running make format.

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


Context:
Currently when using dynamically determined wire count (e.g. qml.device("lightning.qubit") or qml.device("lightning.qubit", shots = x)), we have an issue when we perform measurements without specifying any observables or wires, i.e.

  • qml.probs()
  • qml.counts()
  • qml.sample()

incorrect result is returned, since the number of wires is not known.

Description of the Change:
For measurements with no wires (i.e. no observables or wires provided), we edit the measurement process to include the number of wires. This is fixed for with and without shots.

Benefits:
Get correct results.

Possible Drawbacks:

Related GitHub Issues:
fixes #1086

[sc-85837]

Copy link

codecov bot commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.08%. Comparing base (b16bfb1) to head (fba516f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1081      +/-   ##
==========================================
+ Coverage   96.00%   99.08%   +3.07%     
==========================================
  Files         232      111     -121     
  Lines       39306    17114   -22192     
==========================================
- Hits        37737    16957   -20780     
+ Misses       1569      157    -1412     

☔ 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.

@josephleekl josephleekl added the ci:use-gpu-runner Enable usage of GPU runner for this Pull Request label Mar 6, 2025
@josephleekl josephleekl marked this pull request as ready for review March 6, 2025 23:35
@josephleekl josephleekl added the ci:use-multi-gpu-runner Enable usage of Multi-GPU runner for this Pull Request label Mar 7, 2025
Copy link
Contributor

@AmintorDusko AmintorDusko left a comment

Choose a reason for hiding this comment

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

Good job! Nice integration with the tests we already have in place.
I'm assuming the coverage is showing false positives as usual. Please triple-check. (quadruplet-check?)

Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

Thanks @josephleekl! Happy to approve 🙌

@josephleekl josephleekl merged commit 3e8cd85 into master Mar 11, 2025
74 checks passed
@josephleekl josephleekl deleted the fix-dynamic-wires-measurements branch March 11, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:use-gpu-runner Enable usage of GPU runner for this Pull Request ci:use-multi-gpu-runner Enable usage of Multi-GPU runner for this Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Automatic qubit management on lightning.qubit gives wrong results for probs()
4 participants