Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bindings/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void registerResourceInterface(const py::module& m) {

py::class_<mqss::client::Gate>(m, "Gate")
.def_property_readonly("name", &mqss::client::Gate::getName)
.def_property_readonly("arity", &mqss::client::Gate::getArity)
.def_property_readonly("qubit_number", &mqss::client::Gate::getQubitNumber)
.def_property_readonly("parameter_number", &mqss::client::Gate::getParameterNumber)
.def_property_readonly("supported_qubits",
&mqss::client::Gate::getSupportedQubits);
}
2 changes: 0 additions & 2 deletions include/mqss/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ class MQSSClient {
const std::string& url_or_queue = MQP_DEFAULT_URL,
bool is_hpc = false);

#ifdef ENABLE_UNIT_TEST
explicit MQSSClient(std::unique_ptr<MQSSBaseClient> client)
: mClient(std::move(client)) {}
#endif

// Resources
std::vector<Resource> getAllResources() const;
Expand Down
1 change: 1 addition & 0 deletions include/mqss/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#pragma once
#include <nlohmann/json.hpp>
#include <string>
#include <utility>
Expand Down
15 changes: 11 additions & 4 deletions include/mqss/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#pragma once
#include <nlohmann/json.hpp>
#include <string>
#include <utility>
Expand All @@ -26,14 +27,19 @@ namespace mqss::client {
class Gate {

public:
Gate(std::string name, unsigned int arity,
Gate(std::string name, unsigned int qubitNumber, unsigned int parameterNumber,
std::vector<std::vector<unsigned int>> supportedQubits)
: mName(std::move(name)), mArity(arity),
: mName(std::move(name)), mQubitNumber(qubitNumber),
mParameterNumber(parameterNumber),
mSupportedQubits(std::move(supportedQubits)) {}

const std::string& getName() const noexcept { return mName; }

const unsigned int& getArity() const noexcept { return mArity; }
const unsigned int& getQubitNumber() const noexcept { return mQubitNumber; }

const unsigned int& getParameterNumber() const noexcept {
return mParameterNumber;
}

const std::vector<std::vector<unsigned int>>&
getSupportedQubits() const noexcept {
Expand All @@ -42,7 +48,8 @@ class Gate {

private:
std::string mName;
unsigned int mArity;
unsigned int mQubitNumber;
unsigned int mParameterNumber;
std::vector<std::vector<unsigned int>> mSupportedQubits;
};

Expand Down
49 changes: 43 additions & 6 deletions src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,43 @@ std::vector<std::vector<int>> extractCouplingMap(const nlohmann::json& response,
return result;
}

std::pair<unsigned int, unsigned int>
getGateProterties(const std::string& gateName) {

if (gateName == "cz") {
return {2, 0};
}
if (gateName == "measure") {
return {1, 0};
}
if (gateName == "id") {
return {1, 0};
}
if (gateName == "r") {
return {1, 2};
}
if (gateName == "rx") {
return {1, 1};
}
if (gateName == "rz") {
return {1, 1};
}
if (gateName == "rxx") {
return {2, 1};
}
if (gateName == "if_else") {
return {1, 0};
}
if (gateName == "reset") {
return {1, 0};
}
if (gateName == "swap") {
return {2, 0};
}

throw std::invalid_argument("Unknown Gate: " + gateName);
}

std::vector<Gate> extractGates(const nlohmann::json& response,
const std::string& key) {

Expand All @@ -66,13 +103,13 @@ std::vector<Gate> extractGates(const nlohmann::json& response,
std::regex gateRegex(R"(\(\s*['"]([^'"]+)['"]\s*,\s*(\{[^{}]*\})\s*\))");
auto gateBegin = std::sregex_iterator(text.begin(), text.end(), gateRegex);
auto gateEnd = std::sregex_iterator();
std::string GateName;
unsigned int arity;
std::string gateName;
unsigned int qubitCount;
std::vector<std::vector<unsigned int>> supportedQubits;

for (auto it = gateBegin; it != gateEnd; ++it) {

GateName = (*it)[1];
gateName = (*it)[1];

std::string body = (*it)[2];
std::regex tupleRegex(R"(([^)]*)\)\s*:\s*None)");
Expand All @@ -99,9 +136,9 @@ std::vector<Gate> extractGates(const nlohmann::json& response,
supportedQubits.push_back(qubits);
}

arity = !supportedQubits.empty() ? supportedQubits.at(0).size() : 0;

result.push_back(Gate(GateName, arity, std::move(supportedQubits)));
auto [qubitCount, parameterNumber] = getGateProterties(gateName);
result.emplace_back(gateName, qubitCount, parameterNumber,
std::move(supportedQubits));
}

return result;
Expand Down
Loading