Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/NVIDIA/cuda-quantum into fi…
Browse files Browse the repository at this point in the history
…x-for-demo

Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
  • Loading branch information
annagrin committed Jan 31, 2025
2 parents f33a3b9 + d893046 commit 16d8d69
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 78 deletions.
3 changes: 1 addition & 2 deletions python/tests/backends/test_braket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
34 changes: 0 additions & 34 deletions runtime/common/BraketServerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> 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<std::string, uint> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -51,31 +41,25 @@ 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 "
"specific information.");
backendConfig = std::move(config);
return;
}

parseConfigForCommonParams(config);

// Move the passed config into the member variable backendConfig
backendConfig = std::move(config);
};
Expand All @@ -90,25 +74,19 @@ BraketServerHelper::createJob(std::vector<KernelExecution> &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;
};

Expand Down
11 changes: 1 addition & 10 deletions runtime/cudaq/platform/quera/QuEraServerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions runtime/cudaq/qis/pauli_word.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <algorithm>
#include <cstdint>
#include <ctype.h>
#include <string>

Expand Down

0 comments on commit 16d8d69

Please sign in to comment.