-
Notifications
You must be signed in to change notification settings - Fork 714
[Capture] default.qubit can execute circuits transformed by qml.defer_measurements in analytic mode
#6937
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
Conversation
|
After discussion with @lillian542, it seems like the autograph test failures are unrelated to this PR. Removing the |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6937 +/- ##
==========================================
- Coverage 99.60% 99.59% -0.01%
==========================================
Files 481 481
Lines 45947 45974 +27
==========================================
+ Hits 45764 45789 +25
- Misses 183 185 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…#6961) **Context:** This PR is a follow up on #6838 and #6937 to add finite shot execution support to `default.qubit`. **Description of the Change:** * Update `DefaultQubitInterpreter` to handle the ability to update shots based on the specified `postselect_mode`. The currently supported `postselect_mode`s are `"hw-like"` and `"fill-shots"`. * Update `DeferMeasurementsInterpreter` to not use `aux_wires`. This is needed so that we don't need to know ahead of time which wires to use to map MCMs. Instead, now we specify `num_wires`, which should be an integer for the total number of available wires. When executing, this should be known since the device requires wires to be specified. * Because of traceable wires, there might be some sharp bits. Take a look at the following example: ```python qml.capture.enable() import jax @qml.capture.expand_plxpr_transforms @partial(qml.defer_measurements, num_wires=1) def f(n): qml.measure(n) ``` ```pycon >>> jax.make_jaxpr(f)(0) { lambda ; a:i64[]. let _:AbstractOperator() = CNOT[n_wires=2] a 0 in () } ``` The jaxpr is correct, but if I try to execute with `n=0`, we will expectedly fail because we tried to create a `CNOT([0, 0])`. This is expected, but would be nice if it could be caught at capture time rather than runtime. I have updated the `defer_measurements` documentation accordingly. Let me know if there are any other suggestions about how to deal with this. * Update `DefaultQubitInterpreter` to accept `ExecutionConfig`. **Benefits:** **Possible Drawbacks:** Using `hw-like` postselection currently will not be jit friendly when returning `qml.sample`, as the number of samples can be less than the original number of samples non-deterministically. **Future Work:** * Integrate execution with the `mcm_method` and `postselect_mode` arguments of `QNode`. **Related GitHub Issues:** [sc-82064] --------- Co-authored-by: Astral Cai <astral.cai@xanadu.ai> Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai>
…defer_measurements`, add support for `ctrl` and `adjoint` (#1069) **Context:** This PR follows up on PennyLaneAI/pennylane#6838 to add support to execute circuits transformed with `defer_measurements` on `lightning.qubit`. This PR mirrors the same implementation as for `default.qubit`: PennyLaneAI/pennylane#6937 **Description of the Change:** Update `LightningInterpreter` to support `ctrl_transform` and `adjoint_transform` primitives using `CollectOpsandMeas`. **Related Shortcut Story:** [sc-82056] --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
Context:
This PR follows up on #6838 to add support to execute circuits transformed with
defer_measurementsondefault.qubit. Note that this PR does not integrate the transforms and device preprocessing, so the transform needs to be manually applied to the program before sending to the device for execution. That will happen in future work.Description of the Change:
DefaultQubitInterpreterto supportctrl_transformandadjoint_transformprimitives usingCollectOpsandMeas. This causes control flow to get unrolled, but I'm not really sure how else to get them to work.DefaultQubitInterpreter.interpret_operationto renormalize the state after aProjectoris applied.qml.devices.qubit.measure.get_measurement_functionso that forexpvals that don't have anobs, we default to usingstate_diagonalizing_gates. This was needed as terminal MCM measurements get replaced by measurements on eigvals + wires.Benefits:
Possible Drawbacks:
Related GitHub Issues:
[sc-82054]