diff --git a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp index 848f2ed8..31d6cc59 100644 --- a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp @@ -25,10 +25,13 @@ class ProportionalApplicationScheme final [[nodiscard]] std::size_t computeGateRatio() const noexcept { const std::size_t size1 = this->taskManager1.getCircuit()->size(); const std::size_t size2 = this->taskManager2.getCircuit()->size(); + if (size1 == 0U) { + return size2; + } return std::max((size2 + (size1 / 2U)) / size1, static_cast(1U)); } - const std::size_t gateRatio; + std::size_t gateRatio; }; } // namespace ec diff --git a/src/EquivalenceCheckingManager.cpp b/src/EquivalenceCheckingManager.cpp index ef25e53e..55ac7fcb 100644 --- a/src/EquivalenceCheckingManager.cpp +++ b/src/EquivalenceCheckingManager.cpp @@ -157,6 +157,12 @@ void EquivalenceCheckingManager::run() { return; } + if (qc1.empty() && qc2.empty()) { + results.equivalence = EquivalenceCriterion::Equivalent; + done = true; + return; + } + if (qc1.isVariableFree() && qc2.isVariableFree()) { if (!configuration.execution.parallel || configuration.execution.nthreads <= 1 || diff --git a/test/test_equality.cpp b/test/test_equality.cpp index 28a82d1f..6f1422ff 100644 --- a/test/test_equality.cpp +++ b/test/test_equality.cpp @@ -179,3 +179,83 @@ TEST_F(EqualityTest, ExceptionInParallelThread) { ec::EquivalenceCheckingManager ecm(qc1, qc1, config); EXPECT_THROW(ecm.run(), std::invalid_argument); } + +TEST_F(EqualityTest, BothCircuitsEmptyAlternatingChecker) { + config.execution.runAlternatingChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +} + +TEST_F(EqualityTest, BothCircuitsEmptyConstructionChecker) { + config.execution.runConstructionChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +} + +TEST_F(EqualityTest, BothCircuitsEmptySimulationChecker) { + config.execution.runSimulationChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +} + +TEST_F(EqualityTest, BothCircuitsEmptyZXChecker) { + config.execution.runZXChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +} + +TEST_F(EqualityTest, OneCircuitEmptyAlternatingChecker) { + qc2.h(0); + qc2.x(0); + qc2.h(0); + qc2.z(0); + config.execution.runAlternatingChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +} + +TEST_F(EqualityTest, OneCircuitEmptyConstructionChecker) { + qc2.h(0); + qc2.x(0); + qc2.h(0); + qc2.z(0); + config.execution.runConstructionChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +} + +TEST_F(EqualityTest, OneCircuitEmptySimulationChecker) { + qc2.h(0); + qc2.x(0); + qc2.h(0); + qc2.z(0); + config.execution.runSimulationChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::ProbablyEquivalent); +} + +TEST_F(EqualityTest, OneCircuitEmptyZXChecker) { + qc2.h(0); + qc2.x(0); + qc2.h(0); + qc2.z(0); + config.execution.runZXChecker = true; + ec::EquivalenceCheckingManager ecm(qc1, qc2, config); + ecm.setApplicationScheme(ec::ApplicationSchemeType::Proportional); + ecm.run(); + EXPECT_EQ(ecm.equivalence(), ec::EquivalenceCriterion::Equivalent); +}