Skip to content

[MLIR] Add postselect to assembly format for measure op #1699

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
* Improved the definition of `YieldOp` in the quantum dialect by removing `AnyTypeOf`
[(#1696)](https://github.com/PennyLaneAI/catalyst/pull/1696)

* The assembly format of `MeasureOp` in the `Quantum` dialect and `MeasureInBasisOp` in the `MBQC` dialect now contains the `postselect` attribute.
[(#1732)](https://github.com/PennyLaneAI/catalyst/pull/1732)

* The bufferization of custom catalyst dialects has been migrated to the new one-shot
bufferization interface in mlir.
The new mlir bufferization interface is required by jax 0.4.29 or higher.
Expand All @@ -175,6 +178,7 @@ Sengthai Heng,
David Ittah,
Tzung-Han Juang,
Christina Lee,
Erick Ochoa Lopez,
Mehrdad Malekmohammadi,
Erick Ochoa Lopez,
Ritu Thombre,
Paul Haochen Wang.
2 changes: 1 addition & 1 deletion mlir/include/MBQC/IR/MBQCOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def MeasureInBasisOp : MBQC_Op<"measure_in_basis"> {
);

let assemblyFormat = [{
`[` $plane `,` $angle `]` $in_qubit attr-dict `:` type(results)
`[` $plane `,` $angle `]` $in_qubit (`postselect` $postselect^)? attr-dict `:` type(results)
}];
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/include/Quantum/IR/QuantumOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def MeasureOp : Quantum_Op<"measure"> {
);

let assemblyFormat = [{
$in_qubit attr-dict `:` type(results)
$in_qubit (`postselect` $postselect^)? attr-dict `:` type(results)
}];
}

Expand Down
4 changes: 2 additions & 2 deletions mlir/test/MBQC/ConversionTest.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func.func @testXYPostSelect0(%q1 : !quantum.bit) {
// CHECK: [[plane:%.+]] = llvm.mlir.constant(0 : i32) : i32
// CHECK: [[postselect:%.+]] = llvm.mlir.constant(0 : i32) : i32
// CHECK: llvm.call @__catalyst__mbqc__measure_in_basis(%arg0, [[plane]], [[angle]], [[postselect]])
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 0 : i32} : i1, !quantum.bit
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 0 : i1, !quantum.bit
func.return
}

Expand All @@ -94,6 +94,6 @@ func.func @testXYPostSelect1(%q1 : !quantum.bit) {
// CHECK: [[plane:%.+]] = llvm.mlir.constant(0 : i32) : i32
// CHECK: [[postselect:%.+]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: llvm.call @__catalyst__mbqc__measure_in_basis(%arg0, [[plane]], [[angle]], [[postselect]])
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 1 : i32} : i1, !quantum.bit
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 1 : i1, !quantum.bit
func.return
}
8 changes: 4 additions & 4 deletions mlir/test/MBQC/DialectTest.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func.func @testInvalid(%q1 : !quantum.bit) {

func.func @testPostSelect0(%q1 : !quantum.bit) {
%angle = arith.constant 3.141592653589793 : f64
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 0 : i32} : i1, !quantum.bit
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 0 : i1, !quantum.bit
func.return
}

// -----

func.func @testPostSelect1(%q1 : !quantum.bit) {
%angle = arith.constant 3.141592653589793 : f64
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 1 : i32} : i1, !quantum.bit
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 1 : i1, !quantum.bit
func.return
}

Expand All @@ -76,7 +76,7 @@ func.func @testPostSelect1(%q1 : !quantum.bit) {
func.func @testPostSelectInvalid(%q1 : !quantum.bit) {
%angle = arith.constant 3.141592653589793 : f64
// expected-error@below {{op attribute 'postselect' failed to satisfy constraint}}
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = -1 : i32} : i1, !quantum.bit
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect -1 : i1, !quantum.bit
func.return
}

Expand All @@ -85,6 +85,6 @@ func.func @testPostSelectInvalid(%q1 : !quantum.bit) {
func.func @testPostSelectInvalid(%q1 : !quantum.bit) {
%angle = arith.constant 3.141592653589793 : f64
// expected-error@below {{op attribute 'postselect' failed to satisfy constraint}}
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 2 : i32} : i1, !quantum.bit
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 2 : i1, !quantum.bit
func.return
}
2 changes: 1 addition & 1 deletion mlir/test/Quantum/ConversionTest.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func.func @measure(%q : !quantum.bit) -> !quantum.bit {
// CHECK: [[postselect:%.+]] = llvm.mlir.constant(0 : i32) : i32

// CHECK: llvm.call @__catalyst__qis__Measure(%arg0, [[postselect]])
%res, %new_q = quantum.measure %q {postselect = 0 : i32} : i1, !quantum.bit
%res, %new_q = quantum.measure %q postselect 0 : i1, !quantum.bit

// CHECK: return %arg0
return %new_q : !quantum.bit
Expand Down