Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Properly reset task managers #348

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions include/checker/dd/DDAlternatingChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ class DDAlternatingChecker final
private:
qc::MatrixDD functionality{};

void initializeTask(
[[maybe_unused]] TaskManager<qc::MatrixDD, AlternatingDDPackageConfig>&
taskManager) override{
// task initialization is conducted separately for this checker
};
void initialize() override;
void execute() override;
void finish() override;
Expand Down
1 change: 1 addition & 0 deletions include/checker/dd/DDConstructionChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DDConstructionChecker final
private:
void initializeTask(TaskManager<qc::MatrixDD, ConstructionDDPackageConfig>&
taskManager) override {
DDEquivalenceChecker::initializeTask(taskManager);
const auto initial = dd->makeIdent(nqubits);
taskManager.setInternalState(initial);
taskManager.incRef();
Expand Down
2 changes: 1 addition & 1 deletion include/checker/dd/DDEquivalenceChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DDEquivalenceChecker : public EquivalenceChecker {
// in some form
EquivalenceCriterion equals(const DDType& e, const DDType& f);

virtual void initializeTask(TaskManager<DDType, Config>& taskManager) = 0;
virtual void initializeTask(TaskManager<DDType, Config>& taskManager);
virtual void initialize();
virtual void execute();
virtual void finish();
Expand Down
5 changes: 5 additions & 0 deletions include/checker/dd/TaskManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ template <class DDType, class Config = dd::DDPackageConfig> 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<qc::Operation>& operator()() const { return *iterator; }
Expand Down
6 changes: 6 additions & 0 deletions src/checker/dd/DDEquivalenceChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ EquivalenceCriterion DDEquivalenceChecker<DDType, Config>::run() {
return equivalence;
}

template <class DDType, class Config>
void DDEquivalenceChecker<DDType, Config>::initializeTask(
TaskManager<DDType, Config>& taskManager) {
taskManager.reset();
}

template <class DDType, class Config>
void DDEquivalenceChecker<DDType, Config>::initialize() {
initializeTask(taskManager1);
Expand Down
1 change: 1 addition & 0 deletions src/checker/dd/DDSimulationChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DDSimulationChecker::DDSimulationChecker(const qc::QuantumComputation& circ1,

void DDSimulationChecker::initializeTask(
TaskManager<qc::VectorDD, SimulationDDPackageConfig>& taskManager) {
DDEquivalenceChecker::initializeTask(taskManager);
taskManager.setInternalState(initialState);
taskManager.incRef();
}
Expand Down
26 changes: 26 additions & 0 deletions test/test_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down