Skip to content

Commit e67219c

Browse files
committed
Update documentation
1 parent aa76e32 commit e67219c

5 files changed

Lines changed: 69 additions & 57 deletions

File tree

mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
406406
* builder.c##OP_NAME(q0, q1); \
407407
* ``` \
408408
* ```mlir \
409-
* qc.ctrl(%q0) { \
410-
* qc.OP_NAME %q1 : !qc.qubit \
409+
* qc.ctrl(%q0) targets(%a0 = %q1) { \
410+
* qc.OP_NAME %a0 : !qc.qubit \
411411
* } : !qc.qubit \
412412
* ``` \
413413
*/ \
@@ -424,8 +424,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
424424
* builder.mc##OP_NAME({q0, q1}, q2); \
425425
* ``` \
426426
* ```mlir \
427-
* qc.ctrl(%q0, %q1) { \
428-
* qc.OP_NAME %q2 : !qc.qubit \
427+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2) { \
428+
* qc.OP_NAME %a0 : !qc.qubit \
429429
* } : !qc.qubit, !qc.qubit \
430430
* ``` \
431431
*/ \
@@ -478,8 +478,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
478478
* builder.c##OP_NAME(PARAM, q0, q1); \
479479
* ``` \
480480
* ```mlir \
481-
* qc.ctrl(%q0) { \
482-
* qc.OP_NAME(%PARAM) %q1 : !qc.qubit \
481+
* qc.ctrl(%q0) targets(%a0 = %q1) { \
482+
* qc.OP_NAME(%PARAM) %a0 : !qc.qubit \
483483
* } : !qc.qubit \
484484
* ``` \
485485
*/ \
@@ -498,8 +498,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
498498
* builder.mc##OP_NAME(PARAM, {q0, q1}, q2); \
499499
* ``` \
500500
* ```mlir \
501-
* qc.ctrl(%q0, %q1) { \
502-
* qc.OP_NAME(%PARAM) %q2 : !qc.qubit \
501+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2) { \
502+
* qc.OP_NAME(%PARAM) %a0 : !qc.qubit \
503503
* } : !qc.qubit, !qc.qubit \
504504
* ``` \
505505
*/ \
@@ -549,8 +549,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
549549
* builder.c##OP_NAME(PARAM1, PARAM2, q0, q1); \
550550
* ``` \
551551
* ```mlir \
552-
* qc.ctrl(%q0) { \
553-
* qc.OP_NAME(%PARAM1, %PARAM2) %q1 : !qc.qubit \
552+
* qc.ctrl(%q0) (%a0 = %q1) { \
553+
* qc.OP_NAME(%PARAM1, %PARAM2) %a0 : !qc.qubit \
554554
* } : !qc.qubit \
555555
* ``` \
556556
*/ \
@@ -571,8 +571,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
571571
* builder.mc##OP_NAME(PARAM1, PARAM2, {q0, q1}, q2); \
572572
* ``` \
573573
* ```mlir \
574-
* qc.ctrl(%q0, %q1) { \
575-
* qc.OP_NAME(%PARAM1, %PARAM2) %q2 : !qc.qubit \
574+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2) { \
575+
* qc.OP_NAME(%PARAM1, %PARAM2) %a0 : !qc.qubit \
576576
* } : !qc.qubit, !qc.qubit \
577577
* ``` \
578578
*/ \
@@ -625,8 +625,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
625625
* builder.c##OP_NAME(PARAM1, PARAM2, PARAM3, q0, q1); \
626626
* ``` \
627627
* ```mlir \
628-
* qc.ctrl(%q0) { \
629-
* qc.OP_NAME(%PARAM1, %PARAM2, %PARAM3) %q1 : !qc.qubit \
628+
* qc.ctrl(%q0) targets(%a0 = %q1) { \
629+
* qc.OP_NAME(%PARAM1, %PARAM2, %PARAM3) %a0 : !qc.qubit \
630630
* } : !qc.qubit \
631631
* ``` \
632632
*/ \
@@ -649,8 +649,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
649649
* builder.mc##OP_NAME(PARAM1, PARAM2, PARAM3, {q0, q1}, q2); \
650650
* ``` \
651651
* ```mlir \
652-
* qc.ctrl(%q0, %q1) { \
653-
* qc.OP_NAME(%PARAM1, %PARAM2, %PARAM3) %q2 : !qc.qubit \
652+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2) { \
653+
* qc.OP_NAME(%PARAM1, %PARAM2, %PARAM3) %a0 : !qc.qubit \
654654
* } : !qc.qubit, !qc.qubit \
655655
* ``` \
656656
*/ \
@@ -695,8 +695,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
695695
* builder.c##OP_NAME(q0, q1, q2); \
696696
* ``` \
697697
* ```mlir \
698-
* qc.ctrl(%q0) { \
699-
* qc.OP_NAME %q1, %q2 : !qc.qubit, !qc.qubit \
698+
* qc.ctrl(%q0) targets(%a0 = %q1, %a1 = %q2) { \
699+
* qc.OP_NAME %a0, %a1 : !qc.qubit, !qc.qubit \
700700
* } : !qc.qubit \
701701
* ``` \
702702
*/ \
@@ -714,8 +714,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
714714
* builder.mc##OP_NAME({q0, q1}, q2, q3); \
715715
* ``` \
716716
* ```mlir \
717-
* qc.ctrl(%q0, %q1) { \
718-
* qc.OP_NAME %q2, %q3 : !qc.qubit, !qc.qubit \
717+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2, %a1 = %q3) { \
718+
* qc.OP_NAME %a0, %a1 : !qc.qubit, !qc.qubit \
719719
* } : !qc.qubit, !qc.qubit \
720720
* ``` \
721721
*/ \
@@ -764,8 +764,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
764764
* builder.c##OP_NAME(PARAM, q0, q1, q2); \
765765
* ``` \
766766
* ```mlir \
767-
* qc.ctrl(%q0) { \
768-
* qc.OP_NAME(%PARAM) %q1, %q2 : !qc.qubit, !qc.qubit \
767+
* qc.ctrl(%q0) targets(%a0 = %q1, %a1 = %q2) { \
768+
* qc.OP_NAME(%PARAM) %a0, %a1 : !qc.qubit, !qc.qubit \
769769
* } : !qc.qubit \
770770
* ``` \
771771
*/ \
@@ -785,8 +785,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
785785
* builder.mc##OP_NAME(PARAM, {q0, q1}, q2, q3); \
786786
* ``` \
787787
* ```mlir \
788-
* qc.ctrl(%q0, %q1) { \
789-
* qc.OP_NAME(%PARAM) %q2, %q3 : !qc.qubit, !qc.qubit \
788+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2, %a1 = %q3) { \
789+
* qc.OP_NAME(%PARAM) %a0, %a1 : !qc.qubit, !qc.qubit \
790790
* } : !qc.qubit, !qc.qubit \
791791
* ``` \
792792
*/ \
@@ -839,8 +839,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
839839
* builder.c##OP_NAME(PARAM1, PARAM2, q0, q1, q2); \
840840
* ``` \
841841
* ```mlir \
842-
* qc.ctrl(%q0) { \
843-
* qc.OP_NAME(%PARAM1, %PARAM2) %q1, %q2 : !qc.qubit, \
842+
* qc.ctrl(%q0) targets(%a0 = %q1, %a1 = %q2) { \
843+
* qc.OP_NAME(%PARAM1, %PARAM2) %a0, %a1 : !qc.qubit, \
844844
* !qc.qubit \
845845
* } : !qc.qubit \
846846
* ``` \
@@ -863,8 +863,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
863863
* builder.mc##OP_NAME(PARAM1, PARAM2, {q0, q1}, q2, q3); \
864864
* ``` \
865865
* ```mlir \
866-
* qc.ctrl(%q0, %q1) { \
867-
* qc.OP_NAME(%PARAM1, %PARAM2) %q2, %q3 : !qc.qubit, !qc.qubit \
866+
* qc.ctrl(%q0, %q1) targets(%a0 = %q2, %a1 = %q3) { \
867+
* qc.OP_NAME(%PARAM1, %PARAM2) %a0, %a1 : !qc.qubit, !qc.qubit \
868868
* } : !qc.qubit, !qc.qubit \
869869
* ``` \
870870
*/ \
@@ -909,11 +909,13 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
909909
*
910910
* @par Example:
911911
* ```c++
912-
* builder.ctrl(q0, [&] { builder.x(q1); });
912+
* builder.ctrl(q0, q1, [&](ValueRange targets) {
913+
* builder.x(targets[0]);
914+
* });
913915
* ```
914916
* ```mlir
915-
* qc.ctrl(%q0) {
916-
* qc.x %q1 : !qc.qubit
917+
* qc.ctrl(%q0) targets(%a0 = %q1) {
918+
* qc.x %a0 : !qc.qubit
917919
* } : !qc.qubit
918920
* ```
919921
*/
@@ -929,7 +931,9 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
929931
*
930932
* @par Example:
931933
* ```c++
932-
* builder.inv([&] { builder.s(q0); });
934+
* builder.inv(q0, [&](ValueRange qubits) {
935+
* builder.h(qubits[0]);
936+
* });
933937
* ```
934938
* ```mlir
935939
* qc.inv {

mlir/include/mlir/Dialect/QC/IR/QCOps.td

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -921,18 +921,19 @@ def CtrlOp
921921
RecursiveMemoryEffects]> {
922922
let summary = "Add control qubits to a unitary operation";
923923
let description = [{
924-
A modifier operation that adds control qubits to the unitary operation
925-
defined in its body region. The controlled operation applies the
926-
underlying unitary only when all control qubits are in the |1⟩ state.
924+
A modifier operation that adds control qubits to the unitary operation defined in its body region.
925+
The controlled operation applies the underlying unitary only when all control qubits are in the $|1\rangle$ state.
927926

928-
Note that control qubits are logically unmodified by this operation in that
929-
their quantum state remains unchanged. However, the `controls` argument
930-
is marked with `MemWrite` to ensure correct dependency tracking in MLIR.
927+
Note that control qubits are logically unmodified by this operation in that their quantum state remains unchanged.
928+
However, the `controls` argument is marked with `MemWrite` to ensure correct dependency tracking in MLIR.
929+
930+
The body region may contain an arbitrary amount of unitary and classical operations.
931+
Non-unitary operations, such as `AllocOp` and `MeasureOp`, are not allowed.
931932

932933
Example:
933934
```mlir
934-
qc.ctrl(%q0) {
935-
qc.x %q1 : !qc.qubit
935+
qc.ctrl(%q0) targets(%a0 = %q1) {
936+
qc.x %a0 : !qc.qubit
936937
} : !qc.qubit
937938
```
938939
}];
@@ -978,13 +979,15 @@ def InvOp : QCOp<"inv",
978979
RecursiveMemoryEffects]> {
979980
let summary = "Invert a unitary operation";
980981
let description = [{
981-
A modifier operation that inverts the unitary operation defined in its body
982-
region.
982+
A modifier operation that inverts the unitary operation defined in its body region.
983+
984+
The body region may contain an arbitrary amount of unitary and classical operations.
985+
Non-unitary operations, such as `AllocOp` and `MeasureOp`, are not allowed.
983986

984987
Example:
985988
```mlir
986-
qc.inv {
987-
qc.s %q0 : !qc.qubit
989+
qc.inv (%a0 = %q0) {
990+
qc.s %a0 : !qc.qubit
988991
}
989992
```
990993
}];

mlir/include/mlir/Dialect/QCO/IR/QCOOps.td

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,12 +1069,14 @@ def CtrlOp
10691069
RecursiveMemoryEffects]> {
10701070
let summary = "Add control qubits to a unitary operation";
10711071
let description = [{
1072-
A modifier operation that adds control qubits to the unitary operation
1073-
defined in its body region. The controlled operation applies the
1074-
underlying unitary only when all control qubits are in the |1⟩ state.
1075-
The operation takes a variadic number of control and target qubits as
1076-
inputs and produces corresponding output qubits. Control qubits are not
1077-
modified by the operation and simply pass through to the outputs.
1072+
A modifier operation that adds control qubits to the unitary operation defined in its body region.
1073+
The controlled operation applies the underlying unitary only when all control qubits are in the $|1\rangle$ state.
1074+
1075+
The operation takes a variadic number of control and target qubits as inputs and produces corresponding output qubits.
1076+
Control qubits are not modified by the operation and simply pass through to the outputs.
1077+
1078+
The body region may contain an arbitrary amount of unitary and classical operations.
1079+
Non-unitary operations, such as `AllocOp` and `MeasureOp`, are not allowed.
10781080

10791081
Example:
10801082
```mlir
@@ -1147,9 +1149,12 @@ def InvOp
11471149
RecursiveMemoryEffects]> {
11481150
let summary = "Invert a unitary operation";
11491151
let description = [{
1150-
A modifier operation that inverts the unitary operation defined in its body
1151-
region. The operation takes a variadic number of qubits as inputs and
1152-
produces corresponding output qubits.
1152+
A modifier operation that inverts the unitary operation defined in its body region.
1153+
1154+
The operation takes a variadic number of qubits as inputs and produces corresponding output qubits.
1155+
1156+
The body region may contain an arbitrary amount of unitary and classical operations.
1157+
Non-unitary operations, such as `AllocOp` and `MeasureOp`, are not allowed.
11531158

11541159
Example:
11551160
```mlir

mlir/lib/Conversion/QCOToQC/QCOToQC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ struct ConvertQCOBarrierOp final : OpConversionPattern<qco::BarrierOp> {
630630
* ```
631631
* is converted to
632632
* ```mlir
633-
* qc.ctrl(%q0) {
634-
* qc.x %q1 : !qc.qubit
633+
* qc.ctrl(%q0) targets(%a0 = %q1) {
634+
* qc.x %a0 : !qc.qubit
635635
* } : !qc.qubit
636636
* ```
637637
*/

mlir/lib/Conversion/QCToQCO/QCToQCO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ struct ConvertQCBarrierOp final : StatefulOpConversionPattern<qc::BarrierOp> {
10761076
*
10771077
* @par Example:
10781078
* ```mlir
1079-
* qc.ctrl(%q0) {
1080-
* qc.x %q1 : !qc.qubit
1079+
* qc.ctrl(%q0) targets(%a0 = %q1) {
1080+
* qc.x %a0 : !qc.qubit
10811081
* } : !qc.qubit
10821082
* ```
10831083
* is converted to

0 commit comments

Comments
 (0)