Skip to content

Commit c656bf0

Browse files
⬆️ Update munich-quantum-toolkit/core (#167)
* ⬆️ Update `munich-quantum-toolkit/core` * Update to version 3.3.1 of mqt-core * Adapt code to mqt-core 3.3.1 * Fix linter errors * Raise error for invalid if-else operations --------- Co-authored-by: mqt-app[bot] <219534693+mqt-app[bot]@users.noreply.github.com> Co-authored-by: Daniel Haag <[email protected]>
1 parent b8a4e55 commit c656bf0

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

cmake/ExternalDependencies.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ endif()
2727

2828
# ---------------------------------------------------------------------------------Fetch MQT Core
2929
# cmake-format: off
30-
set(MQT_CORE_MINIMUM_VERSION 3.2.1
30+
set(MQT_CORE_MINIMUM_VERSION 3.3.1
3131
CACHE STRING "MQT Core minimum version")
32-
set(MQT_CORE_VERSION 3.2.1
32+
set(MQT_CORE_VERSION 3.3.1
3333
CACHE STRING "MQT Core version")
34-
set(MQT_CORE_REV "0425f88169f573e4505b49703c4cadf3699ccbcd"
34+
set(MQT_CORE_REV "1392d1b70f7331ea1ebb3247587c62cb8fd1d078"
3535
CACHE STRING "MQT Core identifier (tag, branch or commit hash)")
3636
set(MQT_CORE_REPO_OWNER "munich-quantum-toolkit"
3737
CACHE STRING "MQT Core repository owner (change when using a fork)")

src/backend/dd/DDSimDebug.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "dd/StateGeneration.hpp"
3333
#include "ir/Definitions.hpp"
3434
#include "ir/Register.hpp"
35-
#include "ir/operations/ClassicControlledOperation.hpp"
35+
#include "ir/operations/IfElseOperation.hpp"
3636
#include "ir/operations/OpType.hpp"
3737
#include "qasm3/Importer.hpp"
3838

@@ -838,13 +838,21 @@ Result ddsimStepForward(SimulationState* self) {
838838
ddsim->iterator++;
839839
return OK;
840840
}
841-
if ((*ddsim->iterator)->isClassicControlledOperation()) {
842-
// For classic-controlled operations, we need to read the values of the
843-
// classical register first.
841+
if ((*ddsim->iterator)->isIfElseOperation()) {
842+
// For if-else operations, we need to read the values of the classical
843+
// register first.
844844
const auto* op =
845-
dynamic_cast<qc::ClassicControlledOperation*>((*ddsim->iterator).get());
845+
dynamic_cast<qc::IfElseOperation*>((*ddsim->iterator).get());
846+
if (op->getComparisonKind() != qc::Eq) {
847+
throw std::runtime_error("If-else operations with non-equality "
848+
"comparisons are currently not supported");
849+
}
850+
if (op->getControlBit().has_value()) {
851+
throw std::runtime_error("If-else operations controlled by a single "
852+
"classical bit are currently not supported");
853+
}
846854
const auto& controls = op->getControlRegister();
847-
const auto& exp = op->getExpectedValue();
855+
const auto& exp = op->getExpectedValueRegister();
848856
size_t registerValue = 0;
849857
for (size_t i = 0; i < controls->getSize(); i++) {
850858
const auto name =
@@ -853,7 +861,11 @@ Result ddsimStepForward(SimulationState* self) {
853861
registerValue |= (value ? 1ULL : 0ULL) << i;
854862
}
855863
if (registerValue == exp) {
856-
currDD = dd::getDD(**ddsim->iterator, *ddsim->dd);
864+
auto* thenOp = op->getThenOp();
865+
currDD = dd::getDD(*thenOp, *ddsim->dd);
866+
} else if (op->getElseOp() != nullptr) {
867+
auto* elseOp = op->getElseOp();
868+
currDD = dd::getDD(*elseOp, *ddsim->dd);
857869
} else {
858870
currDD = dd::Package::makeIdent();
859871
}
@@ -915,11 +927,19 @@ Result ddsimStepBackward(SimulationState* self) {
915927
if ((*ddsim->iterator)->getType() == qc::Barrier) {
916928
return OK;
917929
}
918-
if ((*ddsim->iterator)->isClassicControlledOperation()) {
930+
if ((*ddsim->iterator)->isIfElseOperation()) {
919931
const auto* op =
920-
dynamic_cast<qc::ClassicControlledOperation*>((*ddsim->iterator).get());
932+
dynamic_cast<qc::IfElseOperation*>((*ddsim->iterator).get());
933+
if (op->getComparisonKind() != qc::Eq) {
934+
throw std::runtime_error("If-else operations with non-equality "
935+
"comparisons are currently not supported");
936+
}
937+
if (op->getControlBit().has_value()) {
938+
throw std::runtime_error("If-else operations controlled by a single "
939+
"classical bit are currently not supported");
940+
}
921941
const auto& controls = op->getControlRegister();
922-
const auto& exp = op->getExpectedValue();
942+
const auto& exp = op->getExpectedValueRegister();
923943
size_t registerValue = 0;
924944
for (size_t i = 0; i < controls->getSize(); i++) {
925945
const auto name =
@@ -928,7 +948,11 @@ Result ddsimStepBackward(SimulationState* self) {
928948
registerValue |= (value ? 1ULL : 0ULL) << i;
929949
}
930950
if (registerValue == exp) {
931-
currDD = dd::getInverseDD(**ddsim->iterator, *ddsim->dd);
951+
auto* thenOp = op->getThenOp();
952+
currDD = dd::getInverseDD(*thenOp, *ddsim->dd);
953+
} else if (op->getElseOp() != nullptr) {
954+
auto* elseOp = op->getElseOp();
955+
currDD = dd::getInverseDD(*elseOp, *ddsim->dd);
932956
} else {
933957
currDD = dd::Package::makeIdent();
934958
}

test/test_custom_code.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CustomCodeTest : public CustomCodeFixture {};
4141
* @test Test the usage of classically controlled operations where the condition
4242
* evaluates to false.
4343
*/
44-
TEST_F(CustomCodeTest, ClassicControlledOperationFalse) {
44+
TEST_F(CustomCodeTest, IfElseOperationFalse) {
4545
loadCode(2, 1,
4646
"z q[0];"
4747
"cx q[0], q[1];"
@@ -62,7 +62,7 @@ TEST_F(CustomCodeTest, ClassicControlledOperationFalse) {
6262
* @test Test the usage of classically controlled operations where the condition
6363
* evaluates to true.
6464
*/
65-
TEST_F(CustomCodeTest, ClassicControlledOperationTrue) {
65+
TEST_F(CustomCodeTest, IfElseOperationTrue) {
6666
loadCode(2, 1,
6767
"x q[0];"
6868
"cx q[0], q[1];"
@@ -80,10 +80,9 @@ TEST_F(CustomCodeTest, ClassicControlledOperationTrue) {
8080
}
8181

8282
/**
83-
* @test Test the usage of classically controlled operations with multiple
84-
* gates.
83+
* @test Test the usage of if-else operations with multiple gates.
8584
*/
86-
TEST_F(CustomCodeTest, ClassicControlledMultiOperation) {
85+
TEST_F(CustomCodeTest, IfElseOperationMulti) {
8786
loadCode(2, 1,
8887
"x q[0];"
8988
"measure q[0] -> c[0];"

0 commit comments

Comments
 (0)