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.braket import BraketProvider
>>> provider = BraketProvider()
>>> provider.get_devices()
[<qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:us-east-1::device/qpu/ionq/Aria-2')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:us-east-1::device/qpu/ionq/Forte-1')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:us-east-1::device/qpu/ionq/Harmony')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:::device/quantum-simulator/amazon/sv1')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:::device/quantum-simulator/amazon/tn1')>,
 <qbraid.runtime.braket.device.BraketDevice('arn:aws:braket:::device/quantum-simulator/amazon/dm1')>]
>>> device = provider.get_device("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
>>> type(device)
qbraid.runtime.braket.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.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.