Skip to content

Amazon Braket loader#

Introduction#

The Amazon Braket loader lets a solver access the Braket device selected for a QCentroid job without hardcoding AWS credentials, regions, S3 locations, or device ARNs in the source code.

Use this loader when your solver builds circuits or tasks with the Amazon Braket SDK.

Import#

from QCentroidLoaders import BraketLoader

Get the selected device#

Call BraketLoader.get_target() when your solver is ready to submit the task:

device = BraketLoader.get_target()

In the platform runtime, this device is resolved from the provider and backend selected by the user when launching the job.

When running locally without platform initialization, BraketLoader.get_target() returns the Amazon Braket LocalSimulator.

Example pattern#

qcentroid.py
from typing import Any
import logging

from braket.circuits import Circuit
from QCentroidLoaders import BraketLoader

logger = logging.getLogger("qcentroid-user-log")
logging.basicConfig()
logger.setLevel(logging.INFO)

def run(
    input_data: dict[str, Any],
    solver_params: dict[str, Any],
    extra_arguments: dict[str, Any],
) -> dict[str, Any]:
    logger.info("Creating Braket circuit...")

    circuit = Circuit().h(0).cnot(0, 1)

    device = BraketLoader.get_target()
    logger.info(f"Using Braket device: {device}")

    shots = solver_params.get("shots", 100)

    logger.info("Sending task to Amazon Braket...")
    task = device.run(circuit, shots=shots)

    logger.info("Obtaining task result...")
    result = task.result()

    counts = dict(result.measurement_counts)
    logger.info(f"Result from Braket device: {counts}")

    return {
        "status": "ok",
        "provider": "amazon-braket",
        "device": str(device),
        "result": counts,
    }

Platform execution#

When this solver runs in QCentroid:

  1. The user selects the solver and the Amazon Braket device in the dashboard or API.
  2. The platform injects the required provider credentials and runtime configuration.
  3. BraketLoader.get_target() returns the configured Braket device.
  4. The solver submits the task and returns the result to QCentroid.

Local execution#

For local development, install the local loader package from the public QCentroid loaders repository when it is available:

pip install git+<loaders-repository-url>

Then configure your AWS and Braket credentials as described in that repository if you want to run against a remote Braket device locally. If you do not initialize the loader with a remote device, the loader returns LocalSimulator.

Best practices#

  • Keep shots configurable through solver_params so users can control execution cost.
  • Test with a local simulator before submitting to managed simulators or quantum hardware.
  • Avoid logging AWS credentials, S3 paths that contain sensitive information, or provider secrets.

QCentroid Loaders overview

Amazon Braket cost control best practices