Skip to content

Add postselect to assembly format for MeasureOP and MeasureInBasisOp #1699 #1732

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
Show file tree
Hide file tree
Changes from 2 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 @@ -75,6 +75,9 @@
* Improved the definition of `YieldOp` in the quantum dialect by removing `AnyTypeOf`
[(#1696)](https://github.com/PennyLaneAI/catalyst/pull/1696)

* Added ```postselect``` to ```assemblyFormat``` to ```MeasureOp``` in QuantumOp.td and ```MeasureInBasisOp``` in MBQCOps.td
[(#1732)](https://github.com/PennyLaneAI/catalyst/pull/1732)

<h3>Documentation 📝</h3>

<h3>Contributors ✍️</h3>
Expand All @@ -86,4 +89,5 @@ Sengthai Heng,
David Ittah,
Christina Lee,
Erick Ochoa Lopez,
Paul Haochen Wang.
Paul Haochen Wang,
Ritu Thombre
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
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 @@ -50,15 +50,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 @@ -67,7 +67,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 @@ -76,6 +76,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