3
$\begingroup$

I'm interested in learning AWS Braket. Can someone help with basics like creating a circuit and sending a job to the hardware and at the same time how to automatically download the calibration data using python code. For example, IBMQ it is easy to download the calibration data so it is easy to automate the code for IBM. Is there something similar for AWS Braket? In other words I need a method to automate the process of sending jobs and downloading results and the calibration data. Also how to perform compilation to run circuits without further compilation? Thank you

$\endgroup$

1 Answer 1

3
$\begingroup$

Sending a job to hardware

First we import the Amazon Braket SDK modules and define a simple Bell State circuit.

import boto3
from braket.aws import AwsDevice
from braket.circuits import Circuit

# create the circuit
bell = Circuit().h(0).cnot(0, 1)

When running tasks on SV1, TN1, or any QPU, the results of your task are stored in an S3 bucket in your account. Bucket names for Amazon Braket always begin with amazon-braket- followed by other identifying characters you add. If you do not specify a bucket, the Braket SDK creates a default bucket amazon-braket-{region}-{accountID} for you.

# get the account ID
aws_account_id = boto3.client("sts").get_caller_identity()["Account"]
# the name of the bucket
my_bucket = "example-bucket"
# the name of the folder in the bucket
my_prefix = "simulation-output"
s3_folder = (my_bucket, my_prefix)

To run a circuit on the Rigetti Aspen-11 device (or any other QPU), you must provide the location of the S3 bucket you previously selected, as a positional argument in the .run() call.

# choose the Rigetti hardware to run your circuit
device = AwsDevice("arn:aws:braket:::device/qpu/rigetti/Aspen-11")

# execute the circuit
task = device.run(bell, s3_folder, shots=100)

Reference:

Downloading the results

You can download results using the download_file method of the boto3 s3 client. It accepts the names of the bucket and object to download and the filename to save the file to.

import boto3

s3 = boto3.client('s3')
s3.download_file('BUCKET_NAME', 'OBJECT_NAME', 'FILE_NAME')

The download_fileobj method accepts a writeable file-like object. The file object must be opened in binary mode, not text mode.

s3 = boto3.client('s3')
with open('FILE_NAME', 'wb') as f:
    s3.download_fileobj('BUCKET_NAME', 'OBJECT_NAME', f)

Reference:

Downloading device calibration data

Calibration data can be accessed through the device's properties attribute:

data = device.properties.dict()

You can then dump into a json file, or handle it however else is most convenient.

import json

with open('calibration-data.json', 'w') as f:
    json.dump(data, f)

Reference:

Performing compilation

When you run a quantum circuit on quantum computers from Rigetti or Oxford Quantum Circuits (OQC), you can use verbatim compilation to direct the compiler to run your circuits exactly as defined, without any modifications.

When using verbatim compilation, it is advisable to check the topology of the device to ensure that gates are called on connected qubits and that the circuit uses the native gates supported on the hardware.

from braket.device_schema.device_action_properties import DeviceActionType
device.properties.action[DeviceActionType.JAQCD].supportedOperations

See Verbatim_Compilation.ipynb from the amazon-braket-examples repo for example usage.

Reference:

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.