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 7b66358c..2f64edc4 100644 --- a/include/checker/dd/TaskManager.hpp +++ b/include/checker/dd/TaskManager.hpp @@ -15,12 +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), 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, + 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, DDPackage& dd) noexcept : TaskManager(circ, dd, Direction::Left) {} [[nodiscard]] bool finished() const noexcept { return iterator == end; } @@ -126,7 +126,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; 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..39772e59 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; } @@ -50,17 +50,17 @@ 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(); + this->taskManager1->advanceIterator(); } else { - assert(!this->taskManager2.finished()); + 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; } 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);