Amazon Braket¶
Amazon Braket is a fully managed AWS service which provides Jupyter notebook environments, high-performance quantum circuit simulators, and secure, on-demand access to various quantum computers. To get started users must enable Amazon Braket in their AWS account by following these instructions. To learn more about Amazon Braket, you can view the Amazon Braket Documentation and Amazon Braket Examples. A list of available devices and regions can be found here.
Users can run CUDA-Q programs on Amazon Braket with Hybrid Job. See this guide to get started.
Setting Credentials¶
After enabling Amazon Braket in AWS, set credentials using any of the documented methods. One of the simplest ways is to use AWS CLI.
aws configure
Alternatively, users can set the following environment variables.
export AWS_DEFAULT_REGION="<region>"
export AWS_ACCESS_KEY_ID="<key_id>"
export AWS_SECRET_ACCESS_KEY="<access_key>"
export AWS_SESSION_TOKEN="<token>"
Submission from C++¶
To target quantum kernel code for execution in Amazon Braket,
pass the flag --target braket
to the nvq++
compiler.
By default jobs are submitted to the state vector simulator, SV1
.
nvq++ --target braket src.cpp
To execute your kernels on different device, pass the --braket-machine
flag to the nvq++
compiler
to specify which machine to submit quantum kernels to:
nvq++ --target braket --braket-machine "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet" src.cpp ...
where arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet
refers to IQM Garnet QPU.
To emulate the device locally, without submitting through the cloud,
you can also pass the --emulate
flag to nvq++
.
nvq++ --emulate --target braket src.cpp
To see a complete example for using Amazon Braket backends, take a look at our C++ examples.
Submission from Python¶
The target to which quantum kernels are submitted
can be controlled with the cudaq::set_target()
function.
cudaq.set_target("braket")
By default, jobs are submitted to the state vector simulator, SV1
.
To specify which Amazon Braket device to use, set the machine
parameter.
device_arn = "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet"
cudaq.set_target("braket", machine=device_arn)
where arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet
refers to IQM Garnet QPU.
To emulate the device locally, without submitting through the cloud,
you can also set the emulate
flag to True
.
cudaq.set_target("braket", emulate=True)
The number of shots for a kernel execution can be set through the shots_count
argument to cudaq.sample
. By default, the shots_count
is set to 1000.
cudaq.sample(kernel, shots_count=100)
To see a complete example for using Amazon Braket backends, take a look at our Python examples.
Note
The cudaq.observe
API is not yet supported on the braket
target.