diff --git a/include/checker/dd/DDAlternatingChecker.hpp b/include/checker/dd/DDAlternatingChecker.hpp index 8d71cbed..74652292 100644 --- a/include/checker/dd/DDAlternatingChecker.hpp +++ b/include/checker/dd/DDAlternatingChecker.hpp @@ -48,11 +48,6 @@ class DDAlternatingChecker final private: qc::MatrixDD functionality{}; - void initializeTask( - [[maybe_unused]] TaskManager& - taskManager) override{ - // task initialization is conducted separately for this checker - }; void initialize() override; void execute() override; void finish() override; diff --git a/include/checker/dd/DDConstructionChecker.hpp b/include/checker/dd/DDConstructionChecker.hpp index a5df34fd..10437fb9 100644 --- a/include/checker/dd/DDConstructionChecker.hpp +++ b/include/checker/dd/DDConstructionChecker.hpp @@ -30,6 +30,7 @@ class DDConstructionChecker final private: void initializeTask(TaskManager& taskManager) override { + DDEquivalenceChecker::initializeTask(taskManager); const auto initial = dd->makeIdent(nqubits); taskManager.setInternalState(initial); taskManager.incRef(); diff --git a/include/checker/dd/DDEquivalenceChecker.hpp b/include/checker/dd/DDEquivalenceChecker.hpp index 59545af6..11579893 100644 --- a/include/checker/dd/DDEquivalenceChecker.hpp +++ b/include/checker/dd/DDEquivalenceChecker.hpp @@ -52,7 +52,7 @@ class DDEquivalenceChecker : public EquivalenceChecker { // in some form EquivalenceCriterion equals(const DDType& e, const DDType& f); - virtual void initializeTask(TaskManager& taskManager) = 0; + virtual void initializeTask(TaskManager& taskManager); virtual void initialize(); virtual void execute(); virtual void finish(); diff --git a/include/checker/dd/TaskManager.hpp b/include/checker/dd/TaskManager.hpp index 2f64edc4..631a61e2 100644 --- a/include/checker/dd/TaskManager.hpp +++ b/include/checker/dd/TaskManager.hpp @@ -23,6 +23,11 @@ template class TaskManager { TaskManager(const qc::QuantumComputation& circ, DDPackage& dd) noexcept : TaskManager(circ, dd, Direction::Left) {} + void reset() noexcept { + iterator = qc->begin(); + permutation = qc->initialLayout; + } + [[nodiscard]] bool finished() const noexcept { return iterator == end; } const std::unique_ptr& operator()() const { return *iterator; } diff --git a/src/checker/dd/DDEquivalenceChecker.cpp b/src/checker/dd/DDEquivalenceChecker.cpp index 4f26ffe0..1efdfda9 100644 --- a/src/checker/dd/DDEquivalenceChecker.cpp +++ b/src/checker/dd/DDEquivalenceChecker.cpp @@ -143,6 +143,12 @@ EquivalenceCriterion DDEquivalenceChecker::run() { return equivalence; } +template +void DDEquivalenceChecker::initializeTask( + TaskManager& taskManager) { + taskManager.reset(); +} + template void DDEquivalenceChecker::initialize() { initializeTask(taskManager1); diff --git a/src/checker/dd/DDSimulationChecker.cpp b/src/checker/dd/DDSimulationChecker.cpp index daaefd95..7a7f97d2 100644 --- a/src/checker/dd/DDSimulationChecker.cpp +++ b/src/checker/dd/DDSimulationChecker.cpp @@ -16,6 +16,7 @@ DDSimulationChecker::DDSimulationChecker(const qc::QuantumComputation& circ1, void DDSimulationChecker::initializeTask( TaskManager& taskManager) { + DDEquivalenceChecker::initializeTask(taskManager); taskManager.setInternalState(initialState); taskManager.incRef(); } diff --git a/test/test_equality.cpp b/test/test_equality.cpp index 7cf2b3e4..158f8afe 100644 --- a/test/test_equality.cpp +++ b/test/test_equality.cpp @@ -48,6 +48,32 @@ TEST_F(EqualityTest, GlobalPhase) { ec::EquivalenceCriterion::EquivalentUpToGlobalPhase); } +/** + * @brief The following is a regression test for + * https://github.com/cda-tum/mqt-qcec/issues/347 + */ +TEST_F(EqualityTest, GlobalPhaseSimulation) { + qc1.x(0); + qc2.x(0); + + // add a global phase of -1 + qc2.z(0); + qc2.x(0); + qc2.z(0); + qc2.x(0); + + config.execution.runAlternatingChecker = false; + config.execution.runConstructionChecker = false; + config.execution.runZXChecker = false; + config.execution.runSimulationChecker = true; + config.execution.parallel = false; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.run(); + const auto json = ecm.json(); + const auto simChecker = json["checkers"].front(); + EXPECT_EQ(simChecker["equivalence"], "equivalent_up_to_phase"); +} + TEST_F(EqualityTest, CloseButNotEqualAlternating) { qc1.x(0);