Skip to content
Draft
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ project(
MQSS-Client
VERSION 0.1
DESCRIPTION "MQSS Client"
LANGUAGES CXX)
LANGUAGES CXX C)

# Generate compile_commands.json to make it easier to work with clang based tools
set(CMAKE_EXPORT_COMPILE_COMMANDS
Expand All @@ -33,6 +33,7 @@ option(BUILD_TESTS "Build the tests" OFF)
option(BUILD_UNIT_TESTS "Build the unit tests" OFF)
option(BUILD_INTEGRATION_TESTS "Build the unit tests" OFF)
option(ENABLE_COVERAGE "Enabling coverage" OFF)
option(BUILD_BINDINGS "Build Python Bindings" OFF)

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

Expand Down
48 changes: 48 additions & 0 deletions include/mqss-c/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "job.h"
#include "resource.h"

#include <stdbool.h>

typedef struct MQSSOpaqueClient* MQSSClientRef;

MQSSClientRef mqssClientCreateClient(char* token, char* urlOrQueue, bool isHpc);

MQSSResourceRef* mqssClientGetAllResources(MQSSClientRef client, int* size);

MQSSResourceRef* mqssClientGetResourceInfo(MQSSClientRef client,
char* resourceName);

int mqssClientSubmitJob(MQSSClientRef client, MQSSJobRef job);

void mqssClientCancelJob(MQSSClientRef client, MQSSJobRef job);

MQSSJobResultRef mqssClientGetJobResult(MQSSClientRef client, MQSSJobRef job, bool wait,
unsigned int timeout);

int mqssClientGetNumberPendingJobs(MQSSClientRef client, char* resourceName,
int pendingJobNumber);
#ifdef __cplusplus
}
#endif
46 changes: 46 additions & 0 deletions include/mqss-c/job.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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
*/


#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
typedef struct MQSSOpaqueJob *MQSSJobRef;

typedef struct MQSSOpaqueJobResult *MQSSJobResultRef;

MQSSJobRef mqssClientCreateCircuitJob(char* circuit,
char* circuitFormat, char* resourceName,
unsigned int shots, bool noModify, bool queued);

int mqssClientCreateHamiltonianJob(MQSSJobRef job, char* resourceName,
char* interactionStr, char* coefficientsStr);

int mqssClientGetJobResultCounts(MQSSJobResultRef jobResult, char** bitstreams, int* counts, int size);

int mqssClientGetJobResultCompletedTimestamp(MQSSJobResultRef jobResult, unsigned int completedTimestamp);

int mqssClientGetJobResultSubmittedTimestamp(MQSSJobResultRef jobResult, unsigned int submittedTimestamp);

int mqssClientGetJobResultScheduledTimestamp(MQSSJobResultRef jobResult, unsigned int scheduledTimestamp);

#ifdef __cplusplus
}
#endif
40 changes: 40 additions & 0 deletions include/mqss-c/resource.h
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
*/

#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>

typedef struct MQSSOpaqueResource *MQSSResourceRef;

typedef struct MQSSOpaqueGate *MQSSGateRef;

int mqssClientResourceGetInfo(MQSSResourceRef resource, char** name,
unsigned* qubitCount, bool* online,
int** couplingMap, MQSSGateRef** nativeGateset,
unsigned int* gateCount);

int mqssClientResourceGetGateInfo(MQSSGateRef gate, unsigned int qubitNumber,
unsigned int parameterNumber,
int* supportedQubits);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions include/mqss/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@

#define MQP_DEFAULT_URL "https://portal.quantum.lrz.de:4000/v1/"

template <typename T, typename RefT> inline T* unwrap(RefT ref) {
return reinterpret_cast<T*>(ref);
}

template <typename RefT, typename T> inline RefT wrap(T* ptr) {
return reinterpret_cast<RefT>(ptr);
}

namespace mqss::client {

class MQSSBaseClient {
Expand Down
10 changes: 7 additions & 3 deletions include/mqss/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class Gate {
mParameterNumber(parameterNumber),
mSupportedQubits(std::move(supportedQubits)) {}

Gate(const Gate&) = default;
Gate& operator=(const Gate&) = default;

Gate(Gate&&) = default;
Gate& operator=(Gate&&) = default;

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

const unsigned int& getQubitNumber() const noexcept { return mQubitNumber; }
Expand Down Expand Up @@ -69,9 +75,7 @@ class Resource {
return mCouplingMap;
}

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

private:
std::string mName;
Expand Down
38 changes: 38 additions & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "clients/hpc_client.h"
#include "clients/rest_client.h"
#include "mqss-c/client.h"

#include <chrono>
#include <optional>
Expand Down Expand Up @@ -139,3 +140,40 @@ int MQSSClient::getNumberPendingJobs(const std::string& resource) const {

return parsed.value("num_pending_jobs", -1);
}

MQSSClientRef mqssClientCreateClient(char* token, char* urlOrQueue,
bool isHpc) {

return wrap<MQSSClientRef>(new MQSSClient(token, urlOrQueue, isHpc));
}
MQSSResourceRef* mqssClientGetAllResources(MQSSClientRef client, int* size) {
auto resources_ = unwrap<MQSSClient>(client)->getAllResources();

auto resources =
(MQSSResourceRef*)malloc(resources_.size() * sizeof(MQSSResourceRef));

for (size_t i = 0; i < resources_.size(); ++i) {
resources[i] = wrap<MQSSResourceRef>(new Resource(resources_[i]));
}

*size = (int)resources_.size();
return resources;
}

int mqssClientSubmitJob(MQSSClientRef client, MQSSJobRef job) {
auto uuid =
unwrap<MQSSClient>(client)->submitJob(*unwrap<CircuitJobRequest>(job));
if (!uuid.has_value()) {
return -1;
}
return std::stoi(*uuid);
}

MQSSJobResultRef mqssClientGetJobResult(MQSSClientRef client, MQSSJobRef job,
bool wait, unsigned int timeout) {

std::unique_ptr<JobResult> jobResult = unwrap<MQSSClient>(client)->getJobResult(*unwrap<CircuitJobRequest>(job),
wait, timeout);
std::cout << jobResult->getTimestampCompleted() << "\n";
return wrap<MQSSJobResultRef>(jobResult.get());
}
9 changes: 9 additions & 0 deletions src/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

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

using namespace mqss::client;

Expand Down Expand Up @@ -96,3 +98,10 @@ JobResult::JobResult(const nlohmann::json& parsed) {
mTimestampSubmitted = parsed.at("timestamp_submitted").get<std::string>();
mTimestampScheduled = parsed.at("timestamp_scheduled").get<std::string>();
}

MQSSJobRef mqssClientCreateCircuitJob(char* circuit,
char* circuitFormat, char* resourceName,
unsigned int shots, bool noModify, bool queued) {
return wrap<MQSSJobRef>(new CircuitJobRequest(
circuit, circuitFormat, resourceName, shots, noModify, queued));
}
35 changes: 35 additions & 0 deletions src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "mqss/resource.h"

#include "mqss-c/resource.h"
#include "mqss/client.h"
#include <regex>

using namespace mqss::client;
Expand Down Expand Up @@ -170,3 +172,36 @@ Resource::Resource(const nlohmann::json& json) {
mCouplingMap = std::move(couplingMap);
mNativeGateset = std::move(nativeGateset);
}

int mqssClientResourceGetInfo(MQSSResourceRef resource, char** name,
unsigned* qubitCount, bool* online,
int** couplingMap, MQSSGateRef** nativeGateset,
unsigned int* gateCount) {
auto* resource_ = unwrap<Resource>(resource);
if (resource_ == nullptr)
return -2;

// Name
if (asprintf(name, "%s", resource_->getName().c_str()) < 0)
return -3;

*qubitCount = resource_->getQubitCount();
*online = resource_->isOnline();

*couplingMap = nullptr;

auto& gates = resource_->getNativeGateset();

*gateCount = gates.size();

*nativeGateset = (MQSSGateRef*)malloc(sizeof(MQSSGateRef) * gates.size());

if (!*nativeGateset)
return -4;

for (size_t i = 0; i < gates.size(); ++i) {
(*nativeGateset)[i] = wrap<MQSSGateRef>(&gates[i]);
}

return 0;
}
Loading