diff --git a/CMakeLists.txt b/CMakeLists.txt index 496447a8b6..ebbbbd1654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,9 +93,9 @@ if (CUDAQ_ENABLE_REST AND NOT DEFINED CUDAQ_ENABLE_REMOTE_SIM) endif() endif() -# Enable AWS backends by default. +# Enable Amazon Braket backends by default. if (NOT DEFINED CUDAQ_ENABLE_BRAKET_BACKEND) - set(CUDAQ_ENABLE_BRAKET_BACKEND ON CACHE BOOL "Enable building AWS backends.") + set(CUDAQ_ENABLE_BRAKET_BACKEND ON CACHE BOOL "Enable building AWS SDK for Amazon Braket backends.") endif() # Generate a CompilationDatabase (compile_commands.json file) for our build, diff --git a/docs/sphinx/using/examples/hardware_providers.rst b/docs/sphinx/using/examples/hardware_providers.rst index 076a4fed43..96fbc559f2 100644 --- a/docs/sphinx/using/examples/hardware_providers.rst +++ b/docs/sphinx/using/examples/hardware_providers.rst @@ -1,9 +1,25 @@ Using Quantum Hardware Providers ----------------------------------- -CUDA-Q contains support for using a set of hardware providers (IonQ, IQM, OQC, ORCA Computing and Quantinuum). -For more information about executing quantum kernels on different hardware backends, please take a look -at :doc:`hardware <../backends/hardware>`. +CUDA-Q contains support for using a set of hardware providers (Amazon Braket, +IonQ, IQM, OQC, ORCA Computing, Quantinuum and QuEra Computing). +For more information about executing quantum kernels on different hardware +backends, please take a look at :doc:`hardware <../backends/hardware>`. + +Amazon Braket +================================== + +The following code illustrates how to run kernels on Amazon Braket's backends. + +.. tab:: Python + + .. literalinclude:: ../../targets/python/braket.py + :language: python + +.. tab:: C++ + + .. literalinclude:: ../../targets/cpp/braket.cpp + :language: cpp IonQ ================================== diff --git a/runtime/common/BraketExecutor.h b/runtime/common/BraketExecutor.h index a3d432d5ad..05a13656d8 100644 --- a/runtime/common/BraketExecutor.h +++ b/runtime/common/BraketExecutor.h @@ -1,4 +1,4 @@ -/******************************************************************************* +/****************************************************************-*- C++ -*-**** * Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. * * All rights reserved. * * * @@ -7,27 +7,22 @@ ******************************************************************************/ #pragma once + +#include "common/BraketServerHelper.h" #include "common/Executor.h" #include "common/FmtCore.h" +#include "common/Logger.h" #include "common/MeasureCounts.h" #include "cudaq.h" - -#include -#include - -#include - #include -#include -#include - +#include #include #include #include - -#include "common/BraketServerHelper.h" -#include "common/Logger.h" - +#include +#include +#include +#include #include #include #include diff --git a/runtime/common/BraketServerHelper.h b/runtime/common/BraketServerHelper.h index 32f0d4695e..5f008f1a5b 100644 --- a/runtime/common/BraketServerHelper.h +++ b/runtime/common/BraketServerHelper.h @@ -1,4 +1,4 @@ -/******************************************************************************* +/****************************************************************-*- C++ -*-**** * Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. * * All rights reserved. * * * diff --git a/targettests/braket/sudoku_2x2-1.cpp b/targettests/braket/sudoku_2x2-1.cpp deleted file mode 120000 index 09aa81848d..0000000000 --- a/targettests/braket/sudoku_2x2-1.cpp +++ /dev/null @@ -1 +0,0 @@ -../execution/sudoku_2x2-1.cpp \ No newline at end of file diff --git a/targettests/braket/sudoku_2x2-bit_names.cpp b/targettests/braket/sudoku_2x2-bit_names.cpp deleted file mode 120000 index 15e2b47ae2..0000000000 --- a/targettests/braket/sudoku_2x2-bit_names.cpp +++ /dev/null @@ -1 +0,0 @@ -../execution/sudoku_2x2-bit_names.cpp \ No newline at end of file diff --git a/targettests/braket/sudoku_2x2-reg_name.cpp b/targettests/braket/sudoku_2x2-reg_name.cpp deleted file mode 120000 index 367a2098f4..0000000000 --- a/targettests/braket/sudoku_2x2-reg_name.cpp +++ /dev/null @@ -1 +0,0 @@ -../execution/sudoku_2x2-reg_name.cpp \ No newline at end of file diff --git a/targettests/braket/sudoku_2x2.cpp b/targettests/braket/sudoku_2x2.cpp deleted file mode 120000 index 23748412f1..0000000000 --- a/targettests/braket/sudoku_2x2.cpp +++ /dev/null @@ -1 +0,0 @@ -../execution/sudoku_2x2.cpp \ No newline at end of file diff --git a/unittests/backends/braket/BraketTester.cpp b/unittests/backends/braket/BraketTester.cpp index 89fea28164..b0d04753ae 100644 --- a/unittests/backends/braket/BraketTester.cpp +++ b/unittests/backends/braket/BraketTester.cpp @@ -25,8 +25,7 @@ bool isValidExpVal(double value) { } CUDAQ_TEST(BraketTester, checkSampleSync) { - GTEST_SKIP() << "Fails with: Please make sure all qubits in the qubit " - "register are used for tasks submitted to simulators"; + GTEST_SKIP() << "Amazon Braket credentials required"; std::string home = std::getenv("HOME"); std::string fileName = home + "/FakeCppBraket.config"; auto backendString = @@ -68,8 +67,7 @@ CUDAQ_TEST(BraketTester, checkSampleSyncEmulate) { } CUDAQ_TEST(BraketTester, checkSampleAsync) { - GTEST_SKIP() << "Fails with: Please make sure all qubits in the qubit " - "register are used for tasks submitted to simulators"; + GTEST_SKIP() << "Amazon Braket credentials required"; std::string home = std::getenv("HOME"); std::string fileName = home + "/FakeCppBraket.config"; auto backendString = fmt::format(fmt::runtime(backendStringTemplate), @@ -111,8 +109,8 @@ CUDAQ_TEST(BraketTester, checkSampleAsyncEmulate) { } CUDAQ_TEST(BraketTester, checkSampleAsyncLoadFromFile) { - GTEST_SKIP() << "Fails with: Please make sure all qubits in the qubit " - "register are used for tasks submitted to simulators"; + GTEST_SKIP() << "Fails with: Cannot persist a cudaq::future for a local " + "kernel execution."; std::string home = std::getenv("HOME"); std::string fileName = home + "/FakeCppBraket.config"; auto backendString = fmt::format(fmt::runtime(backendStringTemplate), @@ -148,9 +146,7 @@ CUDAQ_TEST(BraketTester, checkSampleAsyncLoadFromFile) { } CUDAQ_TEST(BraketTester, checkObserveSync) { - GTEST_SKIP() << "Fails with: Device requires all qubits in the program to be " - "measured. This may be caused by declaring non-contiguous " - "qubits or measuring partial qubits"; + GTEST_SKIP() << "Fails with: Cannot observe kernel with measures in it"; std::string home = std::getenv("HOME"); std::string fileName = home + "/FakeCppBraket.config"; auto backendString = fmt::format(fmt::runtime(backendStringTemplate), @@ -164,6 +160,7 @@ CUDAQ_TEST(BraketTester, checkObserveSync) { kernel.x(qubit[0]); kernel.ry(theta, qubit[1]); kernel.x(qubit[1], qubit[0]); + kernel.mz(qubit); using namespace cudaq::spin; cudaq::spin_op h = 5.907 - 2.1433 * x(0) * x(1) - 2.1433 * y(0) * y(1) + @@ -232,78 +229,6 @@ CUDAQ_TEST(BraketTester, checkObserveAsync) { EXPECT_TRUE(isValidExpVal(result.expectation())); } -CUDAQ_TEST(BraketTester, checkObserveAsyncEmulate) { - std::string home = std::getenv("HOME"); - std::string fileName = home + "/FakeCppBraket.config"; - auto backendString = fmt::format(fmt::runtime(backendStringTemplate), - mockPort, fileName, machine); - backendString = - std::regex_replace(backendString, std::regex("false"), "true"); - - auto &platform = cudaq::get_platform(); - platform.setTargetBackend(backendString); - - auto [kernel, theta] = cudaq::make_kernel(); - auto qubit = kernel.qalloc(2); - kernel.x(qubit[0]); - kernel.ry(theta, qubit[1]); - kernel.x(qubit[1], qubit[0]); - - using namespace cudaq::spin; - cudaq::spin_op h = 5.907 - 2.1433 * x(0) * x(1) - 2.1433 * y(0) * y(1) + - .21829 * z(0) - 6.125 * z(1); - auto future = cudaq::observe_async(100000, 0, kernel, h, .59); - - auto result = future.get(); - result.dump(); - - printf("ENERGY: %lf\n", result.expectation()); - EXPECT_TRUE(isValidExpVal(result.expectation())); -} - -CUDAQ_TEST(BraketTester, checkObserveAsyncLoadFromFile) { - GTEST_SKIP() << "Fails with: Device requires all qubits in the program to be " - "measured. This may be caused by declaring non-contiguous " - "qubits or measuring partial qubits"; - std::string home = std::getenv("HOME"); - std::string fileName = home + "/FakeCppBraket.config"; - auto backendString = fmt::format(fmt::runtime(backendStringTemplate), - mockPort, fileName, machine); - - auto &platform = cudaq::get_platform(); - platform.setTargetBackend(backendString); - - auto [kernel, theta] = cudaq::make_kernel(); - auto qubit = kernel.qalloc(2); - kernel.x(qubit[0]); - kernel.ry(theta, qubit[1]); - kernel.x(qubit[1], qubit[0]); - - using namespace cudaq::spin; - cudaq::spin_op h = 5.907 - 2.1433 * x(0) * x(1) - 2.1433 * y(0) * y(1) + - .21829 * z(0) - 6.125 * z(1); - auto future = cudaq::observe_async(kernel, h, .59); - - { - std::ofstream out("saveMeObserve.json"); - out << future; - } - - // Later you can come back and read it in - cudaq::async_result readIn(&h); - std::ifstream in("saveMeObserve.json"); - in >> readIn; - - // Get the results of the read in future. - auto result = readIn.get(); - - std::remove("saveMeObserve.json"); - result.dump(); - - printf("ENERGY: %lf\n", result.expectation()); - EXPECT_TRUE(isValidExpVal(result.expectation())); -} - int main(int argc, char **argv) { std::string home = std::getenv("HOME"); std::string fileName = home + "/FakeCppBraket.config";