-
Notifications
You must be signed in to change notification settings - Fork 290
Add Qilimanjaro Target #3345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
fedonman
wants to merge
12
commits into
NVIDIA:main
Choose a base branch
from
qilimanjaro-tech:feature/add-qilimanjaro-target
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Qilimanjaro Target #3345
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bda56f6
initial implementation
fedonman f45789c
Merge branch 'main' into feature/add-qilimanjaro-target
fedonman c8817c9
fix typo
fedonman 7729311
Merge branch 'main' into feature/add-qilimanjaro-target
fedonman a6859a8
fix typo
fedonman 1ae666f
merge from main
fedonman 91c04d4
merge from main
fedonman 88aacc6
Merge branch 'NVIDIA:main' into feature/add-qilimanjaro-target
fedonman fdd620d
fix typo
fedonman 5d5b041
DCO Remediation Commit for Vyron Vasileiadis <hi@fedonman.com>
fedonman 55ced13
merge from main
fedonman d038a20
DCO Remediation Commit for Vyron Vasileiadis <hi@fedonman.com>
fedonman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,7 @@ QPUs | |
QPU’s | ||
QTX | ||
QX | ||
Qilimanjaro | ||
Qiskit | ||
QuEra | ||
QuTiP | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2025 NVIDIA Corporation & Affiliates. # | ||
# All rights reserved. # | ||
# # | ||
# This source code and the accompanying materials are made available under # | ||
# the terms of the Apache License 2.0 which accompanies this distribution. # | ||
# ============================================================================ # | ||
|
||
import cudaq | ||
import json | ||
import os | ||
import pytest | ||
|
||
skipIfQilimanjaroNotInstalled = pytest.mark.skipif( | ||
not cudaq.has_target("qilimanjaro"), | ||
reason='Could not find `qilimanjaro` in installation' | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def do_something(): | ||
# NOTE: Credentials can be set with environment variables | ||
cudaq.set_target("qilimanjaro") | ||
yield "Running the tests." | ||
cudaq.reset_target() | ||
|
||
# leave for gdb debugging | ||
if __name__ == "__main__": | ||
loc = os.path.abspath(__file__) | ||
pytest.main([loc, "-rP"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. # | ||
# All rights reserved. # | ||
# # | ||
# This source code and the accompanying materials are made available under # | ||
# the terms of the Apache License 2.0 which accompanies this distribution. # | ||
# ============================================================================ # | ||
|
||
set(LIBRARY_NAME cudaq-qilimanjaro-qpu) | ||
message(STATUS "Building Qilimanjaro REST QPU.") | ||
|
||
add_library(${LIBRARY_NAME} | ||
SHARED | ||
QilimanjaroRemoteRESTQPU.cpp | ||
QilimanjaroServerHelper.cpp | ||
) | ||
|
||
target_include_directories(${LIBRARY_NAME} PRIVATE . | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/runtime> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
target_link_libraries(${LIBRARY_NAME} | ||
PUBLIC | ||
cudaq-operator | ||
cudaq-common | ||
PRIVATE | ||
pthread | ||
cudaq-mlir-runtime | ||
fmt::fmt-header-only | ||
cudaq | ||
cudaq-platform-default | ||
) | ||
|
||
install(TARGETS ${LIBRARY_NAME} DESTINATION lib) | ||
|
||
add_target_config(qilimanjaro) |
23 changes: 23 additions & 0 deletions
23
runtime/cudaq/platform/qilimanjaro/QilimanjaroRemoteRESTQPU.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#include "common/AnalogRemoteRESTQPU.h" | ||
|
||
namespace { | ||
|
||
/// @brief The `QilimanjaroRemoteRESTQPU` is a subtype of QPU that enables the | ||
/// execution of Analog Hamiltonian Program via a REST Client. | ||
class QilimanjaroRemoteRESTQPU : public cudaq::AnalogRemoteRESTQPU { | ||
public: | ||
QilimanjaroRemoteRESTQPU() : AnalogRemoteRESTQPU() {} | ||
QilimanjaroRemoteRESTQPU(QilimanjaroRemoteRESTQPU &&) = delete; | ||
virtual ~QilimanjaroRemoteRESTQPU() = default; | ||
}; | ||
} // namespace | ||
|
||
CUDAQ_REGISTER_TYPE(cudaq::QPU, QilimanjaroRemoteRESTQPU, qilimanjaro) |
116 changes: 116 additions & 0 deletions
116
runtime/cudaq/platform/qilimanjaro/QilimanjaroServerHelper.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#include "QilimanjaroServerHelper.h" | ||
#include "common/AnalogHamiltonian.h" | ||
#include "common/Logger.h" | ||
|
||
#include <unordered_map> | ||
#include <unordered_set> | ||
|
||
namespace cudaq { | ||
|
||
void QilimanjaroServerHelper::initialize(BackendConfig config) { | ||
cudaq::info("Initialize Qilimanjaro's SpeQtrum."); | ||
|
||
// Hard-coded for now. | ||
const std::string MACHINE = "CUDA_DYNAMICS"; | ||
|
||
cudaq::info("Running on device {}", MACHINE); | ||
|
||
if (!config.contains("machine")) | ||
config["machine"] = MACHINE; | ||
|
||
if (!config["nshots"].empty()) | ||
setShots(std::stoul(config["nshots"])); | ||
|
||
parseConfigForCommonParams(config); | ||
|
||
backendConfig = std::move(config); | ||
} | ||
|
||
RestHeaders QilimanjaroServerHelper::getHeaders() { | ||
std::string token; | ||
|
||
if (auto auth_token = std::getenv("QILIMANJARO_AUTH_TOKEN")) | ||
token = "Bearer " + std::string(auth_token); | ||
else | ||
token = "Bearer "; | ||
|
||
std::map<std::string, std::string> headers{ | ||
{"Authorization", token}, | ||
{"Content-Type", "application/json"}, | ||
{"User-Agent", "cudaq/0.12.0"}, | ||
{"Connection", "keep-alive"}, | ||
{"Accept", "*/*"}}; | ||
|
||
return headers; | ||
} | ||
|
||
ServerJobPayload | ||
QilimanjaroServerHelper::createJob(std::vector<KernelExecution> &circuitCodes) { | ||
std::vector<ServerMessage> tasks; | ||
|
||
for (auto &circuitCode : circuitCodes) { | ||
ServerMessage message; | ||
message["machine"] = backendConfig.at("machine"); | ||
message["shots"] = shots; | ||
message["sequence"] = nlohmann::json::parse(circuitCode.code); | ||
tasks.push_back(message); | ||
} | ||
|
||
cudaq::info("Created job payload for Qilimanjaro, targeting device {}", | ||
backendConfig.at("machine")); | ||
|
||
// Return a tuple containing the job path, headers, and the job message | ||
return std::make_tuple(speqtrumApiUrl + "/execute", getHeaders(), tasks); | ||
} | ||
|
||
std::string QilimanjaroServerHelper::extractJobId(ServerMessage &postResponse) { | ||
return postResponse["data"]["id"].get<std::string>(); | ||
} | ||
|
||
std::string QilimanjaroServerHelper::constructGetJobPath(std::string &jobId) { | ||
return speqtrumApiUrl + "/jobs/" + jobId; | ||
} | ||
|
||
std::string | ||
QilimanjaroServerHelper::constructGetJobPath(ServerMessage &postResponse) { | ||
return speqtrumApiUrl + "/jobs/" + postResponse["data"]["id"].get<std::string>(); | ||
} | ||
|
||
bool QilimanjaroServerHelper::jobIsDone(ServerMessage &getJobResponse) { | ||
std::unordered_set<std::string> terminal_states = {"COMPLETED", "ERROR", "CANCELED"}; | ||
auto jobStatus = getJobResponse["data"]["status"].get<std::string>(); | ||
return terminal_states.find(jobStatus) != terminal_states.end(); | ||
} | ||
|
||
sample_result QilimanjaroServerHelper::processResults(ServerMessage &postJobResponse, | ||
std::string &jobId) { | ||
auto status = postJobResponse["data"]["status"].get<std::string>(); | ||
if (status != "COMPLETED") | ||
throw std::runtime_error("Job status: " + status); | ||
|
||
std::vector<ExecutionResult> results; | ||
auto jobs = postJobResponse["data"]["result"]; | ||
for (auto &job : jobs) { | ||
std::unordered_map<std::string, std::size_t> result; | ||
for (auto &[bitstring, count] : job.items()) { | ||
auto r_bitstring = bitstring; | ||
result[r_bitstring] = count; | ||
} | ||
results.push_back(ExecutionResult(result)); | ||
} | ||
|
||
return sample_result(results); | ||
} | ||
|
||
} // namespace cudaq | ||
|
||
// Register the Qilimanjaro server helper in the CUDA-Q server helper factory | ||
CUDAQ_REGISTER_TYPE(cudaq::ServerHelper, cudaq::QilimanjaroServerHelper, qilimanjaro) |
67 changes: 67 additions & 0 deletions
67
runtime/cudaq/platform/qilimanjaro/QilimanjaroServerHelper.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/****************************************************************-*- C++ -*-**** | ||
* Copyright (c) 2025 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#include "common/ServerHelper.h" | ||
#include "nlohmann/json.hpp" | ||
|
||
namespace cudaq { | ||
|
||
class QilimanjaroServerHelper : public ServerHelper { | ||
protected: | ||
/// @brief Server helper implementation for communicating with the REST API of | ||
/// Qilimanjaro's SpeQtrum platform. | ||
const std::string speqtrumApiUrl = "https://qilimanjaro.ddns.net/public-api/api/v1"; | ||
|
||
public: | ||
/// @brief Returns the name of the server helper. | ||
const std::string name() const override { return "qilimanjaro"; } | ||
|
||
/// @brief Initializes the server helper with the provided backend | ||
/// configuration. | ||
void initialize(BackendConfig config) override; | ||
|
||
/// @brief Return the POST/GET required headers. | ||
/// @return | ||
RestHeaders getHeaders() override; | ||
|
||
/// @brief Creates a quantum computation job using the provided kernel | ||
/// executions and returns the corresponding payload. | ||
ServerJobPayload | ||
createJob(std::vector<KernelExecution> &circuitCodes) override; | ||
|
||
/// @brief Extract the job id from the server response from posting the job. | ||
std::string extractJobId(ServerMessage &postResponse) override; | ||
|
||
/// @brief Get the specific path required to retrieve job results. Construct | ||
/// specifically from the job id. | ||
std::string constructGetJobPath(std::string &jobId) override; | ||
|
||
/// @brief Get the specific path required to retrieve job results. Construct | ||
/// from the full server response message. | ||
std::string constructGetJobPath(ServerMessage &postResponse) override; | ||
|
||
/// @brief Get the jobs results polling interval. | ||
/// @return | ||
std::chrono::microseconds | ||
nextResultPollingInterval(ServerMessage &postResponse) override { | ||
return std::chrono::seconds(1); | ||
} | ||
|
||
/// @brief Return true if the job is done. | ||
bool jobIsDone(ServerMessage &getJobResponse) override; | ||
|
||
/// @brief Given a successful job and the success response, | ||
/// retrieve the results and map them to a sample_result. | ||
/// @param postJobResponse | ||
/// @param jobId | ||
/// @return | ||
sample_result processResults(ServerMessage &postJobResponse, | ||
std::string &jobId) override; | ||
}; | ||
|
||
} // namespace cudaq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. # | ||
# All rights reserved. # | ||
# # | ||
# This source code and the accompanying materials are made available under # | ||
# the terms of the Apache License 2.0 which accompanies this distribution. # | ||
# ============================================================================ # | ||
|
||
name: qilimanjaro | ||
description: "CUDA-Q target for qilimanjaro." | ||
config: | ||
# Tell DefaultQuantumPlatform what QPU subtype to use | ||
platform-qpu: qilimanjaro | ||
# Add the qilimanjaro-qpu library to the link list | ||
link-libs: ["-lcudaq-qilimanjaro-qpu"] | ||
# Allow evolve API in C++ | ||
preprocessor-defines: ["-D CUDAQ_ANALOG_TARGET"] | ||
# Library mode is only for simulators, physical backends must turn this off | ||
library-mode: false | ||
# Tell NVQ++ to generate glue code to set the target backend name | ||
gen-target-backend: true | ||
|
||
target-arguments: | ||
- key: machine | ||
required: false | ||
type: string | ||
platform-arg: machine | ||
help-string: "Specify the Qilimanjaro machine." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit