From 830daf21e76549174168f8102bff407b5fb70d7f Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 5 Jan 2024 14:06:27 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=9A=A8=20change=20reference=20member?= =?UTF-8?q?=20to=20pointer=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- include/checker/dd/TaskManager.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/checker/dd/TaskManager.hpp b/include/checker/dd/TaskManager.hpp index 7b66358c..a7a82cd5 100644 --- a/include/checker/dd/TaskManager.hpp +++ b/include/checker/dd/TaskManager.hpp @@ -17,8 +17,9 @@ template class TaskManager { public: TaskManager(const qc::QuantumComputation& circ, std::unique_ptr& dd, const ec::Direction& dir) noexcept - : qc(&circ), package(dd), direction(dir), permutation(circ.initialLayout), - iterator(circ.begin()), end(circ.end()) {} + : qc(&circ), package(dd.get()), direction(dir), + permutation(circ.initialLayout), iterator(circ.begin()), + end(circ.end()) {} TaskManager(const qc::QuantumComputation& circ, std::unique_ptr& dd) noexcept : TaskManager(circ, dd, Direction::Left) {} @@ -126,7 +127,7 @@ template class TaskManager { private: const qc::QuantumComputation* qc{}; - std::unique_ptr& package; + DDPackage* package; ec::Direction direction = Direction::Left; qc::Permutation permutation{}; decltype(qc->begin()) iterator; From bec240449ce9115fff7a919a894e5b9a0d251534 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 5 Jan 2024 14:14:19 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=9A=B8=20improve=20TaskManager=20inte?= =?UTF-8?q?rface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- include/checker/dd/DDEquivalenceChecker.hpp | 4 ++-- include/checker/dd/TaskManager.hpp | 9 ++++----- test/test_gate_cost_application_scheme.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/checker/dd/DDEquivalenceChecker.hpp b/include/checker/dd/DDEquivalenceChecker.hpp index 9b9b4122..59545af6 100644 --- a/include/checker/dd/DDEquivalenceChecker.hpp +++ b/include/checker/dd/DDEquivalenceChecker.hpp @@ -24,8 +24,8 @@ class DDEquivalenceChecker : public EquivalenceChecker { Configuration config) : EquivalenceChecker(circ1, circ2, std::move(config)), dd(std::make_unique>(nqubits)), - taskManager1(TaskManager(circ1, dd)), - taskManager2(TaskManager(circ2, dd)) {} + taskManager1(TaskManager(circ1, *dd)), + taskManager2(TaskManager(circ2, *dd)) {} EquivalenceCriterion run() override; diff --git a/include/checker/dd/TaskManager.hpp b/include/checker/dd/TaskManager.hpp index a7a82cd5..2f64edc4 100644 --- a/include/checker/dd/TaskManager.hpp +++ b/include/checker/dd/TaskManager.hpp @@ -15,13 +15,12 @@ template class TaskManager { using DDPackage = typename dd::Package; public: - TaskManager(const qc::QuantumComputation& circ, - std::unique_ptr& dd, const ec::Direction& dir) noexcept - : qc(&circ), package(dd.get()), direction(dir), + TaskManager(const qc::QuantumComputation& circ, DDPackage& dd, + const ec::Direction& dir) noexcept + : qc(&circ), package(&dd), direction(dir), permutation(circ.initialLayout), iterator(circ.begin()), end(circ.end()) {} - TaskManager(const qc::QuantumComputation& circ, - std::unique_ptr& dd) noexcept + TaskManager(const qc::QuantumComputation& circ, DDPackage& dd) noexcept : TaskManager(circ, dd, Direction::Left) {} [[nodiscard]] bool finished() const noexcept { return iterator == end; } diff --git a/test/test_gate_cost_application_scheme.cpp b/test/test_gate_cost_application_scheme.cpp index 8ffacabc..d8420637 100644 --- a/test/test_gate_cost_application_scheme.cpp +++ b/test/test_gate_cost_application_scheme.cpp @@ -37,7 +37,7 @@ TEST_F(GateCostApplicationSchemeTest, SchemeFromProfile) { // apply Toffoli gate qc.mcx({1_pc, 2_pc}, 0); - auto tm = ec::TaskManager(qc, dd); + auto tm = ec::TaskManager(qc, *dd); auto scheme = ec::GateCostApplicationScheme(tm, tm, filename); @@ -52,13 +52,13 @@ TEST_F(GateCostApplicationSchemeTest, SchemeFromProfile) { ec::EquivalenceCheckingManager ecm(qc, qc, config); ecm.run(); EXPECT_TRUE(ecm.getResults().consideredEquivalent()); - std::cout << ecm.toString() << std::endl; + std::cout << ecm.toString() << "\n"; } TEST_F(GateCostApplicationSchemeTest, iSWAP) { qc.iswap(0, 1); - auto tm = ec::TaskManager(qc, dd); + auto tm = ec::TaskManager(qc, *dd); auto scheme = ec::GateCostApplicationScheme(tm, tm, &ec::legacyCostFunction); @@ -73,7 +73,7 @@ TEST_F(GateCostApplicationSchemeTest, Peres) { qc.cperes(0_pc, 1, 2); - auto tm = ec::TaskManager(qc, dd); + auto tm = ec::TaskManager(qc, *dd); auto scheme = ec::GateCostApplicationScheme(tm, tm, &ec::legacyCostFunction); From c18ddf48726ace623d4168c4a215acab4f7dbc04 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 5 Jan 2024 14:22:06 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=9A=A8=20change=20reference=20members?= =?UTF-8?q?=20to=20pointer=20type=20in=20`ApplicationScheme`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- .../checker/dd/applicationscheme/ApplicationScheme.hpp | 6 +++--- .../dd/applicationscheme/GateCostApplicationScheme.hpp | 2 +- .../dd/applicationscheme/LookaheadApplicationScheme.hpp | 8 ++++---- .../applicationscheme/ProportionalApplicationScheme.hpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/checker/dd/applicationscheme/ApplicationScheme.hpp b/include/checker/dd/applicationscheme/ApplicationScheme.hpp index c45f9829..fb92cdd6 100644 --- a/include/checker/dd/applicationscheme/ApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/ApplicationScheme.hpp @@ -92,7 +92,7 @@ template class ApplicationScheme { public: ApplicationScheme(TM& tm1, TM& tm2) noexcept - : taskManager1(tm1), taskManager2(tm2){}; + : taskManager1(&tm1), taskManager2(&tm2){}; virtual ~ApplicationScheme() = default; @@ -100,8 +100,8 @@ template class ApplicationScheme { virtual std::pair operator()() = 0; protected: - TM& taskManager1; - TM& taskManager2; + TM* taskManager1; + TM* taskManager2; }; } // namespace ec diff --git a/include/checker/dd/applicationscheme/GateCostApplicationScheme.hpp b/include/checker/dd/applicationscheme/GateCostApplicationScheme.hpp index e9c8d9bc..b1d23670 100644 --- a/include/checker/dd/applicationscheme/GateCostApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/GateCostApplicationScheme.hpp @@ -56,7 +56,7 @@ class GateCostApplicationScheme final return {1U, 1U}; } - const auto& op = this->taskManager1(); + const auto& op = (*this->taskManager1)(); const auto key = GateCostLookupTableKeyType{op->getType(), op->getNcontrols()}; std::size_t cost = 1U; diff --git a/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp b/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp index 7bcf3352..eb37f8da 100644 --- a/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp @@ -30,14 +30,14 @@ class LookaheadApplicationScheme final if (!cached1) { // cache the current operation - op1 = this->taskManager1.getDD(); + op1 = this->taskManager1->getDD(); package->incRef(op1); cached1 = true; } if (!cached2) { // cache the current operation - op2 = this->taskManager2.getInverseDD(); + op2 = this->taskManager2->getInverseDD(); package->incRef(op2); cached2 = true; } @@ -54,13 +54,13 @@ class LookaheadApplicationScheme final *internalState = dd1; package->decRef(op1); cached1 = false; - this->taskManager1.advanceIterator(); + this->taskManager1->advanceIterator(); } else { assert(!this->taskManager2.finished()); *internalState = dd2; package->decRef(op2); cached2 = false; - this->taskManager2.advanceIterator(); + this->taskManager2->advanceIterator(); } // properly track reference counts diff --git a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp index 31d6cc59..1f20b829 100644 --- a/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/ProportionalApplicationScheme.hpp @@ -23,8 +23,8 @@ class ProportionalApplicationScheme final private: [[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(); + const std::size_t size1 = this->taskManager1->getCircuit()->size(); + const std::size_t size2 = this->taskManager2->getCircuit()->size(); if (size1 == 0U) { return size2; } From b112d7222781ada956ca80362a4ac5ada2a0a059 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 5 Jan 2024 15:20:37 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A9=B9=20fix=20leftover=20code=20snip?= =?UTF-8?q?pets=20in=20assert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- .../dd/applicationscheme/LookaheadApplicationScheme.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp b/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp index eb37f8da..39772e59 100644 --- a/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp +++ b/include/checker/dd/applicationscheme/LookaheadApplicationScheme.hpp @@ -50,13 +50,13 @@ class LookaheadApplicationScheme final // greedily chose the smaller resulting decision diagram if (const auto size2 = dd2.size(); size1 <= size2) { - assert(!this->taskManager1.finished()); + assert(!this->taskManager1->finished()); *internalState = dd1; package->decRef(op1); cached1 = false; this->taskManager1->advanceIterator(); } else { - assert(!this->taskManager2.finished()); + assert(!this->taskManager2->finished()); *internalState = dd2; package->decRef(op2); cached2 = false;