Skip to content

Commit d893046

Browse files
[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 <[email protected]> * Update runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp Co-authored-by: Ryan Shaffer <[email protected]> Signed-off-by: Pradnya Khalate <[email protected]> --------- Signed-off-by: Pradnya Khalate <[email protected]> Signed-off-by: Pradnya Khalate <[email protected]> Co-authored-by: Ryan Shaffer <[email protected]>
1 parent f41a736 commit d893046

File tree

4 files changed

+12
-78
lines changed

4 files changed

+12
-78
lines changed

python/tests/backends/test_braket.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
@pytest.fixture(scope="session", autouse=True)
2222
def do_something():
23-
device_arn = "arn:aws:braket:::device/quantum-simulator/amazon/sv1"
24-
cudaq.set_target("braket", machine=device_arn)
23+
cudaq.set_target("braket")
2524
yield "Running the tests."
2625
cudaq.__clearKernelRegistries()
2726
cudaq.reset_target()

runtime/common/BraketServerHelper.h

-34
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,6 @@
1919

2020
namespace cudaq {
2121

22-
const std::string SV1 = "sv1";
23-
const std::string DM1 = "dm1";
24-
const std::string TN1 = "tn1";
25-
const std::string ARIA1 = "aria1";
26-
const std::string ARIA2 = "aria2";
27-
const std::string GARNET = "garnet";
28-
const std::string AQUILA = "aquila";
29-
30-
const std::string SV1_ARN =
31-
"arn:aws:braket:::device/quantum-simulator/amazon/sv1";
32-
const std::string DM1_ARN =
33-
"arn:aws:braket:::device/quantum-simulator/amazon/dm1";
34-
const std::string TN1_ARN =
35-
"arn:aws:braket:::device/quantum-simulator/amazon/tn1";
36-
const std::string ARIA1_ARN =
37-
"arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1";
38-
const std::string ARIA2_ARN =
39-
"arn:aws:braket:us-east-1::device/qpu/ionq/Aria-2";
40-
const std::string GARNET_ARN =
41-
"arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet";
42-
const std::string AQUILA_ARN =
43-
"arn:aws:braket:us-east-1::device/qpu/quera/Aquila";
44-
45-
const std::map<std::string, std::string> deviceArns = {
46-
{SV1, SV1_ARN}, {DM1, DM1_ARN}, {TN1, TN1_ARN},
47-
{ARIA1, ARIA1_ARN}, {ARIA2, ARIA2_ARN}, {GARNET, GARNET_ARN},
48-
{AQUILA, AQUILA_ARN}};
49-
50-
const std::map<std::string, uint> deviceQubitCounts = {
51-
{SV1_ARN, 34}, {DM1_ARN, 17}, {TN1_ARN, 50}, {ARIA1_ARN, 25},
52-
{ARIA2_ARN, 25}, {GARNET_ARN, 20}, {AQUILA_ARN, 256}};
53-
54-
const uint DEFAULT_QUBIT_COUNT = 50;
55-
5622
/// @brief The BraketServerHelper class extends the ServerHelper class to handle
5723
/// interactions with the Amazon Braket server for submitting and retrieving
5824
/// quantum computation jobs.

runtime/cudaq/platform/default/rest/helpers/braket/BraketServerHelper.cpp

+10-32
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,12 @@ std::string prepareOpenQasm(std::string source) {
2121

2222
namespace cudaq {
2323

24-
std::string getDeviceArn(const std::string &machine) {
25-
if (machine.starts_with("arn:aws:braket")) {
24+
std::string checkDeviceArn(const std::string &machine) {
25+
if (machine.starts_with("arn:aws:braket"))
2626
return machine;
27-
}
28-
29-
if (deviceArns.contains(machine)) {
30-
return deviceArns.at(machine);
31-
}
32-
33-
std::string knownMachines;
34-
for (const auto &machine : deviceArns)
35-
knownMachines += machine.first + " ";
36-
const auto errorMessage =
37-
fmt::format("Machine \"{}\" is invalid. Machine must be either an Amazon "
38-
"Braket device ARN or one of the known devices: {}",
39-
machine, knownMachines);
27+
const auto errorMessage = fmt::format("Machine \"{}\" is invalid. Machine "
28+
"must be an Amazon Braket device ARN.",
29+
machine);
4030
throw std::runtime_error(errorMessage);
4131
}
4232

@@ -51,31 +41,25 @@ BraketServerHelper::getValueOrDefault(const BackendConfig &config,
5141
// Initialize the Braket server helper with a given backend configuration
5242
void BraketServerHelper::initialize(BackendConfig config) {
5343
cudaq::info("Initializing Amazon Braket backend.");
54-
5544
// Fetch machine info before checking emulate because we want to be able to
56-
// emulate specific machines.
57-
auto machine = getValueOrDefault(config, "machine", SV1);
58-
auto deviceArn = getDeviceArn(machine);
45+
// emulate specific machines, defaults to state vector simulator
46+
auto machine =
47+
getValueOrDefault(config, "machine",
48+
"arn:aws:braket:::device/quantum-simulator/amazon/sv1");
49+
auto deviceArn = checkDeviceArn(machine);
5950
cudaq::info("Running on device {}", deviceArn);
60-
6151
config["defaultBucket"] = getValueOrDefault(config, "default_bucket", "");
6252
config["deviceArn"] = deviceArn;
63-
config["qubits"] = deviceQubitCounts.contains(deviceArn)
64-
? deviceQubitCounts.at(deviceArn)
65-
: DEFAULT_QUBIT_COUNT;
6653
if (!config["shots"].empty())
6754
this->setShots(std::stoul(config["shots"]));
68-
6955
const auto emulate_it = config.find("emulate");
7056
if (emulate_it != config.end() && emulate_it->second == "true") {
7157
cudaq::info("Emulation is enabled, ignore all Amazon Braket connection "
7258
"specific information.");
7359
backendConfig = std::move(config);
7460
return;
7561
}
76-
7762
parseConfigForCommonParams(config);
78-
7963
// Move the passed config into the member variable backendConfig
8064
backendConfig = std::move(config);
8165
};
@@ -90,25 +74,19 @@ BraketServerHelper::createJob(std::vector<KernelExecution> &circuitCodes) {
9074
ServerMessage taskRequest;
9175
taskRequest["name"] = circuitCode.name;
9276
taskRequest["deviceArn"] = backendConfig.at("deviceArn");
93-
94-
taskRequest["qubits"] = backendConfig.at("qubits");
9577
taskRequest["input"]["format"] = "qasm2";
9678
taskRequest["input"]["data"] = circuitCode.code;
97-
9879
auto action = nlohmann::json::parse(
9980
"{\"braketSchemaHeader\": {\"name\": \"braket.ir.openqasm.program\", "
10081
"\"version\": \"1\"}, \"source\": \"\", \"inputs\": {}}");
10182
action["source"] = prepareOpenQasm(circuitCode.code);
10283
taskRequest["action"] = action.dump();
10384
taskRequest["shots"] = shots;
104-
10585
tasks.push_back(taskRequest);
10686
}
107-
10887
cudaq::info("Created job payload for braket, language is OpenQASM 2.0, "
10988
"targeting device {}",
11089
backendConfig.at("deviceArn"));
111-
11290
return ret;
11391
};
11492

runtime/cudaq/platform/quera/QuEraServerHelper.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,14 @@ namespace cudaq {
1313

1414
void QuEraServerHelper::initialize(BackendConfig config) {
1515
cudaq::info("Initializing QuEra via Amazon Braket.");
16-
1716
// Hard-coded for now
18-
auto machine = AQUILA;
19-
auto deviceArn = AQUILA_ARN;
20-
17+
auto deviceArn = "arn:aws:braket:us-east-1::device/qpu/quera/Aquila";
2118
cudaq::info("Running on device {}", deviceArn);
22-
2319
config["defaultBucket"] = getValueOrDefault(config, "default_bucket", "");
2420
config["deviceArn"] = deviceArn;
25-
config["qubits"] = deviceQubitCounts.contains(deviceArn)
26-
? deviceQubitCounts.at(deviceArn)
27-
: DEFAULT_QUBIT_COUNT;
2821
if (!config["shots"].empty())
2922
this->setShots(std::stoul(config["shots"]));
30-
3123
parseConfigForCommonParams(config);
32-
3324
// Move the passed config into the member variable backendConfig
3425
backendConfig = std::move(config);
3526
}

0 commit comments

Comments
 (0)