From b9edb6ec2563a661a105a53211ff10c3fbe36ee8 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sat, 18 Mar 2023 14:35:19 +0100 Subject: [PATCH 01/10] =?UTF-8?q?=F0=9F=A9=B9=20temporary=20fix=20for=20re?= =?UTF-8?q?moved=20string=20->=20opType=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- include/Architecture.hpp | 16 ++++--- src/Architecture.cpp | 93 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 7 deletions(-) diff --git a/include/Architecture.hpp b/include/Architecture.hpp index d00c4d969..829e4dd07 100644 --- a/include/Architecture.hpp +++ b/include/Architecture.hpp @@ -83,14 +83,13 @@ class Architecture { void setSingleQubitErrorRate(std::uint16_t qubit, const std::string& operation, double errorRate) { - singleQubitErrorRate.get(qubit).set(qc::opTypeFromString(operation), + singleQubitErrorRate.get(qubit).set(opTypeFromString(operation), errorRate); } [[nodiscard]] double getSingleQubitErrorRate(std::uint16_t qubit, const std::string& operation) const { - return singleQubitErrorRate.get(qubit).get( - qc::opTypeFromString(operation)); + return singleQubitErrorRate.get(qubit).get(opTypeFromString(operation)); } [[nodiscard]] double getAverageSingleQubitErrorRate(const std::uint16_t qubit) const { @@ -106,14 +105,14 @@ class Architecture { void setTwoQubitErrorRate(std::uint16_t qubit1, std::uint16_t qubit2, double errorRate, const std::string& operation = "cx") { - twoQubitErrorRate.get(qubit1).get(qubit2).set( - qc::opTypeFromString(operation), errorRate); + twoQubitErrorRate.get(qubit1).get(qubit2).set(opTypeFromString(operation), + errorRate); } [[nodiscard]] double getTwoQubitErrorRate(std::uint16_t qubit1, std::uint16_t qubit2, const std::string& operation = "cx") const { return twoQubitErrorRate.get(qubit1).get(qubit2).get( - qc::opTypeFromString(operation)); + opTypeFromString(operation)); } [[nodiscard]] bool twoQubitErrorRateAvailable(std::uint16_t qubit1, std::uint16_t qubit2, @@ -121,7 +120,7 @@ class Architecture { return twoQubitErrorRate.available(qubit1) && twoQubitErrorRate.get(qubit1).available(qubit2) && twoQubitErrorRate.get(qubit1).get(qubit2).available( - qc::opTypeFromString(operation)); + opTypeFromString(operation)); } void clear() { @@ -397,4 +396,7 @@ class Architecture { std::uint16_t node, std::uint16_t curSum, const std::vector>& connections, std::vector& d, std::vector& visited); + + [[nodiscard]] static qc::OpType + opTypeFromString(const std::string& operation); }; diff --git a/src/Architecture.cpp b/src/Architecture.cpp index 89c065d61..511f336cf 100644 --- a/src/Architecture.cpp +++ b/src/Architecture.cpp @@ -691,3 +691,96 @@ void Architecture::printCouplingMap(const CouplingMap& cm, std::ostream& os) { } os << "}" << std::endl; } + +qc::OpType Architecture::opTypeFromString(const std::string& operation) { + if (operation == "i" || operation == "id") { + return qc::OpType::I; + } + if (operation == "h" || operation == "ch") { + return qc::OpType::H; + } + if (operation == "x" || operation == "cx" || operation == "cnot") { + return qc::OpType::X; + } + if (operation == "y" || operation == "cy") { + return qc::OpType::Y; + } + if (operation == "z" || operation == "cz") { + return qc::OpType::Z; + } + if (operation == "s" || operation == "cs") { + return qc::OpType::S; + } + if (operation == "sdg" || operation == "csdg") { + return qc::OpType::Sdag; + } + if (operation == "t" || operation == "ct") { + return qc::OpType::T; + } + if (operation == "tdg" || operation == "ctdg") { + return qc::OpType::Tdag; + } + if (operation == "u3" || operation == "cu3" || operation == "u" || + operation == "cu") { + return qc::OpType::U3; + } + if (operation == "u2" || operation == "cu2") { + return qc::OpType::U2; + } + if (operation == "u1" || operation == "cu1" || operation == "p" || + operation == "cp") { + return qc::OpType::Phase; + } + if (operation == "sx" || operation == "csx") { + return qc::OpType::SX; + } + if (operation == "sxdg" || operation == "csxdg") { + return qc::OpType::SXdag; + } + if (operation == "rx" || operation == "crx") { + return qc::OpType::RX; + } + if (operation == "ry" || operation == "cry") { + return qc::OpType::RY; + } + if (operation == "rz" || operation == "crz") { + return qc::OpType::RZ; + } + if (operation == "swap" || operation == "cswap") { + return qc::OpType::SWAP; + } + if (operation == "iswap") { + return qc::OpType::iSWAP; + } + if (operation == "dcx") { + return qc::OpType::DCX; + } + if (operation == "ecr") { + return qc::OpType::ECR; + } + if (operation == "rxx") { + return qc::OpType::RXX; + } + if (operation == "ryy") { + return qc::OpType::RYY; + } + if (operation == "rzz") { + return qc::OpType::RZZ; + } + if (operation == "rzx") { + return qc::OpType::RZX; + } + if (operation == "xx_minus_yy") { + return qc::OpType::XXminusYY; + } + if (operation == "xx_plus_yy") { + return qc::OpType::XXplusYY; + } + if (operation == "measure") { + return qc::OpType::Measure; + } + if (operation == "reset") { + return qc::OpType::Reset; + } + throw std::invalid_argument("Unsupported operation type: " + operation); +} From e1402861c3497e4a32c3c420109de2c7888df77a Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sat, 18 Mar 2023 14:35:46 +0100 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=A9=B9=20fix=20gate=20construction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- src/exact/ExactMapper.cpp | 3 +-- src/heuristic/HeuristicMapper.cpp | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/exact/ExactMapper.cpp b/src/exact/ExactMapper.cpp index 28fdf9e5d..20bf90f68 100644 --- a/src/exact/ExactMapper.cpp +++ b/src/exact/ExactMapper.cpp @@ -278,8 +278,7 @@ void ExactMapper::map(const Configuration& settings) { qcMapped.emplace_back( qcMapped.getNqubits(), locations.at(gate.target), op->getType(), - op->getParameter().at(0), op->getParameter().at(1), - op->getParameter().at(2)); + op->getParameter()); } else { const Edge cnot = {locations.at(static_cast(gate.control)), locations.at(gate.target)}; diff --git a/src/heuristic/HeuristicMapper.cpp b/src/heuristic/HeuristicMapper.cpp index 4a107a577..a92edacc9 100644 --- a/src/heuristic/HeuristicMapper.cpp +++ b/src/heuristic/HeuristicMapper.cpp @@ -82,15 +82,13 @@ void HeuristicMapper::map(const Configuration& configuration) { if (locations.at(gate.target) == DEFAULT_POSITION) { qcMapped.emplace_back( qcMapped.getNqubits(), gate.target, op->getType(), - op->getParameter().at(0), op->getParameter().at(1), - op->getParameter().at(2)); + op->getParameter()); gatesToAdjust.push_back(gateidx); gateidx++; } else { qcMapped.emplace_back( qcMapped.getNqubits(), locations.at(gate.target), op->getType(), - op->getParameter().at(0), op->getParameter().at(1), - op->getParameter().at(2)); + op->getParameter()); gateidx++; } } else { From 99c20e741df9d59818c1392b9bb7651423687dbb Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sat, 18 Mar 2023 15:21:39 +0100 Subject: [PATCH 03/10] =?UTF-8?q?=E2=9C=A8=20add=20new=20gate=20support=20?= =?UTF-8?q?to=20Clifford=20Tableau=20simulation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- include/cliffordsynthesis/Tableau.hpp | 3 ++ src/cliffordsynthesis/Tableau.cpp | 44 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/cliffordsynthesis/Tableau.hpp b/include/cliffordsynthesis/Tableau.hpp index cce0e5b4d..6e304cb49 100644 --- a/include/cliffordsynthesis/Tableau.hpp +++ b/include/cliffordsynthesis/Tableau.hpp @@ -87,6 +87,9 @@ class Tableau { void applyCY(std::size_t control, std::size_t target); void applyCZ(std::size_t control, std::size_t target); void applySwap(std::size_t q1, std::size_t q2); + void applyISwap(std::size_t q1, std::size_t q2); + void applyDCX(std::size_t q1, std::size_t q2); + void applyECR(std::size_t q1, std::size_t q2); [[gnu::pure]] friend bool operator==(const Tableau& lhs, const Tableau& rhs) { return lhs.tableau == rhs.tableau; diff --git a/src/cliffordsynthesis/Tableau.cpp b/src/cliffordsynthesis/Tableau.cpp index fd866534d..533b48692 100644 --- a/src/cliffordsynthesis/Tableau.cpp +++ b/src/cliffordsynthesis/Tableau.cpp @@ -88,6 +88,21 @@ void Tableau::applyGate(const qc::Operation* const gate) { applySwap(target, target2); break; } + case qc::OpType::iSWAP: { + const auto target2 = static_cast(gate->getTargets().at(1U)); + applyISwap(target, target2); + break; + } + case qc::OpType::DCX: { + const auto target2 = static_cast(gate->getTargets().at(1U)); + applyDCX(target, target2); + break; + } + case qc::OpType::ECR: { + const auto target2 = static_cast(gate->getTargets().at(1U)); + applyECR(target, target2); + break; + } default: // unsupported non-controlled gate type util::fatal("Tableau::applyGate: Unsupported non-controlled gate type " + @@ -295,6 +310,35 @@ void Tableau::applySwap(const std::size_t q1, const std::size_t q2) { applyCX(q1, q2); } +void Tableau::applyISwap(const std::size_t q1, const std::size_t q2) { + assert(q1 < nQubits); + assert(q2 < nQubits); + assert(q1 != q2); + applyS(q2); + applyS(q1); + applyH(q1); + applyDCX(q1, q2); + applyH(q2); +} + +void Tableau::applyDCX(const std::size_t q1, const std::size_t q2) { + assert(q1 < nQubits); + assert(q2 < nQubits); + assert(q1 != q2); + applyCX(q1, q2); + applyCX(q2, q1); +} + +void Tableau::applyECR(const std::size_t q1, const std::size_t q2) { + assert(q1 < nQubits); + assert(q2 < nQubits); + assert(q1 != q2); + applyS(q1); + applySx(q2); + applyCX(q1, q2); + applyX(q1); +} + Tableau::Tableau(const qc::QuantumComputation& qc, const std::size_t begin, const std::size_t end) : Tableau(qc.getNqubits()) { From f5aa64c1e6e7011f0352dc0e3584fd9d2461ffe4 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sat, 18 Mar 2023 15:28:33 +0100 Subject: [PATCH 04/10] =?UTF-8?q?=E2=9C=85=20add=20new=20gates=20to=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- test/test_tableau.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_tableau.cpp b/test/test_tableau.cpp index 963c06d00..474962255 100644 --- a/test/test_tableau.cpp +++ b/test/test_tableau.cpp @@ -243,6 +243,9 @@ TEST_F(TestTableau, CircuitTranslation) { qc.y(1, 0_pc); qc.z(1, 0_pc); qc.swap(0, 1); + qc.iswap(0, 1); + qc.dcx(0, 1); + qc.ecr(0, 1); auto compOP = std::make_unique(2U); compOP->emplace_back(2U, 0, qc::H); From b7b44829795c31e3bb585ec84b8f889476526662 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sat, 18 Mar 2023 15:30:07 +0100 Subject: [PATCH 05/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20update=20QFR=20versi?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adds new gate support and better QASM parser Signed-off-by: Lukas Burgholzer --- extern/qfr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/qfr b/extern/qfr index 6fc0527e0..94229bf0f 160000 --- a/extern/qfr +++ b/extern/qfr @@ -1 +1 @@ -Subproject commit 6fc0527e0a68805462e6a920f7425a33bb9ba191 +Subproject commit 94229bf0f6ff70aae4f4036741f74a5f3a9bd0e5 From 71336b4dd5e91357a9a7c3e20b5b50e9d7c747ae Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sun, 19 Mar 2023 11:14:12 +0100 Subject: [PATCH 06/10] =?UTF-8?q?=F0=9F=A9=B9=20provide=20input=20and=20ou?= =?UTF-8?q?tput=20stream=20support=20for=20`Encoding`=20and=20`CommanderGr?= =?UTF-8?q?ouping`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- include/configuration/CommanderGrouping.hpp | 20 ++++++++++++++++---- include/configuration/Encoding.hpp | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/configuration/CommanderGrouping.hpp b/include/configuration/CommanderGrouping.hpp index 903468e16..c346f83d4 100644 --- a/include/configuration/CommanderGrouping.hpp +++ b/include/configuration/CommanderGrouping.hpp @@ -10,8 +10,7 @@ enum class CommanderGrouping { Halves, Fixed2, Fixed3, Logarithm }; -[[maybe_unused]] static inline std::string -toString(const CommanderGrouping grouping) { +static inline std::string toString(const CommanderGrouping grouping) { switch (grouping) { case CommanderGrouping::Fixed2: return "fixed2"; @@ -25,8 +24,7 @@ toString(const CommanderGrouping grouping) { return " "; } -[[maybe_unused]] static CommanderGrouping -groupingFromString(const std::string& grouping) { +static CommanderGrouping groupingFromString(const std::string& grouping) { if (grouping == "halves" || grouping == "0") { return CommanderGrouping::Halves; } @@ -41,3 +39,17 @@ groupingFromString(const std::string& grouping) { } throw std::invalid_argument("Invalid grouping value: " + grouping); } + +[[maybe_unused]] static inline std::ostream& +operator<<(std::ostream& os, const CommanderGrouping& grouping) { + os << toString(grouping); + return os; +} + +[[maybe_unused]] static inline std::istream& +operator>>(std::istream& is, CommanderGrouping& grouping) { + std::string s; + is >> s; + grouping = groupingFromString(s); + return is; +} diff --git a/include/configuration/Encoding.hpp b/include/configuration/Encoding.hpp index ce2928036..15d4834a2 100644 --- a/include/configuration/Encoding.hpp +++ b/include/configuration/Encoding.hpp @@ -10,7 +10,7 @@ enum class Encoding { Naive, Commander, Bimander }; -[[maybe_unused]] static inline std::string toString(const Encoding encoding) { +static inline std::string toString(const Encoding encoding) { switch (encoding) { case Encoding::Naive: return "naive"; @@ -22,8 +22,7 @@ enum class Encoding { Naive, Commander, Bimander }; return " "; } -[[maybe_unused]] static Encoding -encodingFromString(const std::string& encoding) { +static Encoding encodingFromString(const std::string& encoding) { if (encoding == "naive" || encoding == "0") { return Encoding::Naive; } @@ -35,3 +34,17 @@ encodingFromString(const std::string& encoding) { } throw std::invalid_argument("Invalid encoding value: " + encoding); } + +[[maybe_unused]] static inline std::ostream& +operator<<(std::ostream& os, const Encoding& encoding) { + os << toString(encoding); + return os; +} + +[[maybe_unused]] static inline std::istream& operator>>(std::istream& is, + Encoding& encoding) { + std::string s; + is >> s; + encoding = encodingFromString(s); + return is; +} From 84a92d5f375be0b6185a2a6e794d16355646500e Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sun, 19 Mar 2023 11:38:08 +0100 Subject: [PATCH 07/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20update=20QFR=20with?= =?UTF-8?q?=20global=20phase=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- extern/qfr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/qfr b/extern/qfr index 94229bf0f..1dba93555 160000 --- a/extern/qfr +++ b/extern/qfr @@ -1 +1 @@ -Subproject commit 94229bf0f6ff70aae4f4036741f74a5f3a9bd0e5 +Subproject commit 1dba93555c3db86485b1ec396ddc251f67dc4f3d From 9eeabd6b750dc41a5436cfed525d5e069bcfa514 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sun, 19 Mar 2023 12:20:26 +0100 Subject: [PATCH 08/10] =?UTF-8?q?=E2=9C=85=20add=20a=20test=20ensuring=20t?= =?UTF-8?q?hat=20all=20gates=20can=20be=20provided=20with=20an=20error=20r?= =?UTF-8?q?ate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- test/test_architecture.cpp | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/test_architecture.cpp b/test/test_architecture.cpp index 4e3460479..5aabacb67 100644 --- a/test/test_architecture.cpp +++ b/test/test_architecture.cpp @@ -6,6 +6,7 @@ #include "Architecture.hpp" #include "gtest/gtest.h" +#include class TestArchitecture : public testing::TestWithParam { protected: @@ -160,3 +161,69 @@ TEST(TestArchitecture, TestCouplingLimitRing) { architecture.loadCouplingMap(5, cm); EXPECT_EQ(architecture.getCouplingLimit(), 2); } + +TEST(TestArchitecture, opTypeFromString) { + Architecture arch{2, {{0, 1}}}; + auto& props = arch.getProperties(); + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> dis(0., 1.); + + const std::vector> singleQubitGates = { + {"i", qc::OpType::I}, + {"x", qc::OpType::X}, + {"y", qc::OpType::Y}, + {"z", qc::OpType::Z}, + {"sx", qc::OpType::SX}, + {"sxdg", qc::OpType::SXdag}, + {"h", qc::OpType::H}, + {"s", qc::OpType::S}, + {"sdg", qc::OpType::Sdag}, + {"t", qc::OpType::T}, + {"tdg", qc::OpType::Tdag}, + {"rx", qc::OpType::RX}, + {"ry", qc::OpType::RY}, + {"rz", qc::OpType::RZ}, + {"u1", qc::OpType::Phase}, + {"u2", qc::OpType::U2}, + {"u3", qc::OpType::U3}, + {"reset", qc::OpType::Reset}, + {"measure", qc::OpType::Measure}}; + + for (const auto& [opName, opType] : singleQubitGates) { + const auto errorRate = dis(gen); + + props.setSingleQubitErrorRate(0, opName, errorRate); + EXPECT_EQ(props.getSingleQubitErrorRate(0, opName), errorRate); + } + + const std::vector> twoQubitGates = { + {"cx", qc::OpType::X}, + {"cz", qc::OpType::Z}, + {"cy", qc::OpType::Y}, + {"ch", qc::OpType::H}, + {"swap", qc::OpType::SWAP}, + {"crx", qc::OpType::RX}, + {"ry", qc::OpType::RY}, + {"crz", qc::OpType::RZ}, + {"cu1", qc::OpType::Phase}, + {"cu2", qc::OpType::U2}, + {"cu3", qc::OpType::U3}, + {"iswap", qc::OpType::iSWAP}, + {"ecr", qc::OpType::ECR}, + {"dcx", qc::OpType::DCX}, + {"rxx", qc::OpType::RXX}, + {"rzz", qc::OpType::RZZ}, + {"ryy", qc::OpType::RYY}, + {"rzx", qc::OpType::RZX}, + {"xx_minus_yy", qc::OpType::XXminusYY}, + {"xx_plus_yy", qc::OpType::XXplusYY}}; + + for (const auto& [opName, opType] : twoQubitGates) { + const auto errorRate = dis(gen); + + props.setTwoQubitErrorRate(0, 1, errorRate, opName); + EXPECT_EQ(props.getTwoQubitErrorRate(0, 1, opName), errorRate); + } +} From 261c0583cf81c8c18500a23b27a6349fa8d745ed Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sun, 19 Mar 2023 14:32:15 +0100 Subject: [PATCH 09/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20update=20QFR=20with?= =?UTF-8?q?=20string=20to=20OpType=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- extern/qfr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/qfr b/extern/qfr index 1dba93555..9dbdebce6 160000 --- a/extern/qfr +++ b/extern/qfr @@ -1 +1 @@ -Subproject commit 1dba93555c3db86485b1ec396ddc251f67dc4f3d +Subproject commit 9dbdebce6f0c2f5246d7ecfe240f34a3ec6c8ea9 From 27bb1c85750d5a8dc803065dc0bb537c6a1ddb98 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Sun, 19 Mar 2023 14:32:38 +0100 Subject: [PATCH 10/10] =?UTF-8?q?=E2=8F=AA=20revert=20string=20to=20OpType?= =?UTF-8?q?=20conversion=20workaround?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- include/Architecture.hpp | 16 +++---- src/Architecture.cpp | 93 ---------------------------------------- 2 files changed, 7 insertions(+), 102 deletions(-) diff --git a/include/Architecture.hpp b/include/Architecture.hpp index 829e4dd07..d00c4d969 100644 --- a/include/Architecture.hpp +++ b/include/Architecture.hpp @@ -83,13 +83,14 @@ class Architecture { void setSingleQubitErrorRate(std::uint16_t qubit, const std::string& operation, double errorRate) { - singleQubitErrorRate.get(qubit).set(opTypeFromString(operation), + singleQubitErrorRate.get(qubit).set(qc::opTypeFromString(operation), errorRate); } [[nodiscard]] double getSingleQubitErrorRate(std::uint16_t qubit, const std::string& operation) const { - return singleQubitErrorRate.get(qubit).get(opTypeFromString(operation)); + return singleQubitErrorRate.get(qubit).get( + qc::opTypeFromString(operation)); } [[nodiscard]] double getAverageSingleQubitErrorRate(const std::uint16_t qubit) const { @@ -105,14 +106,14 @@ class Architecture { void setTwoQubitErrorRate(std::uint16_t qubit1, std::uint16_t qubit2, double errorRate, const std::string& operation = "cx") { - twoQubitErrorRate.get(qubit1).get(qubit2).set(opTypeFromString(operation), - errorRate); + twoQubitErrorRate.get(qubit1).get(qubit2).set( + qc::opTypeFromString(operation), errorRate); } [[nodiscard]] double getTwoQubitErrorRate(std::uint16_t qubit1, std::uint16_t qubit2, const std::string& operation = "cx") const { return twoQubitErrorRate.get(qubit1).get(qubit2).get( - opTypeFromString(operation)); + qc::opTypeFromString(operation)); } [[nodiscard]] bool twoQubitErrorRateAvailable(std::uint16_t qubit1, std::uint16_t qubit2, @@ -120,7 +121,7 @@ class Architecture { return twoQubitErrorRate.available(qubit1) && twoQubitErrorRate.get(qubit1).available(qubit2) && twoQubitErrorRate.get(qubit1).get(qubit2).available( - opTypeFromString(operation)); + qc::opTypeFromString(operation)); } void clear() { @@ -396,7 +397,4 @@ class Architecture { std::uint16_t node, std::uint16_t curSum, const std::vector>& connections, std::vector& d, std::vector& visited); - - [[nodiscard]] static qc::OpType - opTypeFromString(const std::string& operation); }; diff --git a/src/Architecture.cpp b/src/Architecture.cpp index 511f336cf..89c065d61 100644 --- a/src/Architecture.cpp +++ b/src/Architecture.cpp @@ -691,96 +691,3 @@ void Architecture::printCouplingMap(const CouplingMap& cm, std::ostream& os) { } os << "}" << std::endl; } - -qc::OpType Architecture::opTypeFromString(const std::string& operation) { - if (operation == "i" || operation == "id") { - return qc::OpType::I; - } - if (operation == "h" || operation == "ch") { - return qc::OpType::H; - } - if (operation == "x" || operation == "cx" || operation == "cnot") { - return qc::OpType::X; - } - if (operation == "y" || operation == "cy") { - return qc::OpType::Y; - } - if (operation == "z" || operation == "cz") { - return qc::OpType::Z; - } - if (operation == "s" || operation == "cs") { - return qc::OpType::S; - } - if (operation == "sdg" || operation == "csdg") { - return qc::OpType::Sdag; - } - if (operation == "t" || operation == "ct") { - return qc::OpType::T; - } - if (operation == "tdg" || operation == "ctdg") { - return qc::OpType::Tdag; - } - if (operation == "u3" || operation == "cu3" || operation == "u" || - operation == "cu") { - return qc::OpType::U3; - } - if (operation == "u2" || operation == "cu2") { - return qc::OpType::U2; - } - if (operation == "u1" || operation == "cu1" || operation == "p" || - operation == "cp") { - return qc::OpType::Phase; - } - if (operation == "sx" || operation == "csx") { - return qc::OpType::SX; - } - if (operation == "sxdg" || operation == "csxdg") { - return qc::OpType::SXdag; - } - if (operation == "rx" || operation == "crx") { - return qc::OpType::RX; - } - if (operation == "ry" || operation == "cry") { - return qc::OpType::RY; - } - if (operation == "rz" || operation == "crz") { - return qc::OpType::RZ; - } - if (operation == "swap" || operation == "cswap") { - return qc::OpType::SWAP; - } - if (operation == "iswap") { - return qc::OpType::iSWAP; - } - if (operation == "dcx") { - return qc::OpType::DCX; - } - if (operation == "ecr") { - return qc::OpType::ECR; - } - if (operation == "rxx") { - return qc::OpType::RXX; - } - if (operation == "ryy") { - return qc::OpType::RYY; - } - if (operation == "rzz") { - return qc::OpType::RZZ; - } - if (operation == "rzx") { - return qc::OpType::RZX; - } - if (operation == "xx_minus_yy") { - return qc::OpType::XXminusYY; - } - if (operation == "xx_plus_yy") { - return qc::OpType::XXplusYY; - } - if (operation == "measure") { - return qc::OpType::Measure; - } - if (operation == "reset") { - return qc::OpType::Reset; - } - throw std::invalid_argument("Unsupported operation type: " + operation); -}