Skip to content

Commit d493825

Browse files
committed
use rx instead of s gate for tests
1 parent dc57d7d commit d493825

8 files changed

Lines changed: 136 additions & 62 deletions

File tree

mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ INSTANTIATE_TEST_SUITE_P(
152152
MQT_NAMED_BUILDER(qc::powSingleExponent)},
153153
QCOToQCTestCase{"PowRxx", MQT_NAMED_BUILDER(qco::powRxx),
154154
MQT_NAMED_BUILDER(qc::powRxx)},
155-
QCOToQCTestCase{"NegPowS", MQT_NAMED_BUILDER(qco::negPowS),
156-
MQT_NAMED_BUILDER(qc::negPowS)},
157-
QCOToQCTestCase{"InvPowS", MQT_NAMED_BUILDER(qco::invPowS),
158-
MQT_NAMED_BUILDER(qc::powSdg)}));
155+
QCOToQCTestCase{"NegPowRx", MQT_NAMED_BUILDER(qco::negPowRx),
156+
MQT_NAMED_BUILDER(qc::negPowRx)},
157+
QCOToQCTestCase{"InvPowRx", MQT_NAMED_BUILDER(qco::invPowRx),
158+
MQT_NAMED_BUILDER(qc::powRxNeg)}));
159159
/// @}
160160

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

mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ INSTANTIATE_TEST_SUITE_P(
151151
MQT_NAMED_BUILDER(qco::powSingleExponent)},
152152
QCToQCOTestCase{"PowRxx", MQT_NAMED_BUILDER(qc::powRxx),
153153
MQT_NAMED_BUILDER(qco::powRxx)},
154-
QCToQCOTestCase{"NegPowS", MQT_NAMED_BUILDER(qc::negPowS),
155-
MQT_NAMED_BUILDER(qco::negPowS)},
156-
QCToQCOTestCase{"InvPowS", MQT_NAMED_BUILDER(qc::invPowS),
157-
MQT_NAMED_BUILDER(qco::powSdg)}));
154+
QCToQCOTestCase{"NegPowRx", MQT_NAMED_BUILDER(qc::negPowRx),
155+
MQT_NAMED_BUILDER(qco::negPowRx)},
156+
QCToQCOTestCase{"InvPowRx", MQT_NAMED_BUILDER(qc::invPowRx),
157+
MQT_NAMED_BUILDER(qco::powRxNeg)}));
158158
/// @}
159159

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

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,31 @@ INSTANTIATE_TEST_SUITE_P(
116116
/// @{
117117
INSTANTIATE_TEST_SUITE_P(
118118
QCPowOpTest, QCTest,
119-
testing::Values(QCTestCase{"Pow1Inline", MQT_NAMED_BUILDER(pow1Inline),
120-
MQT_NAMED_BUILDER(s)},
121-
QCTestCase{"Pow0Erase", MQT_NAMED_BUILDER(pow0Erase),
122-
MQT_NAMED_BUILDER(emptyQC)},
123-
QCTestCase{"NestedPow", MQT_NAMED_BUILDER(nestedPow),
124-
MQT_NAMED_BUILDER(powSingleExponent)},
125-
QCTestCase{"PowRxx", MQT_NAMED_BUILDER(powRxx),
126-
MQT_NAMED_BUILDER(powRxx)},
127-
QCTestCase{"NegPowS", MQT_NAMED_BUILDER(negPowS),
128-
MQT_NAMED_BUILDER(powSdg)},
129-
QCTestCase{"InvPowS", MQT_NAMED_BUILDER(invPowS),
130-
MQT_NAMED_BUILDER(powSdg)}));
119+
testing::Values(
120+
// pow(1) { g } => g (InlinePow1)
121+
QCTestCase{"Pow1Inline", MQT_NAMED_BUILDER(pow1Inline),
122+
MQT_NAMED_BUILDER(rx)},
123+
// pow(0) { g } => <erased> (ErasePow0)
124+
QCTestCase{"Pow0Erase", MQT_NAMED_BUILDER(pow0Erase),
125+
MQT_NAMED_BUILDER(emptyQC)},
126+
// pow(p) { pow(q) { g } } => pow(p*q) { g } (MergeNestedPow)
127+
QCTestCase{"NestedPow", MQT_NAMED_BUILDER(nestedPow),
128+
MQT_NAMED_BUILDER(powSingleExponent)},
129+
// // pow(p) { g } unchanged when no simplification applies
130+
// QCTestCase{"PowRxx", MQT_NAMED_BUILDER(powRxx),
131+
// MQT_NAMED_BUILDER(powRxx)},
132+
// pow(-p) { g } => pow(p) { inv { g } } (NegPowToInvPow)
133+
QCTestCase{"NegPowRx", MQT_NAMED_BUILDER(negPowRx),
134+
MQT_NAMED_BUILDER(powRxNeg)},
135+
// TODO should this maybe be in the inv tests?
136+
// inv { pow(p) { g } } => pow(p) { inv { g } }
137+
// (MovePowOutside)
138+
QCTestCase{"InvPowRx", MQT_NAMED_BUILDER(invPowRx),
139+
MQT_NAMED_BUILDER(powRxNeg)},
140+
// pow(p) { ctrl(q) { g } } => ctrl(q) { pow(p) { g } }
141+
// (MoveCtrlOutside)
142+
QCTestCase{"PowCtrlRx", MQT_NAMED_BUILDER(powCtrlRx),
143+
MQT_NAMED_BUILDER(ctrlPowRx)}));
131144
/// @}
132145

133146
/// \name QC/Modifiers/InvOp.cpp

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,29 @@ INSTANTIATE_TEST_SUITE_P(
185185
/// @{
186186
INSTANTIATE_TEST_SUITE_P(
187187
QCOPowOpTest, QCOTest,
188-
testing::Values(QCOTestCase{"Pow1Inline", MQT_NAMED_BUILDER(pow1Inline),
189-
MQT_NAMED_BUILDER(s)},
190-
QCOTestCase{"Pow0Erase", MQT_NAMED_BUILDER(pow0Erase),
191-
MQT_NAMED_BUILDER(emptyQCO)},
192-
QCOTestCase{"NestedPow", MQT_NAMED_BUILDER(nestedPow),
193-
MQT_NAMED_BUILDER(powSingleExponent)},
194-
QCOTestCase{"PowRxx", MQT_NAMED_BUILDER(powRxx),
195-
MQT_NAMED_BUILDER(powRxx)},
196-
QCOTestCase{"NegPowS", MQT_NAMED_BUILDER(negPowS),
197-
MQT_NAMED_BUILDER(powSdg)},
198-
QCOTestCase{"InvPowS", MQT_NAMED_BUILDER(invPowS),
199-
MQT_NAMED_BUILDER(powSdg)}));
188+
testing::Values(
189+
// pow(1) { g } => g (InlinePow1)
190+
QCOTestCase{"Pow1Inline", MQT_NAMED_BUILDER(pow1Inline),
191+
MQT_NAMED_BUILDER(rx)},
192+
// pow(0) { g } => <erased> (ErasePow0)
193+
QCOTestCase{"Pow0Erase", MQT_NAMED_BUILDER(pow0Erase),
194+
MQT_NAMED_BUILDER(emptyQCO)},
195+
// pow(p) { pow(q) { g } } => pow(p*q) { g } (MergeNestedPow)
196+
QCOTestCase{"NestedPow", MQT_NAMED_BUILDER(nestedPow),
197+
MQT_NAMED_BUILDER(powSingleExponent)},
198+
// pow(p) { g } unchanged when no simplification applies
199+
QCOTestCase{"PowRxx", MQT_NAMED_BUILDER(powRxx),
200+
MQT_NAMED_BUILDER(powRxx)},
201+
// pow(-p) { g } => pow(p) { inv { g } } (NegPowToInvPow)
202+
QCOTestCase{"NegPowRx", MQT_NAMED_BUILDER(negPowRx),
203+
MQT_NAMED_BUILDER(powRxNeg)},
204+
// inv { pow(p) { g } } => pow(p) { inv { g } }
205+
QCOTestCase{"InvPowRx", MQT_NAMED_BUILDER(invPowRx),
206+
MQT_NAMED_BUILDER(powRxNeg)},
207+
// pow(p) { ctrl(q) { g } } => ctrl(q) { pow(p) { g } }
208+
// (MoveCtrlOutside)
209+
QCOTestCase{"PowCtrlRx", MQT_NAMED_BUILDER(powCtrlRx),
210+
MQT_NAMED_BUILDER(ctrlPowRx)}));
200211
/// @}
201212

202213
/// \name QCO/Operations/StandardGates/BarrierOp.cpp

mlir/unittests/programs/qc_programs.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,42 +1240,52 @@ void invCtrlSandwich(QCProgramBuilder& b) {
12401240

12411241
void pow1Inline(QCProgramBuilder& b) {
12421242
auto q = b.allocQubitRegister(1);
1243-
b.pow(1.0, [&] { b.s(q[0]); });
1243+
b.pow(1.0, [&] { b.rx(0.123, q[0]); });
12441244
}
12451245

12461246
void pow0Erase(QCProgramBuilder& b) {
12471247
auto q = b.allocQubitRegister(1);
1248-
b.pow(0.0, [&] { b.s(q[0]); });
1248+
b.pow(0.0, [&] { b.rx(0.123, q[0]); });
12491249
}
12501250

12511251
void nestedPow(QCProgramBuilder& b) {
12521252
auto q = b.allocQubitRegister(1);
1253-
b.pow(3.0, [&] { b.pow(2.0, [&] { b.s(q[0]); }); });
1253+
b.pow(3.0, [&] { b.pow(2.0, [&] { b.rx(0.123, q[0]); }); });
12541254
}
12551255

12561256
void powSingleExponent(QCProgramBuilder& b) {
12571257
auto q = b.allocQubitRegister(1);
1258-
b.pow(6.0, [&] { b.s(q[0]); });
1258+
b.pow(6.0, [&] { b.rx(0.123, q[0]); });
12591259
}
12601260

12611261
void powRxx(QCProgramBuilder& b) {
12621262
auto q = b.allocQubitRegister(2);
12631263
b.pow(2.0, [&] { b.rxx(0.123, q[0], q[1]); });
12641264
}
12651265

1266-
void negPowS(QCProgramBuilder& b) {
1266+
void negPowRx(QCProgramBuilder& b) {
12671267
auto q = b.allocQubitRegister(1);
1268-
b.pow(-2.0, [&] { b.s(q[0]); });
1268+
b.pow(-2.0, [&] { b.rx(0.123, q[0]); });
12691269
}
12701270

1271-
void invPowS(QCProgramBuilder& b) {
1271+
void invPowRx(QCProgramBuilder& b) {
12721272
auto q = b.allocQubitRegister(1);
1273-
b.inv([&] { b.pow(2.0, [&] { b.s(q[0]); }); });
1273+
b.inv([&] { b.pow(2.0, [&] { b.rx(0.123, q[0]); }); });
12741274
}
12751275

1276-
void powSdg(QCProgramBuilder& b) {
1276+
void powRxNeg(QCProgramBuilder& b) {
12771277
auto q = b.allocQubitRegister(1);
1278-
b.pow(2.0, [&] { b.sdg(q[0]); });
1278+
b.pow(2.0, [&] { b.rx(-0.123, q[0]); });
1279+
}
1280+
1281+
void powCtrlRx(QCProgramBuilder& b) {
1282+
auto q = b.allocQubitRegister(2);
1283+
b.pow(2.0, [&] { b.ctrl(q[0], [&] { b.rx(0.123, q[1]); }); });
1284+
}
1285+
1286+
void ctrlPowRx(QCProgramBuilder& b) {
1287+
auto q = b.allocQubitRegister(2);
1288+
b.ctrl(q[0], [&] { b.pow(2.0, [&] { b.rx(0.123, q[1]); }); });
12791289
}
12801290

12811291
} // namespace mlir::qc

mlir/unittests/programs/qc_programs.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,23 @@ void powSingleExponent(QCProgramBuilder& b);
827827
/// Creates a circuit with pow(2.0) wrapping a two-qubit RXX gate.
828828
void powRxx(QCProgramBuilder& b);
829829

830-
/// Creates a circuit with pow(-2.0) wrapping an S gate (negative exponent).
831-
void negPowS(QCProgramBuilder& b);
830+
/// Creates a circuit with pow(-2.0) wrapping an RX gate (negative exponent).
831+
void negPowRx(QCProgramBuilder& b);
832832

833833
/// Creates a circuit with inv wrapping pow (should reorder to pow wrapping
834834
/// inv).
835-
void invPowS(QCProgramBuilder& b);
835+
void invPowRx(QCProgramBuilder& b);
836836

837-
/// Creates a circuit with pow(2.0) wrapping sdg (reference for invPowS).
838-
void powSdg(QCProgramBuilder& b);
837+
/// Creates a circuit with pow(2.0) wrapping RX(-0.123) (reference for
838+
/// negPowRx and invPowRx — inv folds into angle negation).
839+
void powRxNeg(QCProgramBuilder& b);
840+
841+
/// Creates a circuit with pow wrapping ctrl wrapping RX (should move ctrl
842+
/// outside).
843+
void powCtrlRx(QCProgramBuilder& b);
844+
845+
/// Creates a circuit with ctrl wrapping pow wrapping RX (reference for
846+
/// powCtrlRx).
847+
void ctrlPowRx(QCProgramBuilder& b);
839848

840849
} // namespace mlir::qc

mlir/unittests/programs/qco_programs.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,15 +2069,15 @@ void invCtrlSandwich(QCOProgramBuilder& b) {
20692069
void pow1Inline(QCOProgramBuilder& b) {
20702070
auto q = b.allocQubitRegister(1);
20712071
b.pow({q[0]}, 1.0, [&](mlir::ValueRange qubits) {
2072-
auto q0 = b.s(qubits[0]);
2072+
auto q0 = b.rx(0.123, qubits[0]);
20732073
return llvm::SmallVector<mlir::Value>{q0};
20742074
});
20752075
}
20762076

20772077
void pow0Erase(QCOProgramBuilder& b) {
20782078
auto q = b.allocQubitRegister(1);
20792079
b.pow({q[0]}, 0.0, [&](mlir::ValueRange qubits) {
2080-
auto q0 = b.s(qubits[0]);
2080+
auto q0 = b.rx(0.123, qubits[0]);
20812081
return llvm::SmallVector<mlir::Value>{q0};
20822082
});
20832083
}
@@ -2086,7 +2086,7 @@ void nestedPow(QCOProgramBuilder& b) {
20862086
auto q = b.allocQubitRegister(1);
20872087
b.pow({q[0]}, 3.0, [&](mlir::ValueRange qubits) {
20882088
auto inner = b.pow({qubits[0]}, 2.0, [&](mlir::ValueRange innerQubits) {
2089-
auto q0 = b.s(innerQubits[0]);
2089+
auto q0 = b.rx(0.123, innerQubits[0]);
20902090
return llvm::SmallVector<mlir::Value>{q0};
20912091
});
20922092
return llvm::SmallVector<mlir::Value>{inner};
@@ -2096,7 +2096,7 @@ void nestedPow(QCOProgramBuilder& b) {
20962096
void powSingleExponent(QCOProgramBuilder& b) {
20972097
auto q = b.allocQubitRegister(1);
20982098
b.pow({q[0]}, 6.0, [&](mlir::ValueRange qubits) {
2099-
auto q0 = b.s(qubits[0]);
2099+
auto q0 = b.rx(0.123, qubits[0]);
21002100
return llvm::SmallVector<mlir::Value>{q0};
21012101
});
21022102
}
@@ -2109,33 +2109,55 @@ void powRxx(QCOProgramBuilder& b) {
21092109
});
21102110
}
21112111

2112-
void negPowS(QCOProgramBuilder& b) {
2112+
void negPowRx(QCOProgramBuilder& b) {
21132113
auto q = b.allocQubitRegister(1);
21142114
b.pow({q[0]}, -2.0, [&](mlir::ValueRange qubits) {
2115-
auto q0 = b.s(qubits[0]);
2115+
auto q0 = b.rx(0.123, qubits[0]);
21162116
return llvm::SmallVector<mlir::Value>{q0};
21172117
});
21182118
}
21192119

2120-
void invPowS(QCOProgramBuilder& b) {
2120+
void invPowRx(QCOProgramBuilder& b) {
21212121
auto q = b.allocQubitRegister(1);
21222122
b.inv({q[0]}, [&](mlir::ValueRange invArgs) {
21232123
auto inner = b.pow({invArgs[0]}, 2.0, [&](mlir::ValueRange powArgs) {
2124-
auto q0 = b.s(powArgs[0]);
2124+
auto q0 = b.rx(0.123, powArgs[0]);
21252125
return llvm::SmallVector<mlir::Value>{q0};
21262126
});
21272127
return llvm::SmallVector<mlir::Value>{inner};
21282128
});
21292129
}
21302130

2131-
void powSdg(QCOProgramBuilder& b) {
2131+
void powRxNeg(QCOProgramBuilder& b) {
21322132
auto q = b.allocQubitRegister(1);
21332133
b.pow({q[0]}, 2.0, [&](mlir::ValueRange qubits) {
2134-
auto q0 = b.sdg(qubits[0]);
2134+
auto q0 = b.rx(-0.123, qubits[0]);
21352135
return llvm::SmallVector<mlir::Value>{q0};
21362136
});
21372137
}
21382138

2139+
void powCtrlRx(QCOProgramBuilder& b) {
2140+
auto q = b.allocQubitRegister(2);
2141+
b.pow({q[0], q[1]}, 2.0, [&](mlir::ValueRange powArgs) {
2142+
const auto& [controlsOut, targetsOut] =
2143+
b.ctrl({powArgs[0]}, {powArgs[1]}, [&](mlir::ValueRange targets) {
2144+
return llvm::SmallVector<mlir::Value>{b.rx(0.123, targets[0])};
2145+
});
2146+
return llvm::to_vector(llvm::concat<mlir::Value>(controlsOut, targetsOut));
2147+
});
2148+
}
2149+
2150+
void ctrlPowRx(QCOProgramBuilder& b) {
2151+
auto q = b.allocQubitRegister(2);
2152+
b.ctrl({q[0]}, {q[1]}, [&](mlir::ValueRange targets) {
2153+
auto inner = b.pow({targets[0]}, 2.0, [&](mlir::ValueRange powArgs) {
2154+
auto q0 = b.rx(0.123, powArgs[0]);
2155+
return llvm::SmallVector<mlir::Value>{q0};
2156+
});
2157+
return llvm::SmallVector<mlir::Value>{inner};
2158+
});
2159+
}
2160+
21392161
// --- IfOp ---------------------------------------------------------------- //
21402162

21412163
void simpleIf(QCOProgramBuilder& b) {

mlir/unittests/programs/qco_programs.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,24 @@ void powSingleExponent(QCOProgramBuilder& b);
980980
/// Creates a circuit with pow(2.0) wrapping a two-qubit RXX gate.
981981
void powRxx(QCOProgramBuilder& b);
982982

983-
/// Creates a circuit with pow(-2.0) wrapping an S gate (negative exponent).
984-
void negPowS(QCOProgramBuilder& b);
983+
/// Creates a circuit with pow(-2.0) wrapping an RX gate (negative exponent).
984+
void negPowRx(QCOProgramBuilder& b);
985985

986986
/// Creates a circuit with inv wrapping pow (should reorder to pow wrapping
987987
/// inv).
988-
void invPowS(QCOProgramBuilder& b);
988+
void invPowRx(QCOProgramBuilder& b);
989989

990-
/// Creates a circuit with pow(2.0) wrapping sdg (reference for invPowS).
991-
void powSdg(QCOProgramBuilder& b);
990+
/// Creates a circuit with pow(2.0) wrapping RX(-0.123) (reference for
991+
/// negPowRx and invPowRx — inv folds into angle negation).
992+
void powRxNeg(QCOProgramBuilder& b);
993+
994+
/// Creates a circuit with pow wrapping ctrl wrapping RX (should move ctrl
995+
/// outside).
996+
void powCtrlRx(QCOProgramBuilder& b);
997+
998+
/// Creates a circuit with ctrl wrapping pow wrapping RX (reference for
999+
/// powCtrlRx).
1000+
void ctrlPowRx(QCOProgramBuilder& b);
9921001

9931002
// --- IfOp ---------------------------------------------------------------- //
9941003

0 commit comments

Comments
 (0)