Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
- ✨ Add conversions between `jeff` and QCO ([#1479], [#1548], [#1565], [#1637], [#1676], [#1706]) ([**@denialhaag**], [**@burgholzer**])
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588], [#1600], [#1664], [#1709], [#1716], [#1748]) ([**@MatthiasReumann**], [**@burgholzer**])
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1717], [#1728], [#1730])
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1717], [#1728], [#1730], [#1749])
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])

### Changed
Expand Down Expand Up @@ -402,6 +402,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool

<!-- PR links -->

[#1749]: https://github.com/munich-quantum-toolkit/core/pull/1749
[#1748]: https://github.com/munich-quantum-toolkit/core/pull/1748
[#1737]: https://github.com/munich-quantum-toolkit/core/pull/1737
[#1730]: https://github.com/munich-quantum-toolkit/core/pull/1730
Expand Down
17 changes: 8 additions & 9 deletions mlir/lib/Conversion/QCToQCO/QCToQCO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,7 @@ static void extractQubitsAfterOp(LoweringState& state, Operation* target,
*/
static std::pair<SetVector<Value>, SetVector<Value>>
collectQubitValuesInsideSCFOps(Operation* op, LoweringState* state) {
// Get the regions of the current operation
const auto& regions = op->getRegions();
auto& regionQubitMap = state->regionQubitMap[op];
auto& regionRegisterMap = state->regionRegisterMap[op];

for (auto& region : regions) {
auto& qubitInfoMap = state->qubitInfoMap[&region];
for (auto& region : op->getRegions()) {
// Skip empty regions e.g. empty else region of an If operation
if (region.empty()) {
continue;
Expand All @@ -534,12 +528,16 @@ collectQubitValuesInsideSCFOps(Operation* op, LoweringState* state) {
if (operation.getNumRegions() > 0) {
auto [qubits, registers] =
collectQubitValuesInsideSCFOps(&operation, state);
auto& regionQubitMap = state->regionQubitMap[op];
auto& qubitInfoMap = state->qubitInfoMap[&region];
regionQubitMap.set_union(qubits);
// Remove duplicate qubits
regionQubitMap.remove_if(
[&](Value qubit) { return qubitInfoMap.contains(qubit); });
regionRegisterMap.set_union(registers);
state->regionRegisterMap[op].set_union(registers);
}
auto& qubitInfoMap = state->qubitInfoMap[&region];
auto& regionRegisterMap = state->regionRegisterMap[op];
// Track qubits from loadOp
if (auto loadOp = dyn_cast<memref::LoadOp>(operation)) {
QubitInfo info{.reg = loadOp.getMemRef(),
Expand All @@ -548,6 +546,7 @@ collectQubitValuesInsideSCFOps(Operation* op, LoweringState* state) {
regionRegisterMap.insert(loadOp.getMemRef());
continue;
}
auto& regionQubitMap = state->regionQubitMap[op];
// Add the QC qubit and memref operands to the maps
for (const auto& operand : operation.getOperands()) {
if (isa<qc::QubitType>(operand.getType())) {
Expand All @@ -564,7 +563,7 @@ collectQubitValuesInsideSCFOps(Operation* op, LoweringState* state) {
}
}

return {regionQubitMap, regionRegisterMap};
return {state->regionQubitMap[op], state->regionRegisterMap[op]};
}

namespace {
Expand Down
9 changes: 6 additions & 3 deletions mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,13 @@ INSTANTIATE_TEST_SUITE_P(
QCOToQCTestCase{"SingleControlledX",
MQT_NAMED_BUILDER(qco::singleControlledX),
MQT_NAMED_BUILDER(qc::singleControlledX)},
QCOToQCTestCase{"MultipleControlledX",
MQT_NAMED_BUILDER(qco::multipleControlledX),
MQT_NAMED_BUILDER(qc::multipleControlledX)},
QCOToQCTestCase{
"MultipleControlledX",
MQT_NAMED_BUILDER(qco::multipleControlledX),
MQT_NAMED_BUILDER(qc::multipleControlledX)}));
"RepeatedControlledX",
MQT_NAMED_BUILDER(qco::repeatedControlledX),
MQT_NAMED_BUILDER(qc::repeatedControlledX)}));
/// @}

/// \name QCOToQC/Operations/StandardGates/XxMinusYyOp.cpp
Expand Down
20 changes: 12 additions & 8 deletions mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,19 @@ INSTANTIATE_TEST_SUITE_P(
/// @{
INSTANTIATE_TEST_SUITE_P(
QCXOpTest, QCToQCOTest,
testing::Values(QCToQCOTestCase{"X", MQT_NAMED_BUILDER(qc::x),
MQT_NAMED_BUILDER(qco::x)},
QCToQCOTestCase{"SingleControlledX",
MQT_NAMED_BUILDER(qc::singleControlledX),
MQT_NAMED_BUILDER(qco::singleControlledX)},
QCToQCOTestCase{
"MultipleControlledX",
testing::Values(
QCToQCOTestCase{"X", MQT_NAMED_BUILDER(qc::x),
MQT_NAMED_BUILDER(qco::x)},
QCToQCOTestCase{"SingleControlledX",
MQT_NAMED_BUILDER(qc::singleControlledX),
MQT_NAMED_BUILDER(qco::singleControlledX)},
QCToQCOTestCase{"MultipleControlledX",
MQT_NAMED_BUILDER(qc::multipleControlledX),
MQT_NAMED_BUILDER(qco::multipleControlledX)}));
MQT_NAMED_BUILDER(qco::multipleControlledX)},
QCToQCOTestCase{"RepeatedControlledX",
MQT_NAMED_BUILDER(qc::repeatedControlledX),
MQT_NAMED_BUILDER(qco::repeatedControlledX)}));

/// @}

/// \name QCToQCO/Operations/StandardGates/XxMinusYyOp.cpp
Expand Down
9 changes: 9 additions & 0 deletions mlir/unittests/programs/qc_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ void trivialControlledX(QCProgramBuilder& b) {
b.mcx({}, q[0]);
}

void repeatedControlledX(QCProgramBuilder& b) {
auto control = b.allocQubit();
b.h(control);
for (auto i = 0; i < 50; i++) {
auto qubit = b.allocQubit();
b.mcx(control, qubit);
}
}

Comment thread
burgholzer marked this conversation as resolved.
void inverseX(QCProgramBuilder& b) {
auto q = b.allocQubitRegister(1);
b.inv([&]() { b.x(q[0]); });
Expand Down
3 changes: 3 additions & 0 deletions mlir/unittests/programs/qc_programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ void nestedControlledX(QCProgramBuilder& b);
/// Creates a circuit with a trivial controlled X gate.
void trivialControlledX(QCProgramBuilder& b);

/// Creates a circuit with repeated controlled X gates.
void repeatedControlledX(QCProgramBuilder& b);

/// Creates a circuit with an inverse modifier applied to an X gate.
void inverseX(QCProgramBuilder& b);

Expand Down
9 changes: 9 additions & 0 deletions mlir/unittests/programs/qco_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ void trivialControlledX(QCOProgramBuilder& b) {
b.mcx({}, q[0]);
}

void repeatedControlledX(QCOProgramBuilder& b) {
auto q0 = b.allocQubit();
auto control = b.h(q0);
for (auto i = 0; i < 50; i++) {
auto qubit = b.allocQubit();
control = b.mcx(control, qubit).first[0];
}
}

void inverseX(QCOProgramBuilder& b) {
auto q = b.allocQubitRegister(1);
b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.x(qubits[0])}; });
Expand Down
3 changes: 3 additions & 0 deletions mlir/unittests/programs/qco_programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ void nestedControlledX(QCOProgramBuilder& b);
/// Creates a circuit with a trivial controlled X gate.
void trivialControlledX(QCOProgramBuilder& b);

/// Creates a circuit with repeated controlled X gates.
void repeatedControlledX(QCOProgramBuilder& b);

/// Creates a circuit with an inverse modifier applied to an X gate.
void inverseX(QCOProgramBuilder& b);

Expand Down
Loading