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
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ option(ENABLE_COVERAGE "Enabling coverage" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if(ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -O0 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0 -g")
add_library(coverage_flags INTERFACE)

target_compile_options(coverage_flags INTERFACE --coverage -fprofile-arcs -ftest-coverage -O0)

target_link_options(coverage_flags INTERFACE --coverage)
endif()

set(CMAKE_C_STANDARD 11)
Expand Down
11 changes: 7 additions & 4 deletions include/mqss/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ class MQSSClient {
std::unique_ptr<JobResult> waitForJobResult(const JobRequest& job,
size_t poll_seconds);

std::unique_ptr<MQSSBaseClient> mClient;

public:
MQSSClient(const std::string& token = "",
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;
std::optional<Resource> getResourceInfo(const std::string& resource) const;
Expand All @@ -64,11 +71,7 @@ class MQSSClient {
std::string getJobStatus(const JobRequest& job);
std::unique_ptr<JobResult>
getJobResult(const JobRequest& job, bool wait = false, size_t timeout = 100);

int getNumberPendingJobs(const std::string& resource) const;

private:
std::unique_ptr<MQSSBaseClient> mClient;
};

} // namespace mqss::client
3 changes: 2 additions & 1 deletion src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <thread>

using namespace mqss::client;

// GCOVR_EXCL_START
MQSSClient::MQSSClient(const std::string& token,
const std::string& url_or_queue, bool is_hpc) {
if (is_hpc) {
Expand All @@ -36,6 +36,7 @@ MQSSClient::MQSSClient(const std::string& token,
mClient = std::make_unique<MQSSRestClient>(token, url_or_queue);
}
}
// GCOVR_EXCL_STOP

std::vector<Resource> MQSSClient::getAllResources() const {
std::vector<Resource> Resources;
Expand Down
3 changes: 3 additions & 0 deletions src/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ nlohmann::json HamiltonianJobRequest::toJson() const {
{"coefficients_str", mCoefficientsStr}};
}

// GCOVR_EXCL_START
JobResult::JobResult(std::vector<std::map<std::string, unsigned int>> results,
std::string timestampCompleted,
std::string timestampSubmitted,
Expand All @@ -63,6 +64,8 @@ JobResult::JobResult(std::vector<std::map<std::string, unsigned int>> results,
mTimestampSubmitted(std::move(timestampSubmitted)),
mTimestampScheduled(std::move(timestampScheduled)) {}

// GCOVR_EXCL_STOP

JobResult::JobResult(const nlohmann::json& parsed) {

std::vector<std::map<std::string, unsigned int>> results;
Expand Down
5 changes: 2 additions & 3 deletions src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ std::vector<Gate> extractGates(const nlohmann::json& response,
const std::string& text = it->get_ref<const std::string&>();
if (text == "None")
return result;
std::regex gateRegex(R"(\(\s*'([^']+)'\s*,\s*\{([^}]*)\}\s*\))");

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;
Expand Down Expand Up @@ -126,7 +125,7 @@ Resource::Resource(const nlohmann::json& json) {
std::vector<std::vector<int>> couplingMap =
extractCouplingMap(json, "connectivity");

std::vector<Gate> nativeGateset = extractGates(json, "Gates");
std::vector<Gate> nativeGateset = extractGates(json, "instructions");

mName = std::move(name);
mQubitCount = qubitCount;
Expand Down
22 changes: 21 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,24 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

enable_testing()
add_subdirectory(unit_tests)
include(GoogleTest)

function(add_test test_name)
add_executable(${test_name} ${test_name}.cpp)

target_link_libraries(${test_name} PRIVATE gmock gtest gtest_main mqss_client)

if(ENABLE_COVERAGE)
target_link_libraries(${test_name} PRIVATE coverage_flags)
endif()

gtest_discover_tests(${test_name})
endfunction()

if(BUILD_TESTS OR BUILD_UNIT_TESTS)
add_subdirectory(unit/c++)
endif()

if(BUILD_TESTS OR BUILD_INTEGRATION_TESTS)
add_subdirectory(integration/c++)
endif()
19 changes: 19 additions & 0 deletions tests/integration/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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

add_test(job_integration_test)
add_test(resource_integration_test)
19 changes: 19 additions & 0 deletions tests/unit/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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

add_test(job_unit_test)
add_test(resource_unit_test)
Loading
Loading