Skip to content

[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
merged 25 commits into from
May 2, 2025

Conversation

joeycarter
Copy link
Contributor

@joeycarter joeycarter commented Apr 11, 2025

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 as qml.ftqc.measure_arbitrary_basis().

To support these new functions and abstractions, we recently added the mbqc dialect to Catalyst in #1663, which includes the mbqc.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 the mbqc 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 the mbqc.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 before llvm-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]

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]).
@joeycarter joeycarter changed the title [WIP] [FTQC] Add support for parametric mid-circuit measurements [FTQC] Add support for parametric mid-circuit measurements May 1, 2025
@joeycarter joeycarter marked this pull request as ready for review May 1, 2025 21:26
@joeycarter joeycarter requested review from a team May 1, 2025 21:27
Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Copy link

codecov bot commented May 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.71%. Comparing base (e06eba4) to head (72ed935).
Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add tests checking the postselect argument and that inputting invalid
args raises the appropriate exceptions.
@joeycarter joeycarter merged commit 5edce1b into main May 2, 2025
43 checks passed
@joeycarter joeycarter deleted the joeycarter/arb-basis-measurements branch May 2, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants