Skip to content

Commit 44844b4

Browse files
Add postselect to assembly format for MeasureOP and MeasureInBasisOp #1699 (#1732)
**Context:** **Description of the Change:** add postselect to assembly format to MeasureOp in QuantumOps and MeasureInBasisOp in MBQCOps **Benefits:** easier xDSL generation from table gen **Possible Drawbacks:** None **Related GitHub Issues:** Fixes #1690, #1699
1 parent a3124ab commit 44844b4

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

doc/releases/changelog-dev.md

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
* Improved the definition of `YieldOp` in the quantum dialect by removing `AnyTypeOf`
7676
[(#1696)](https://github.com/PennyLaneAI/catalyst/pull/1696)
7777

78+
* Added ```postselect``` to ```assemblyFormat``` to ```MeasureOp``` in QuantumOp.td and ```MeasureInBasisOp``` in MBQCOps.td
79+
[(#1732)](https://github.com/PennyLaneAI/catalyst/pull/1732)
80+
7881
<h3>Documentation 📝</h3>
7982

8083
<h3>Contributors ✍️</h3>
@@ -86,4 +89,5 @@ Sengthai Heng,
8689
David Ittah,
8790
Christina Lee,
8891
Erick Ochoa Lopez,
92+
Ritu Thombre,
8993
Paul Haochen Wang.

mlir/include/MBQC/IR/MBQCOps.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def MeasureInBasisOp : MBQC_Op<"measure_in_basis"> {
8787
);
8888

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

mlir/test/MBQC/ConversionTest.mlir

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func.func @testXYPostSelect0(%q1 : !quantum.bit) {
7878
// CHECK: [[plane:%.+]] = llvm.mlir.constant(0 : i32) : i32
7979
// CHECK: [[postselect:%.+]] = llvm.mlir.constant(0 : i32) : i32
8080
// CHECK: llvm.call @__catalyst__mbqc__measure_in_basis(%arg0, [[plane]], [[angle]], [[postselect]])
81-
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 0 : i32} : i1, !quantum.bit
81+
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 0 : i1, !quantum.bit
8282
func.return
8383
}
8484

@@ -94,6 +94,6 @@ func.func @testXYPostSelect1(%q1 : !quantum.bit) {
9494
// CHECK: [[plane:%.+]] = llvm.mlir.constant(0 : i32) : i32
9595
// CHECK: [[postselect:%.+]] = llvm.mlir.constant(1 : i32) : i32
9696
// CHECK: llvm.call @__catalyst__mbqc__measure_in_basis(%arg0, [[plane]], [[angle]], [[postselect]])
97-
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 1 : i32} : i1, !quantum.bit
97+
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 1 : i1, !quantum.bit
9898
func.return
9999
}

mlir/test/MBQC/DialectTest.mlir

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ func.func @testInvalid(%q1 : !quantum.bit) {
5050

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

5757
// -----
5858

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

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

@@ -76,6 +76,6 @@ func.func @testPostSelectInvalid(%q1 : !quantum.bit) {
7676
func.func @testPostSelectInvalid(%q1 : !quantum.bit) {
7777
%angle = arith.constant 3.141592653589793 : f64
7878
// expected-error@below {{op attribute 'postselect' failed to satisfy constraint}}
79-
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 {postselect = 2 : i32} : i1, !quantum.bit
79+
%res, %new_q = mbqc.measure_in_basis [XY, %angle] %q1 postselect 2 : i1, !quantum.bit
8080
func.return
8181
}

mlir/test/Quantum/ConversionTest.mlir

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func.func @measure(%q : !quantum.bit) -> !quantum.bit {
440440
// CHECK: [[postselect:%.+]] = llvm.mlir.constant(0 : i32) : i32
441441

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

445445
// CHECK: return %arg0
446446
return %new_q : !quantum.bit

0 commit comments

Comments
 (0)