forked from PennyLaneAI/pennylane
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QNode config for mid-circuit measurement options (PennyLaneAI#5679)
**Context:** This PR adds qnode arguments to configure mid-circuit measurement behaviour **Description of the Change:** * Added `postselect_mode` and `mcm_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 with `INTEGER_MIN_VAL` with `mcm_method="one-shot"`. An error will be raised with `defer_measurements` with `postselect_mode="hw-like"`` and jax jit. * `mcm_method` is a string and can be either `"deferred"` or `"one-shot"` * Update `qml.devices.preprocess.mid_circuit_measurements` to accommodate mcm configuration options when deciding which transform to use. * Update `QNode._execution_component` to use the `qml.devices.preprocess.mid_circuit_measurements` transform for old API devices. * Update `ExecutionConfig` to include an `mcm_config` and update `QNode` and `qml.execute` to set this config. * Added new section with details about the kwargs to the measurements intro doc. Note: When using jax-jit, `postselect_mode="hw-like"` will add dummy values to the samples with `dynamic_one_shot` and these won't be used for MPs other than `qml.sample`. However, with `defer_measurements`, an error will be raised. This is a limitation of the current implementation of `defer_measurements`, and I've documented it as such **Benefits:** Users can easily configure how to apply and process mid-circuit measurements. **Possible Drawbacks:** More kwargs to `QNode` and `qml.execute`. **Related GitHub Issues:** --------- Co-authored-by: Christina Lee <[email protected]>
- Loading branch information
Showing
27 changed files
with
763 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.