-
Notifications
You must be signed in to change notification settings - Fork 47
[FTQC] Add support for parametric mid-circuit measurements #1645
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
Merged
Conversation
This file contains hidden or 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
Define a few of the system-level tests that are expected to pass once this PR is complete.
Note that the code currently assumes the existence of `MeasureInBasisOp` in the MLIR layer, which will be added in another PR.
Adds mlir_quantum.dialects.mbqc to list of mock modules
The assert was previously that result == 0.0, which is expected for expval(Z) on the null.qubit device, but not guaranteed in future releases.
We follow the convention that `wire` is the last positional argument, therefore the order becomes (angle, wires, plane, [reset, postselect]).
dime10
approved these changes
May 1, 2025
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.
Looks good 👍
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1645 +/- ##
==========================================
+ Coverage 96.69% 96.71% +0.01%
==========================================
Files 81 81
Lines 8963 9005 +42
Branches 856 857 +1
==========================================
+ Hits 8667 8709 +42
Misses 240 240
Partials 56 56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add tests checking the postselect argument and that inputting invalid args raises the appropriate exceptions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
PennyLane now contains an experimental
ftqc
module that defines a number of functions and abstractions for constructing fault-tolerant quantum workloads in the MBQC representation. Among these are the parametric, arbitrary-basis mid-circuit measurement operations, such asqml.ftqc.measure_arbitrary_basis()
.To support these new functions and abstractions, we recently added the
mbqc
dialect to Catalyst in #1663, which includes thembqc.measure_in_basis
operation to represent the arbitrary-basis mid-circuit measurements for MBQC workloads. We now require the appropriate mechanisms to lower the arbitrary-basis MCM primitives defined in PennyLane (added in PennyLaneAI/pennylane#7219) to the operations defined in thembqc
MLIR dialect.Description of the Change:
This PR registers the
measure_in_basis
PLxPR primitive in Catalyst and adds the functions to lower it to thembqc.measure_in_basis
MLIR operation. Recall that the basis state of an arbitrary-basis MCMs is parameterized by a plane (one of XY, YZ or ZX) and a rotation angle about that plane.In order to execute the compiled workloads, we require a new pass pipeline containing the MBQC-to-LLVM dialect-conversion pass. Currently, this pipeline is defined manually in the tests, and consists of the default quantum compilation pipeline with the
convert-mbqc-to-llvm
pass inserted immediately beforellvm-dialect-lowering-pipeline
.This PR also adds frontend lit tests and pytests to verify the generated MLIR and to test the integration of the arbitrary-basis PLxPR primitives, the MLIR operations and the corresponding Runtime C-API call. The system-level pytests execute the compiled workloads on the null.qubit device, and as such do not verify the correctness of the results, only that we can properly integrate all of the components.
Benefits:
Support for arbitrary-basis measurements across the stack, which will allow for compiling and executing full MBQC workloads.
Possible Drawbacks:
We do not currently have the ability to fully simulate compiled MBQC workloads (e.g. on lightning.qubit). Rather, the aim of this PR is to demonstrate that we can push an MBQC workload through the compilation pipeline.
[sc-88876]