-
Notifications
You must be signed in to change notification settings - Fork 603
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
dynamic_one_shot
supports broadcasting; broadcast_expand
supports shot vectors
#5473
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5473 +/- ##
==========================================
- Coverage 99.67% 99.66% -0.01%
==========================================
Files 406 406
Lines 37881 37623 -258
==========================================
- Hits 37758 37498 -260
- Misses 123 125 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small comments/requests, and a question about those wrapped dict
s.
Very nice extension of the recursion logic both in code and tests 💯 💪
And great testing @mudit2812 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate_measurements
needs a small fix, but otherwise looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT, good job @mudit2812 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additional fix of Conditional
@mudit2812 ! 💯
Is there a test that would fail without that fix?
Maybe you could also mention the fix of Conditional
in the changelog? And shouldn't there be some unit tests of Conditional
affected or bind_new_parameters
affected somehow? 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Context:
Native mid-circuit measurements with
default.qubit
are not compatible with parameter broadcasting. Due to the complexity of a "native" implementation, I decided to usebroadcast_expand
, but realized that it does not work with shot vectors.Description of the Change:
This PR does two things:
dynamic_one_shot
transform to usebroadcast_expand
and process batched results correctly.broadcast_expand
to support shot vectors.dynamic_one_shot
anddefer_measurements
because both transforms usebroadcast_expand
for broadcasting, althoughdefer_measurements
only usesbroadcast_expand
with postselection.Note that broadcasting with
qml.sample
and postselection will still not work due to ragged dimensions. If reviewers are okay with it, I would like to merge this and leave that improvement as technical debt. cc @trbromley @isaacdevlugt.Edit about note: Talked offline, decided to raise a more informative error if a user requests postselection with broadcasting when returning samples.
Benefits:
Both transforms are more capable.
Possible Drawbacks:
Because of the stacking and squeezing happening in the post-processing function of
broadcast_expand
, counts dictionaries get wrapped inside 0-D numpy arrays, which makes indexing into the dict impossible. To access the dictionary and its contents, one has to usearray.item()
to extract the single item inside the array.Related GitHub Issues:
#5443