API Reference: qbraid.runtime.braket

Installation & Setup

To interface with Amazon Braket supported devices, install the braket extra:

pip install 'qbraid[braket]'

Then, follow instructions to configure your AWS credentials. Or, install the qBraid-CLI and use commands to enable Amazon Braket jobs using your qBraid API key.

Basic Usage

Submit a Quantum Task to an AWS device using the BraketProvider:

from qbraid.runtime import BraketProvider

provider = BraketProvider()

provider.get_devices()
# [<qbraid.runtime.aws.device.BraketDevice('.../qpu/ionq/Aria-1')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../qpu/ionq/Aria-2')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../qpu/rigetti/Aspen-M-3')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../qpu/ionq/Forte-1')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../qpu/ionq/Harmony')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../qpu/oqc/Lucy')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../quantum-simulator/amazon/sv1')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../quantum-simulator/amazon/tn1')>,
#  <qbraid.runtime.aws.device.BraketDevice('.../quantum-simulator/amazon/dm1')>]

device = provider.get_device("arn:aws:braket:::device/quantum-simulator/amazon/sv1")

type(device)
# qbraid.runtime.aws.device.BraketDevice

device.metadata()
# {'device_id': 'arn:aws:braket:::device/quantum-simulator/amazon/sv1',
#  'device_type': 'SIMULATOR',
#  'num_qubits': 34,
#  'provider_name': 'Amazon Braket',
#  'status': 'ONLINE',
#  'queue_depth': 0}

Now that we’ve instantiated our device, in this case the AWS SV1 simulator, we can construct a quantum circuit and submit a task using the .run method:

from braket.circuits import Circuit

circuit = Circuit().h(0).cnot(0, 1)
job = device.run(circuit, shots=10)

We now have job which is of type BraketQuantumTask, which inherits from QuantumJob. To see the results, we can do the following:

res = job.result()

res.data.get_counts()
# {'00': 6, '11': 4}

res.data.measurements
# array([[0, 0],
#        [0, 0],
#        [1, 1],
#        [1, 1],
#        [0, 0],
#        [0, 0],
#        [0, 0],
#        [1, 1],
#        [0, 0],
#        [0, 0]])

See how to visualize these results in the Visualization section.