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

Update counts to handle floats/NaN values from hardware #4739

Merged
merged 5 commits into from
Oct 27, 2023

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Oct 26, 2023

The QuEra hardware sometimes has failed measurements, which return as NaN. Because of this, all samples from the device are returned with type float, and some of them are np.NaN. These were not handled well in counts. On the _default_qubit device, nothing was converted to integers, so it did this:

{'0.00.00.0': 149,
'0.00.01.0': 281, 
'0.00.0nan': 2,
'0.01.00.0': 277,
'0.01.01.0': 4,
'0.0nan0.0': 4,
'1.00.00.0': 268,
'1.00.0nan': 2,
'1.01.00.0': 5,
'nan0.00.0': 8}

We don't like that. Now they are converted into integers if there is no observable, just like in CountsMP.

Also added a line both there and in CountsMP to avoid converting the NaN values to 0 and implying they were ground state measurements - instead, any sample where at least one wire failed is disregarded when totalling the number of counts.

Has been tested with the QuEra hardware, and now returns nicely:

>>> res = circuit(params)
>>> res
{'000': 230, '001': 251, '010': 252, '011': 1, '100': 249, '110': 4}

with 13 disregarded failed measurements:

>>> sum(count for count in res.values())
987

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (v0.33.0-rc0@cf2bd9d). Click here to learn what that means.

Additional details and impacted files
@@              Coverage Diff               @@
##             v0.33.0-rc0    #4739   +/-   ##
==============================================
  Coverage               ?   99.64%           
==============================================
  Files                  ?      380           
  Lines                  ?    33998           
  Branches               ?        0           
==============================================
  Hits                   ?    33876           
  Misses                 ?      122           
  Partials               ?        0           

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

@lillian542 lillian542 changed the base branch from master to v0.33.0-rc0 October 26, 2023 01:35
@lillian542
Copy link
Contributor Author

[sc-48588]

@lillian542 lillian542 changed the title Update counts on _qubit_device to handle floats/NaN values from hardware Update counts to handle floats/NaN values from hardware Oct 26, 2023
@lillian542 lillian542 marked this pull request as ready for review October 26, 2023 19:52
@lillian542 lillian542 added this to the v0.33 milestone Oct 26, 2023
@lillian542 lillian542 requested a review from a team October 27, 2023 15:02
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

changelog?

Thanks for this fix 🎉

pennylane/_qubit_device.py Show resolved Hide resolved
@lillian542 lillian542 enabled auto-merge (squash) October 27, 2023 17:14
@lillian542 lillian542 merged commit 6fe47b5 into v0.33.0-rc0 Oct 27, 2023
32 checks passed
@lillian542 lillian542 deleted the counts-update branch October 27, 2023 17:34
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