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
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL "Export compile commands" FORCE)

option(BUILD_UNIT_TESTS "Build the unit tests" ON)
option(ENABLE_COVERAGE "Enabling coverage" ON)
option(BUILD_TESTS "Build the tests" OFF)
option(BUILD_UNIT_TESTS "Build the unit tests" OFF)
option(ENABLE_COVERAGE "Enabling coverage" OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

Expand Down Expand Up @@ -58,3 +59,7 @@ endif()
if(BUILD_DOCUMENTATION)
add_subdirectory(docs)
endif()

if(BUILD_BINDINGS)
add_subdirectory(bindings)
endif()
39 changes: 39 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2024 - 2026 MQSS Project
# All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

find_package(pybind11 REQUIRED)

set(MQSS_PYTHON_MODULE_NAME PyMQSSClient)

file(GLOB_RECURSE MQSS_CLIENT_SOURCES **.cpp)

pybind11_add_module(${MQSS_PYTHON_MODULE_NAME} MODULE ${MQSS_CLIENT_SOURCES})

target_include_directories(${MQSS_PYTHON_MODULE_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(${MQSS_PYTHON_MODULE_NAME} PRIVATE mqss_client)

set_target_properties(${MQSS_PYTHON_MODULE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN")

install(
TARGETS ${MQSS_PYTHON_MODULE_NAME}
DESTINATION .
COMPONENT mqss_client_bindings)
27 changes: 27 additions & 0 deletions bindings/bindings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 - 2026 MQSS Project
* All rights reserved.
*
* Licensed under the Apache License v2.0 with LLVM Exceptions (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "bindings.h"

PYBIND11_MODULE(PyMQSSClient, m) {
m.doc() = "Python bindings for the MQSS client";
registerClientInterface(m);
registerJobInterface(m);
registerResourceInterface(m);
}
26 changes: 26 additions & 0 deletions bindings/bindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2024 - 2026 MQSS Project
* All rights reserved.
*
* Licensed under the Apache License v2.0 with LLVM Exceptions (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include <pybind11/pybind11.h>

namespace py = pybind11;

void registerClientInterface(const py::module& m);
void registerJobInterface(const py::module& m);
void registerResourceInterface(const py::module& m);
43 changes: 43 additions & 0 deletions bindings/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 - 2026 MQSS Project
* All rights reserved.
*
* Licensed under the Apache License v2.0 with LLVM Exceptions (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "mqss/client.h"

#include "bindings.h"

void registerClientInterface(const py::module& m) {

py::class_<mqss::client::MQSSClient>(m, "MQSSClient")
.def(py::init<const std::string&, const std::string&, bool>(),
py::arg("token") = "", py::arg("url_or_queue") = MQP_DEFAULT_URL,
py::arg("is_hpc") = false)
.def_property_readonly("resources",
&mqss::client::MQSSClient::getAllResources)
.def("resource", &mqss::client::MQSSClient::getResourceInfo,
py::arg("resource"))
.def("submit_job", &mqss::client::MQSSClient::submitJob,
py::arg("job_request"))
.def("cancel_job", &mqss::client::MQSSClient::cancelJob, py::arg("job"))
.def("job_status", &mqss::client::MQSSClient::getJobStatus,
py::arg("job"))
.def("job_results", &mqss::client::MQSSClient::getJobResult,
py::arg("job"), py::arg("wait") = false, py::arg("timeout") = 100)
.def("pending_job_count", &mqss::client::MQSSClient::getNumberPendingJobs,
py::arg("resource"));
}
48 changes: 6 additions & 42 deletions src/python/bindings.cpp → bindings/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,15 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "mqss/client.h"
#include "mqss/job.h"

#include <pybind11/cast.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

PYBIND11_MODULE(mqss, m) {
m.doc() = "Python bindings for the MQSS client";

py::module_ clientModule = m.def_submodule("client", "Submodule Client");

py::class_<mqss::client::MQSSClient>(clientModule, "MQSSClient")
.def(py::init<const std::string&, const std::string&, bool>(),
py::arg("token") = "", py::arg("url_or_queue") = MQP_DEFAULT_URL,
py::arg("is_hpc") = false)
.def_property_readonly("resources",
&mqss::client::MQSSClient::getAllResources)
.def("resource", &mqss::client::MQSSClient::getResourceInfo,
py::arg("resource"))
.def("submit_job", &mqss::client::MQSSClient::submitJob,
py::arg("job_request"))
.def("cancel_job", &mqss::client::MQSSClient::cancelJob, py::arg("job"))
.def("job_status", &mqss::client::MQSSClient::getJobStatus,
py::arg("job"))
.def("job_results", &mqss::client::MQSSClient::getJobResult,
py::arg("job"), py::arg("wait") = false, py::arg("timeout") = 100)
.def("pending_job_count", &mqss::client::MQSSClient::getNumberPendingJobs,
py::arg("resource"));

py::class_<mqss::client::Resource>(clientModule, "Resource")
.def_property_readonly("name", &mqss::client::Resource::getName)
.def_property_readonly("qubit_count",
&mqss::client::Resource::getQubitCount)
.def_property_readonly("online", &mqss::client::Resource::isOnline)
.def_property_readonly("coupling_map",
&mqss::client::Resource::getCouplingMap)
.def_property_readonly("native_gateset",
&mqss::client::Resource::getNativeGateset);
#include "bindings.h"

void registerJobInterface(const py::module& m) {
py::class_<mqss::client::JobRequest>(m, "JobRequest").doc();

py::class_<mqss::client::CircuitJobRequest, mqss::client::JobRequest>(
clientModule, "CircuitJobRequest")
m, "CircuitJobRequest")
.def(py::init<>())
.def(py::init<std::string&, std::string&, std::string&, unsigned int,
bool, bool>(),
Expand All @@ -84,7 +48,7 @@ PYBIND11_MODULE(mqss, m) {
&mqss::client::CircuitJobRequest::setQueued);

py::class_<mqss::client::HamiltonianJobRequest, mqss::client::JobRequest>(
clientModule, "HamiltonianJobRequest")
m, "HamiltonianJobRequest")
.def(py::init<>())
.def(py::init<std::string&, std::string&, std::string&>(),
py::arg("resource_name"), py::arg("interaction"),
Expand All @@ -100,7 +64,7 @@ PYBIND11_MODULE(mqss, m) {
&mqss::client::HamiltonianJobRequest::getCoefficientsString,
&mqss::client::HamiltonianJobRequest::setCoefficientsString);

py::class_<mqss::client::JobResult>(clientModule, "JobResult")
py::class_<mqss::client::JobResult>(m, "JobResult")
.def_property_readonly("results", &mqss::client::JobResult::getResults)
.def_property_readonly("completion_timestamp",
&mqss::client::JobResult::getTimestampCompleted)
Expand Down
40 changes: 40 additions & 0 deletions bindings/resource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 - 2026 MQSS Project
* All rights reserved.
*
* Licensed under the Apache License v2.0 with LLVM Exceptions (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "mqss/resource.h"

#include "bindings.h"

void registerResourceInterface(const py::module& m) {
py::class_<mqss::client::Resource>(m, "Resource")
.def_property_readonly("name", &mqss::client::Resource::getName)
.def_property_readonly("qubit_count",
&mqss::client::Resource::getQubitCount)
.def_property_readonly("online", &mqss::client::Resource::isOnline)
.def_property_readonly("coupling_map",
&mqss::client::Resource::getCouplingMap)
.def_property_readonly("native_gateset",
&mqss::client::Resource::getNativeGateset);

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("supported_qubits",
&mqss::client::Gate::getSupportedQubits);
}
8 changes: 5 additions & 3 deletions include/mqss/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@ class HamiltonianJobRequest : public JobRequest {

class JobResult {

std::map<std::string, unsigned int> mResults;
std::vector<std::map<std::string, unsigned int>> mResults;
std::string mTimestampCompleted;
std::string mTimestampSubmitted;
std::string mTimestampScheduled;

public:
JobResult(std::map<std::string, unsigned int> results,
JobResult(std::vector<std::map<std::string, unsigned int>> results,
std::string timestampCompleted, std::string timestampSubmitted,
std::string timestampScheduled);

JobResult(const nlohmann::json& parsed);

std::map<std::string, unsigned int> getResults() const { return mResults; }
std::vector<std::map<std::string, unsigned int>> getResults() const {
return mResults;
}
std::string getTimestampCompleted() const { return mTimestampCompleted; }
std::string getTimestampSubmitted() const { return mTimestampSubmitted; }
std::string getTimestampScheduled() const { return mTimestampScheduled; }
Expand Down
37 changes: 31 additions & 6 deletions include/mqss/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,56 @@
#include <utility>
#include <vector>
namespace mqss::client {

class Gate {

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

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

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

const std::vector<std::vector<unsigned int>>&
getSupportedQubits() const noexcept {
return mSupportedQubits;
}

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

class Resource {
public:
Resource(std::string name, unsigned qubitCount, bool online,
std::vector<std::pair<int, int>> couplingMap,
std::vector<std::string> nativeGateset);
std::vector<std::vector<int>> couplingMap,
std::vector<Gate> nativeGateset);

Resource(const nlohmann::json& json);

const std::string& getName() const noexcept { return mName; }
unsigned getQubitCount() const noexcept { return mQubitCount; }
bool isOnline() const noexcept { return mOnline; }

const std::vector<std::pair<int, int>>& getCouplingMap() const noexcept {
const std::vector<std::vector<int>>& getCouplingMap() const noexcept {
return mCouplingMap;
}

const std::vector<std::string>& getNativeGateset() const noexcept {
const std::vector<Gate>& getNativeGateset() const noexcept {
return mNativeGateset;
}

private:
std::string mName;
unsigned mQubitCount;
bool mOnline;
std::vector<std::pair<int, int>> mCouplingMap;
std::vector<std::string> mNativeGateset;
std::vector<std::vector<int>> mCouplingMap;
std::vector<Gate> mNativeGateset;
};

} // namespace mqss::client
Loading
Loading