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

Improve support for Torch and Jax with dynamic_one_shot #5672

Merged
merged 115 commits into from
May 24, 2024
Merged

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented May 8, 2024

Context:
Opened in favour of #5630. Bug fix for #5442. This PR updates dynamic_one_shot so that it has better compatibility with the torch and jax interfaces.

Description of the Change:

  • Change casting method from array.astype() to qml.math.cast in the apply_operation dispatch for MidMeasureMP.
  • Update usage of qml.math in dynamic_one_shot.
  • When using qml.counts, cast results to ints before converting to strings for lists of MCM values and floats for single MCM values. This is needed because jax arrays are not hashable, and the hash of torch tensors seems to be independent of the value(s) stored inside it. Thus, neither can be used as keys for dictionaries.

Benefits:
Better interface support with dynamic_one_shot.

Possible Drawbacks:

Related GitHub Issues:

mudit2812 and others added 30 commits March 7, 2024 12:37
@mudit2812
Copy link
Contributor Author

[sc-59938]

@mudit2812 mudit2812 marked this pull request as ready for review May 15, 2024 20:45
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.

@mudit2812 mudit2812 requested a review from vincentmr May 15, 2024 21:11
@mudit2812 mudit2812 linked an issue May 15, 2024 that may be closed by this pull request
1 task
Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

Thanks @mudit2812 . Just a couple suggestions and a kudo ;) I'm ready to approved afterwards.

pennylane/devices/qubit/apply_operation.py Outdated Show resolved Hide resolved
pennylane/transforms/dynamic_one_shot.py Outdated Show resolved Hide resolved
@mudit2812 mudit2812 requested a review from vincentmr May 16, 2024 20:25
Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @mudit2812 .

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Thanks @mudit2812 , this is a neat extension of MCM support! :)

Had three small suggestions, a question for understanding and would like to iterate Vincent's kudo!

doc/releases/changelog-dev.md Show resolved Hide resolved
pennylane/transforms/dynamic_one_shot.py Outdated Show resolved Hide resolved
pennylane/transforms/dynamic_one_shot.py Outdated Show resolved Hide resolved
pennylane/transforms/dynamic_one_shot.py Show resolved Hide resolved
@mudit2812
Copy link
Contributor Author

I will keep iterating with changing the number of shots/seed until the tests pass, but otherwise this should be good to go.

@mudit2812 mudit2812 requested a review from dwierichs May 16, 2024 21:17
Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Thanks @mudit2812 !

@mudit2812 mudit2812 changed the title Improve support for interfaces with dynamic_one_shot Improve support for Torch and Jax with dynamic_one_shot May 17, 2024
@mudit2812 mudit2812 enabled auto-merge (squash) May 24, 2024 22:30
Copy link

codecov bot commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (fbc2a39) to head (7d1915d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5672      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         416      416              
  Lines       39105    38815     -290     
==========================================
- Hits        38981    38690     -291     
- Misses        124      125       +1     

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

@mudit2812 mudit2812 merged commit 59a1e05 into master May 24, 2024
40 checks passed
@mudit2812 mudit2812 deleted the dos-interfaces branch May 24, 2024 22:54
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.

[BUG] Torch interface incompatibility with finite-shot mid-circuit measurements
8 participants