-
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
Add QNode config for mid-circuit measurement options #5679
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5679 +/- ##
==========================================
- Coverage 99.67% 99.67% -0.01%
==========================================
Files 414 414
Lines 39316 39067 -249
==========================================
- Hits 39188 38939 -249
Misses 128 128 ☔ 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.
Nice job @mudit2812 !
I may still be confused about a few aspects of the config. Most of the documentation is really clear, there were just a few points where I was not sure I understood what the configuration will end up doing.
I left a number of comments, some of which are very subjective and definitely non-blocking!
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 all the explanations and the nice update to behaviour with JITting.
Nice work! 🎉
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.
Very nice upgrade, well done @mudit2812 . I'm just sad I'll have to update #5180 for the n-th time accordingly :p
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.
Nice work, happy to reapprove @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.
Approved from the docs perspective, just leaving one suggestion.
Context:
This PR adds qnode arguments to configure mid-circuit measurement behaviour
Description of the Change:
postselect_mode
andmcm_method
kwargs to qnode.postselect_mode
is a string, and setting it to"fill-shots"
will return all samples regardless of validity. Setting it to"hw-like"
will scale shots with postselection. Note that"hw-like"
with jax will replace invalid samples withINTEGER_MIN_VAL
withmcm_method="one-shot"
. An error will be raised withdefer_measurements
with `postselect_mode="hw-like"`` and jax jit.mcm_method
is a string and can be either"deferred"
or"one-shot"
qml.devices.preprocess.mid_circuit_measurements
to accommodate mcm configuration options when deciding which transform to use.QNode._execution_component
to use theqml.devices.preprocess.mid_circuit_measurements
transform for old API devices.ExecutionConfig
to include anmcm_config
and updateQNode
andqml.execute
to set this config.Note:
When using jax-jit,
postselect_mode="hw-like"
will add dummy values to the samples withdynamic_one_shot
and these won't be used for MPs other thanqml.sample
. However, withdefer_measurements
, an error will be raised. This is a limitation of the current implementation ofdefer_measurements
, and I've documented it as suchBenefits:
Users can easily configure how to apply and process mid-circuit measurements.
Possible Drawbacks:
More kwargs to
QNode
andqml.execute
.Related GitHub Issues: