Skip to content

Commit f353012

Browse files
committed
🔧 Update static qubits test cases and implementations across QC, QIR, and QCO programs.
1 parent d2d54c1 commit f353012

12 files changed

Lines changed: 102 additions & 62 deletions

File tree

‎mlir/unittests/Compiler/test_compiler_pipeline.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ INSTANTIATE_TEST_SUITE_P(
198198
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithOps),
199199
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithOps),
200200
MQT_NAMED_BUILDER(mlir::qir::staticQubitsWithOps), false},
201-
CompilerPipelineTestCase{
202-
"StaticQubitsWithDuplicates", nullptr,
203-
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithDuplicates),
204-
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithOps),
205-
MQT_NAMED_BUILDER(mlir::qir::staticQubitsWithOps), false},
206201
CompilerPipelineTestCase{
207202
"StaticQubitsWithParametricOps", nullptr,
208203
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithParametricOps),
@@ -223,6 +218,11 @@ INSTANTIATE_TEST_SUITE_P(
223218
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithInv),
224219
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithInv),
225220
MQT_NAMED_BUILDER(mlir::qir::staticQubitsWithInv), false},
221+
CompilerPipelineTestCase{
222+
"StaticQubitsWithDuplicates", nullptr,
223+
MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithDuplicates),
224+
MQT_NAMED_BUILDER(mlir::qc::staticQubitsCanonical),
225+
MQT_NAMED_BUILDER(mlir::qir::staticQubitsCanonical), false},
226226
CompilerPipelineTestCase{"AllocQubit",
227227
MQT_NAMED_BUILDER(qc::allocQubit), nullptr,
228228
MQT_NAMED_BUILDER(mlir::qc::allocQubit),

‎mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ INSTANTIATE_TEST_SUITE_P(
134134
QCToQCOTestCase{"StaticQubitsWithInv",
135135
MQT_NAMED_BUILDER(qc::staticQubitsWithInv),
136136
MQT_NAMED_BUILDER(qco::staticQubitsWithInv)},
137+
QCToQCOTestCase{"StaticQubitsWithDuplicates",
138+
MQT_NAMED_BUILDER(qc::staticQubitsWithDuplicates),
139+
MQT_NAMED_BUILDER(qco::staticQubitsCanonical)},
137140
QCToQCOTestCase{"AllocDeallocPair",
138141
MQT_NAMED_BUILDER(qc::allocDeallocPair),
139142
MQT_NAMED_BUILDER(qco::allocSinkPair)}));

‎mlir/unittests/Conversion/QCToQIR/test_qc_to_qir.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,6 @@ INSTANTIATE_TEST_SUITE_P(
627627
QCToQIRTestCase{"StaticQubitsWithOps",
628628
MQT_NAMED_BUILDER(qc::staticQubitsWithOps),
629629
MQT_NAMED_BUILDER(qir::staticQubitsWithOps)},
630-
QCToQIRTestCase{"StaticQubitsWithDuplicates",
631-
MQT_NAMED_BUILDER(qc::staticQubitsWithDuplicates),
632-
MQT_NAMED_BUILDER(qir::staticQubitsWithOps)},
633630
QCToQIRTestCase{"StaticQubitsWithParametricOps",
634631
MQT_NAMED_BUILDER(qc::staticQubitsWithParametricOps),
635632
MQT_NAMED_BUILDER(qir::staticQubitsWithParametricOps)},
@@ -642,6 +639,9 @@ INSTANTIATE_TEST_SUITE_P(
642639
QCToQIRTestCase{"StaticQubitsWithInv",
643640
MQT_NAMED_BUILDER(qc::staticQubitsWithInv),
644641
MQT_NAMED_BUILDER(qir::staticQubitsWithInv)},
642+
QCToQIRTestCase{"StaticQubitsWithDuplicates",
643+
MQT_NAMED_BUILDER(qc::staticQubitsWithDuplicates),
644+
MQT_NAMED_BUILDER(qir::staticQubitsCanonical)},
645645
QCToQIRTestCase{"AllocDeallocPair",
646646
MQT_NAMED_BUILDER(qc::allocDeallocPair),
647647
MQT_NAMED_BUILDER(qir::emptyQIR)}));

‎mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,6 @@ INSTANTIATE_TEST_SUITE_P(
902902
QCTestCase{"StaticQubitsWithOps",
903903
MQT_NAMED_BUILDER(staticQubitsWithOps),
904904
MQT_NAMED_BUILDER(staticQubitsWithOps)},
905-
QCTestCase{"StaticQubitsWithDuplicates",
906-
MQT_NAMED_BUILDER(staticQubitsWithDuplicates),
907-
MQT_NAMED_BUILDER(staticQubitsWithOps)},
908905
QCTestCase{"StaticQubitsWithParametricOps",
909906
MQT_NAMED_BUILDER(staticQubitsWithParametricOps),
910907
MQT_NAMED_BUILDER(staticQubitsWithParametricOps)},
@@ -917,6 +914,9 @@ INSTANTIATE_TEST_SUITE_P(
917914
QCTestCase{"StaticQubitsWithInv",
918915
MQT_NAMED_BUILDER(staticQubitsWithInv),
919916
MQT_NAMED_BUILDER(staticQubitsWithInv)},
917+
QCTestCase{"StaticQubitsWithDuplicates",
918+
MQT_NAMED_BUILDER(staticQubitsWithDuplicates),
919+
MQT_NAMED_BUILDER(staticQubitsCanonical)},
920920
QCTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(allocDeallocPair),
921921
MQT_NAMED_BUILDER(emptyQC)}));
922922
/// @}

‎mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,9 @@ INSTANTIATE_TEST_SUITE_P(
10751075
QCOTestCase{"StaticQubitsWithInv",
10761076
MQT_NAMED_BUILDER(staticQubitsWithInv),
10771077
MQT_NAMED_BUILDER(staticQubitsWithInv)},
1078+
QCOTestCase{"StaticQubitsWithDuplicatesCanonical",
1079+
MQT_NAMED_BUILDER(staticQubitsCanonical),
1080+
MQT_NAMED_BUILDER(staticQubitsCanonical)},
10781081
QCOTestCase{"AllocSinkPair", MQT_NAMED_BUILDER(allocSinkPair),
10791082
MQT_NAMED_BUILDER(emptyQCO)}));
10801083
/// @}

‎mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,6 @@ INSTANTIATE_TEST_SUITE_P(
537537
QIRTestCase{"StaticQubitsWithOps",
538538
MQT_NAMED_BUILDER(staticQubitsWithOps),
539539
MQT_NAMED_BUILDER(staticQubitsWithOps)},
540-
QIRTestCase{"StaticQubitsWithDuplicates",
541-
MQT_NAMED_BUILDER(staticQubitsWithDuplicates),
542-
MQT_NAMED_BUILDER(staticQubitsWithOps)},
543540
QIRTestCase{"StaticQubitsWithParametricOps",
544541
MQT_NAMED_BUILDER(staticQubitsWithParametricOps),
545542
MQT_NAMED_BUILDER(staticQubitsWithParametricOps)},
@@ -551,5 +548,8 @@ INSTANTIATE_TEST_SUITE_P(
551548
MQT_NAMED_BUILDER(staticQubitsWithCtrl)},
552549
QIRTestCase{"StaticQubitsWithInv",
553550
MQT_NAMED_BUILDER(staticQubitsWithInv),
554-
MQT_NAMED_BUILDER(staticQubitsWithInv)}));
551+
MQT_NAMED_BUILDER(staticQubitsWithInv)},
552+
QIRTestCase{"StaticQubitsWithDuplicates",
553+
MQT_NAMED_BUILDER(staticQubitsWithDuplicates),
554+
MQT_NAMED_BUILDER(staticQubitsCanonical)}));
555555
/// @}

‎mlir/unittests/programs/qc_programs.cpp‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ void allocLargeRegister(QCProgramBuilder& b) { b.allocQubitRegister(100); }
3232
void staticQubits(QCProgramBuilder& b) {
3333
const auto q0 = b.staticQubit(0);
3434
const auto q1 = b.staticQubit(1);
35-
36-
b.h(q0);
37-
b.h(q1);
38-
b.ctrl(q0, [&] { b.x(q1); });
3935
}
4036

4137
void staticQubitsWithOps(QCProgramBuilder& b) {
@@ -44,18 +40,6 @@ void staticQubitsWithOps(QCProgramBuilder& b) {
4440

4541
b.h(q0);
4642
b.h(q1);
47-
b.ctrl(q0, [&] { b.x(q1); });
48-
}
49-
50-
void staticQubitsWithDuplicates(QCProgramBuilder& b) {
51-
const auto q0a = b.staticQubit(0);
52-
const auto q1a = b.staticQubit(1);
53-
const auto q0b = b.staticQubit(0);
54-
const auto q1b = b.staticQubit(1);
55-
56-
b.h(q0a);
57-
b.h(q1a);
58-
b.ctrl(q0b, [&] { b.x(q1b); });
5943
}
6044

6145
void staticQubitsWithParametricOps(QCProgramBuilder& b) {
@@ -82,6 +66,30 @@ void staticQubitsWithInv(QCProgramBuilder& b) {
8266
b.inv([&]() { b.t(q0); });
8367
}
8468

69+
void staticQubitsWithDuplicates(QCProgramBuilder& b) {
70+
const auto q0a = b.staticQubit(0);
71+
const auto q1a = b.staticQubit(1);
72+
const auto q0b = b.staticQubit(0);
73+
const auto q1b = b.staticQubit(1);
74+
75+
b.rx(std::numbers::pi / 4., q0a);
76+
b.p(std::numbers::pi / 2., q1a);
77+
b.rzz(0.123, q0b, q1b);
78+
b.cx(q0b, q1b);
79+
b.inv([&]() { b.t(q0a); });
80+
}
81+
82+
void staticQubitsCanonical(QCProgramBuilder& b) {
83+
const auto q0 = b.staticQubit(0);
84+
const auto q1 = b.staticQubit(1);
85+
86+
b.rx(std::numbers::pi / 4., q0);
87+
b.p(std::numbers::pi / 2., q1);
88+
b.rzz(0.123, q0, q1);
89+
b.cx(q0, q1);
90+
b.inv([&]() { b.t(q0); });
91+
}
92+
8593
void allocDeallocPair(QCProgramBuilder& b) {
8694
auto q = b.allocQubit();
8795
b.dealloc(q);

‎mlir/unittests/programs/qc_programs.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@ void allocMultipleQubitRegisters(QCProgramBuilder& b);
3030
/// Allocates a large qubit register.
3131
void allocLargeRegister(QCProgramBuilder& b);
3232

33-
/// Allocates two inline qubits and applies H on both and a controlled-X between
34-
/// them.
33+
/// Allocates two inline qubits.
3534
void staticQubits(QCProgramBuilder& b);
3635

3736
/// Allocates two static qubits and applies operations.
3837
void staticQubitsWithOps(QCProgramBuilder& b);
3938

40-
/// Allocates duplicate static qubits and applies H on both and a controlled-X
41-
/// between them.
42-
void staticQubitsWithDuplicates(QCProgramBuilder& b);
43-
4439
/// Allocates two static qubits and applies parametric gates.
4540
void staticQubitsWithParametricOps(QCProgramBuilder& b);
4641

@@ -52,6 +47,14 @@ void staticQubitsWithCtrl(QCProgramBuilder& b);
5247

5348
/// Allocates a static qubit and applies an inverse modifier.
5449
void staticQubitsWithInv(QCProgramBuilder& b);
50+
51+
/// Allocates duplicate static qubits and applies operations on both.
52+
void staticQubitsWithDuplicates(QCProgramBuilder& b);
53+
54+
/// Same as `staticQubitsWithDuplicates`, but with canonical static qubit
55+
/// retrievals.
56+
void staticQubitsCanonical(QCProgramBuilder& b);
57+
5558
/// Allocates and explicitly deallocates a single qubit.
5659
void allocDeallocPair(QCProgramBuilder& b);
5760

‎mlir/unittests/programs/qco_programs.cpp‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ void allocLargeRegister(QCOProgramBuilder& b) { b.allocQubitRegister(100); }
3636
void staticQubits(QCOProgramBuilder& b) {
3737
auto q0 = b.staticQubit(0);
3838
auto q1 = b.staticQubit(1);
39-
40-
q0 = b.h(q0);
41-
q1 = b.h(q1);
42-
b.ctrl({q0}, {q1}, [&](mlir::ValueRange targets) {
43-
return llvm::SmallVector<mlir::Value>{b.x(targets[0])};
44-
});
4539
}
4640

4741
void staticQubitsWithOps(QCOProgramBuilder& b) {
@@ -77,6 +71,19 @@ void staticQubitsWithInv(QCOProgramBuilder& b) {
7771
})[0];
7872
}
7973

74+
void staticQubitsCanonical(QCOProgramBuilder& b) {
75+
auto q0 = b.staticQubit(0);
76+
auto q1 = b.staticQubit(1);
77+
78+
q0 = b.rx(std::numbers::pi / 4., q0);
79+
q1 = b.p(std::numbers::pi / 2., q1);
80+
std::tie(q0, q1) = b.rzz(0.123, q0, q1);
81+
std::tie(q0, q1) = b.cx(q0, q1);
82+
q0 = b.inv({q0}, [&](auto targets) -> llvm::SmallVector<Value> {
83+
return {b.t(targets[0])};
84+
})[0];
85+
}
86+
8087
void allocSinkPair(QCOProgramBuilder& b) {
8188
auto q = b.allocQubit();
8289
b.sink(q);

‎mlir/unittests/programs/qco_programs.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ void allocMultipleQubitRegisters(QCOProgramBuilder& b);
3030
/// Allocates a large qubit register.
3131
void allocLargeRegister(QCOProgramBuilder& b);
3232

33-
/// Allocates two inline qubits and applies H on both and a controlled-X between
34-
/// them.
33+
/// Allocates two inline qubits.
3534
void staticQubits(QCOProgramBuilder& b);
3635

3736
/// Allocates two static qubits and applies operations.
@@ -49,6 +48,9 @@ void staticQubitsWithCtrl(QCOProgramBuilder& b);
4948
/// Allocates a static qubit and applies an inverse modifier.
5049
void staticQubitsWithInv(QCOProgramBuilder& b);
5150

51+
/// Same as `staticQubitsCanonical` in `qc_programs.cpp` and `qir_programs.cpp`.
52+
void staticQubitsCanonical(QCOProgramBuilder& b);
53+
5254
/// Allocates and explicitly sinks a single qubit.
5355
void allocSinkPair(QCOProgramBuilder& b);
5456

0 commit comments

Comments
 (0)