Skip to content

Commit 05c9335

Browse files
committed
conversion tests
🎨 pre-commit fixes
1 parent 48ee457 commit 05c9335

8 files changed

Lines changed: 38 additions & 27 deletions

File tree

mlir/lib/Dialect/QC/IR/Modifiers/PowOp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <llvm/ADT/STLFunctionalExtras.h>
1616
#include <llvm/ADT/TypeSwitch.h>
1717
#include <llvm/Support/Casting.h>
18-
19-
#include <cstdint>
2018
#include <mlir/Dialect/Arith/IR/Arith.h>
2119
#include <mlir/IR/Builders.h>
2220
#include <mlir/IR/MLIRContext.h>
@@ -26,6 +24,7 @@
2624
#include <mlir/Support/LogicalResult.h>
2725

2826
#include <cmath>
27+
#include <cstdint>
2928
#include <numbers>
3029

3130
using namespace mlir;

mlir/lib/Dialect/QCO/IR/Modifiers/PowOp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <Eigen/Core>
1616
#include <Eigen/Eigenvalues>
1717
#include <llvm/ADT/STLFunctionalExtras.h>
18-
19-
#include <cstdint>
2018
#include <llvm/ADT/SmallVector.h>
2119
#include <llvm/ADT/TypeSwitch.h>
2220
#include <llvm/Support/Casting.h>
@@ -33,6 +31,7 @@
3331

3432
#include <cmath>
3533
#include <cstddef>
34+
#include <cstdint>
3635
#include <numbers>
3736
#include <optional>
3837

mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,10 @@ INSTANTIATE_TEST_SUITE_P(
148148
INSTANTIATE_TEST_SUITE_P(
149149
QCOPowOpTest, QCOToQCTest,
150150
testing::Values(
151-
QCOToQCTestCase{"PowSingleExponent",
152-
MQT_NAMED_BUILDER(qco::powSingleExponent),
153-
MQT_NAMED_BUILDER(qc::powSingleExponent)},
154-
QCOToQCTestCase{"NestedPow", MQT_NAMED_BUILDER(qco::nestedPow),
155-
MQT_NAMED_BUILDER(qc::powSingleExponent)},
156-
QCOToQCTestCase{"PowRxx", MQT_NAMED_BUILDER(qco::powRxx),
157-
MQT_NAMED_BUILDER(qc::powRxx)},
158-
QCOToQCTestCase{"NegPowRx", MQT_NAMED_BUILDER(qco::negPowRx),
159-
MQT_NAMED_BUILDER(qc::negPowRx)},
160-
QCOToQCTestCase{"InvPowRx", MQT_NAMED_BUILDER(qco::invPowRx),
161-
MQT_NAMED_BUILDER(qc::powRxNeg)}));
151+
// pow(1/3){SX} inside ctrl: fold would emit gphase+rx (two ops,
152+
// invalid in ctrl body) → pow survives and hits ConvertQCOPowOp
153+
QCOToQCTestCase{"CtrlPowSx", MQT_NAMED_BUILDER(qco::ctrlPowSx),
154+
MQT_NAMED_BUILDER(qc::ctrlPowSx)}));
162155
/// @}
163156

164157
/// \name QCOToQC/Modifiers/InvOp.cpp

mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,11 @@ INSTANTIATE_TEST_SUITE_P(
146146
/// @{
147147
INSTANTIATE_TEST_SUITE_P(
148148
QCPowOpTest, QCToQCOTest,
149-
testing::Values(QCToQCOTestCase{"PowSingleExponent",
150-
MQT_NAMED_BUILDER(qc::powSingleExponent),
151-
MQT_NAMED_BUILDER(qco::powSingleExponent)},
152-
QCToQCOTestCase{"NestedPow",
153-
MQT_NAMED_BUILDER(qc::nestedPow),
154-
MQT_NAMED_BUILDER(qco::powSingleExponent)},
155-
QCToQCOTestCase{"PowRxx", MQT_NAMED_BUILDER(qc::powRxx),
156-
MQT_NAMED_BUILDER(qco::powRxx)},
157-
QCToQCOTestCase{"NegPowRx", MQT_NAMED_BUILDER(qc::negPowRx),
158-
MQT_NAMED_BUILDER(qco::negPowRx)},
159-
QCToQCOTestCase{"InvPowRx", MQT_NAMED_BUILDER(qc::invPowRx),
160-
MQT_NAMED_BUILDER(qco::powRxNeg)}));
149+
testing::Values(
150+
// pow(1/3){SX} inside ctrl: fold would emit gphase+rx (two ops,
151+
// invalid in ctrl body) → pow survives and hits ConvertQCPowOp
152+
QCToQCOTestCase{"CtrlPowSx", MQT_NAMED_BUILDER(qc::ctrlPowSx),
153+
MQT_NAMED_BUILDER(qco::ctrlPowSx)}));
161154
/// @}
162155

163156
/// \name QCToQCO/Modifiers/InvOp.cpp

mlir/unittests/programs/qc_programs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,4 +1608,9 @@ void ctrlPowRx(QCProgramBuilder& b) {
16081608
b.ctrl(q[0], [&] { b.pow(2.0, [&] { b.rx(0.123, q[1]); }); });
16091609
}
16101610

1611+
void ctrlPowSx(QCProgramBuilder& b) {
1612+
auto q = b.allocQubitRegister(2);
1613+
b.ctrl(q[0], [&] { b.pow(1.0 / 3.0, [&] { b.sx(q[1]); }); });
1614+
}
1615+
16111616
} // namespace mlir::qc

mlir/unittests/programs/qc_programs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,4 +1040,9 @@ void powCtrlRx(QCProgramBuilder& b);
10401040
/// powCtrlRx).
10411041
void ctrlPowRx(QCProgramBuilder& b);
10421042

1043+
/// Creates a circuit with ctrl wrapping pow(1/3) wrapping SX. The fold
1044+
/// pow(p){SX} → gphase+rx is suppressed inside ctrl (would emit two ops),
1045+
/// so the pow survives canonicalization and reaches ConvertQCPowOp.
1046+
void ctrlPowSx(QCProgramBuilder& b);
1047+
10431048
} // namespace mlir::qc

mlir/unittests/programs/qco_programs.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,18 @@ void ctrlPowRx(QCOProgramBuilder& b) {
25712571
});
25722572
}
25732573

2574+
void ctrlPowSx(QCOProgramBuilder& b) {
2575+
auto q = b.allocQubitRegister(2);
2576+
b.ctrl({q[0]}, {q[1]}, [&](mlir::ValueRange targets) {
2577+
auto inner =
2578+
b.pow({targets[0]}, 1.0 / 3.0, [&](mlir::ValueRange powArgs) {
2579+
auto q0 = b.sx(powArgs[0]);
2580+
return llvm::SmallVector<mlir::Value>{q0};
2581+
});
2582+
return llvm::SmallVector<mlir::Value>{inner};
2583+
});
2584+
}
2585+
25742586
// --- IfOp ---------------------------------------------------------------- //
25752587

25762588
void simpleIf(QCOProgramBuilder& b) {

mlir/unittests/programs/qco_programs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,11 @@ void powCtrlRx(QCOProgramBuilder& b);
11861186
/// powCtrlRx).
11871187
void ctrlPowRx(QCOProgramBuilder& b);
11881188

1189+
/// Creates a circuit with ctrl wrapping pow(1/3) wrapping SX. The fold
1190+
/// pow(p){SX} → gphase+rx is suppressed inside ctrl (would emit two ops),
1191+
/// so the pow survives canonicalization and reaches ConvertQCOPowOp.
1192+
void ctrlPowSx(QCOProgramBuilder& b);
1193+
11891194
// --- IfOp ---------------------------------------------------------------- //
11901195

11911196
/// Creates a circuit with a simple if operation with one qubit.

0 commit comments

Comments
 (0)