From fddee2546f5159a9acce59f4bedd3b0ecda30f1e Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 3 Oct 2023 10:51:41 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix=20a=20potential=20divisi?= =?UTF-8?q?on=20by=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- .../dd/applicationscheme/ProportionalApplicationScheme.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp index 848f2ed8..b753d61d 100644 --- a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp @@ -25,6 +25,9 @@ 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)); } From 1339dda0fea5634cfac7d311d3565728fb53e6da Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 3 Oct 2023 11:15:02 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9A=A1=20add=20shortcut=20if=20both=20ci?= =?UTF-8?q?rcuits=20are=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/EquivalenceCheckingManager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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 || From 0eb9011a04c171416d525564823f14a1656b1370 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 3 Oct 2023 11:15:29 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85=20add=20tests=20for=20corner=20ca?= =?UTF-8?q?ses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- test/test_equality.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) 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); +} From c15ca995c2688448829902141d18bade04ae8e16 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 3 Oct 2023 11:31:00 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=9A=A8=20remove=20const=20qualificati?= =?UTF-8?q?on=20from=20`gateRatio`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- .../dd/applicationscheme/ProportionalApplicationScheme.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp index b753d61d..31d6cc59 100644 --- a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp @@ -32,6 +32,6 @@ class ProportionalApplicationScheme final static_cast(1U)); } - const std::size_t gateRatio; + std::size_t gateRatio; }; } // namespace ec