From f41a736ce2cae488dca35286c37a9adcd86ce900 Mon Sep 17 00:00:00 2001 From: Bruno Schmitt <7152025+boschmitt@users.noreply.github.com> Date: Thu, 30 Jan 2025 22:11:07 +0100 Subject: [PATCH 1/2] [rt] Add missing header. (#2563) Signed-off-by: boschmitt <7152025+boschmitt@users.noreply.github.com> --- runtime/cudaq/qis/pauli_word.h | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/cudaq/qis/pauli_word.h b/runtime/cudaq/qis/pauli_word.h index f0a56c2a5d..4f410088a4 100644 --- a/runtime/cudaq/qis/pauli_word.h +++ b/runtime/cudaq/qis/pauli_word.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include From d8930461128a9c564d636d7531d21f836eb1a59e Mon Sep 17 00:00:00 2001 From: Pradnya Khalate <148914294+khalatepradnya@users.noreply.github.com> Date: Thu, 30 Jan 2025 20:56:28 -0800 Subject: [PATCH 2/2] [braket] Remove the hardcoded device list and qubit count (#2562) * Manually tested following files: - test_braket.py - test_quera.py - braket.py with IQM/Garnet and IonQ/Forte-1 Signed-off-by: Pradnya Khalate * Update runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp Co-authored-by: Ryan Shaffer <3620100+rmshaffer@users.noreply.github.com> Signed-off-by: Pradnya Khalate <148914294+khalatepradnya@users.noreply.github.com> --------- Signed-off-by: Pradnya Khalate Signed-off-by: Pradnya Khalate <148914294+khalatepradnya@users.noreply.github.com> Co-authored-by: Ryan Shaffer <3620100+rmshaffer@users.noreply.github.com> --- python/tests/backends/test_braket.py | 3 +- runtime/common/BraketServerHelper.h | 34 --------------- .../helpers/braket/BraketServerHelper.cpp | 42 +++++-------------- .../platform/quera/QuEraServerHelper.cpp | 11 +---- 4 files changed, 12 insertions(+), 78 deletions(-) diff --git a/python/tests/backends/test_braket.py b/python/tests/backends/test_braket.py index 320b7c9461..504be54910 100644 --- a/python/tests/backends/test_braket.py +++ b/python/tests/backends/test_braket.py @@ -20,8 +20,7 @@ @pytest.fixture(scope="session", autouse=True) def do_something(): - device_arn = "arn:aws:braket:::device/quantum-simulator/amazon/sv1" - cudaq.set_target("braket", machine=device_arn) + cudaq.set_target("braket") yield "Running the tests." cudaq.__clearKernelRegistries() cudaq.reset_target() diff --git a/runtime/common/BraketServerHelper.h b/runtime/common/BraketServerHelper.h index 306116a09a..8231c1d2e9 100644 --- a/runtime/common/BraketServerHelper.h +++ b/runtime/common/BraketServerHelper.h @@ -19,40 +19,6 @@ namespace cudaq { -const std::string SV1 = "sv1"; -const std::string DM1 = "dm1"; -const std::string TN1 = "tn1"; -const std::string ARIA1 = "aria1"; -const std::string ARIA2 = "aria2"; -const std::string GARNET = "garnet"; -const std::string AQUILA = "aquila"; - -const std::string SV1_ARN = - "arn:aws:braket:::device/quantum-simulator/amazon/sv1"; -const std::string DM1_ARN = - "arn:aws:braket:::device/quantum-simulator/amazon/dm1"; -const std::string TN1_ARN = - "arn:aws:braket:::device/quantum-simulator/amazon/tn1"; -const std::string ARIA1_ARN = - "arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1"; -const std::string ARIA2_ARN = - "arn:aws:braket:us-east-1::device/qpu/ionq/Aria-2"; -const std::string GARNET_ARN = - "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet"; -const std::string AQUILA_ARN = - "arn:aws:braket:us-east-1::device/qpu/quera/Aquila"; - -const std::map deviceArns = { - {SV1, SV1_ARN}, {DM1, DM1_ARN}, {TN1, TN1_ARN}, - {ARIA1, ARIA1_ARN}, {ARIA2, ARIA2_ARN}, {GARNET, GARNET_ARN}, - {AQUILA, AQUILA_ARN}}; - -const std::map deviceQubitCounts = { - {SV1_ARN, 34}, {DM1_ARN, 17}, {TN1_ARN, 50}, {ARIA1_ARN, 25}, - {ARIA2_ARN, 25}, {GARNET_ARN, 20}, {AQUILA_ARN, 256}}; - -const uint DEFAULT_QUBIT_COUNT = 50; - /// @brief The BraketServerHelper class extends the ServerHelper class to handle /// interactions with the Amazon Braket server for submitting and retrieving /// quantum computation jobs. diff --git a/runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp b/runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp index 2176004bbc..70da8f4514 100644 --- a/runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp +++ b/runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp @@ -21,22 +21,12 @@ std::string prepareOpenQasm(std::string source) { namespace cudaq { -std::string getDeviceArn(const std::string &machine) { - if (machine.starts_with("arn:aws:braket")) { +std::string checkDeviceArn(const std::string &machine) { + if (machine.starts_with("arn:aws:braket")) return machine; - } - - if (deviceArns.contains(machine)) { - return deviceArns.at(machine); - } - - std::string knownMachines; - for (const auto &machine : deviceArns) - knownMachines += machine.first + " "; - const auto errorMessage = - fmt::format("Machine \"{}\" is invalid. Machine must be either an Amazon " - "Braket device ARN or one of the known devices: {}", - machine, knownMachines); + const auto errorMessage = fmt::format("Machine \"{}\" is invalid. Machine " + "must be an Amazon Braket device ARN.", + machine); throw std::runtime_error(errorMessage); } @@ -51,21 +41,17 @@ BraketServerHelper::getValueOrDefault(const BackendConfig &config, // Initialize the Braket server helper with a given backend configuration void BraketServerHelper::initialize(BackendConfig config) { cudaq::info("Initializing Amazon Braket backend."); - // Fetch machine info before checking emulate because we want to be able to - // emulate specific machines. - auto machine = getValueOrDefault(config, "machine", SV1); - auto deviceArn = getDeviceArn(machine); + // emulate specific machines, defaults to state vector simulator + auto machine = + getValueOrDefault(config, "machine", + "arn:aws:braket:::device/quantum-simulator/amazon/sv1"); + auto deviceArn = checkDeviceArn(machine); cudaq::info("Running on device {}", deviceArn); - config["defaultBucket"] = getValueOrDefault(config, "default_bucket", ""); config["deviceArn"] = deviceArn; - config["qubits"] = deviceQubitCounts.contains(deviceArn) - ? deviceQubitCounts.at(deviceArn) - : DEFAULT_QUBIT_COUNT; if (!config["shots"].empty()) this->setShots(std::stoul(config["shots"])); - const auto emulate_it = config.find("emulate"); if (emulate_it != config.end() && emulate_it->second == "true") { cudaq::info("Emulation is enabled, ignore all Amazon Braket connection " @@ -73,9 +59,7 @@ void BraketServerHelper::initialize(BackendConfig config) { backendConfig = std::move(config); return; } - parseConfigForCommonParams(config); - // Move the passed config into the member variable backendConfig backendConfig = std::move(config); }; @@ -90,25 +74,19 @@ BraketServerHelper::createJob(std::vector &circuitCodes) { ServerMessage taskRequest; taskRequest["name"] = circuitCode.name; taskRequest["deviceArn"] = backendConfig.at("deviceArn"); - - taskRequest["qubits"] = backendConfig.at("qubits"); taskRequest["input"]["format"] = "qasm2"; taskRequest["input"]["data"] = circuitCode.code; - auto action = nlohmann::json::parse( "{\"braketSchemaHeader\": {\"name\": \"braket.ir.openqasm.program\", " "\"version\": \"1\"}, \"source\": \"\", \"inputs\": {}}"); action["source"] = prepareOpenQasm(circuitCode.code); taskRequest["action"] = action.dump(); taskRequest["shots"] = shots; - tasks.push_back(taskRequest); } - cudaq::info("Created job payload for braket, language is OpenQASM 2.0, " "targeting device {}", backendConfig.at("deviceArn")); - return ret; }; diff --git a/runtime/cudaq/platform/quera/QuEraServerHelper.cpp b/runtime/cudaq/platform/quera/QuEraServerHelper.cpp index 5f949086bb..feb2c33372 100644 --- a/runtime/cudaq/platform/quera/QuEraServerHelper.cpp +++ b/runtime/cudaq/platform/quera/QuEraServerHelper.cpp @@ -13,23 +13,14 @@ namespace cudaq { void QuEraServerHelper::initialize(BackendConfig config) { cudaq::info("Initializing QuEra via Amazon Braket."); - // Hard-coded for now - auto machine = AQUILA; - auto deviceArn = AQUILA_ARN; - + auto deviceArn = "arn:aws:braket:us-east-1::device/qpu/quera/Aquila"; cudaq::info("Running on device {}", deviceArn); - config["defaultBucket"] = getValueOrDefault(config, "default_bucket", ""); config["deviceArn"] = deviceArn; - config["qubits"] = deviceQubitCounts.contains(deviceArn) - ? deviceQubitCounts.at(deviceArn) - : DEFAULT_QUBIT_COUNT; if (!config["shots"].empty()) this->setShots(std::stoul(config["shots"])); - parseConfigForCommonParams(config); - // Move the passed config into the member variable backendConfig backendConfig = std::move(config); }