API Reference: qbraid.runtime.azure

Installation & Setup

To interface with Azure Quantum supported devices, install the azure extra:

pip install 'qbraid[azure]'

Then, follow the Azure Quantum setup instructions to create a workspace and get your credentials.

Authentication Methods

The AzureQuantumProvider can be initialized in several ways:

Using Environment Variables

The simplest method is to set environment variables that will be used to automatically create an Azure Workspace:

# Required workspace configuration
export AZURE_SUBSCRIPTION_ID="your-subscription-id"
export AZURE_RESOURCE_GROUP="your-resource-group"
export AZURE_WORKSPACE_NAME="your-workspace-name"
export AZURE_LOCATION="your-location"  # e.g. "westus"

# Optional authentication credentials
export AZURE_CLIENT_ID="your-client-id"
export AZURE_CLIENT_SECRET="your-client-secret"
export AZURE_TENANT_ID="your-tenant-id"

You can then create the provider without any arguments:

from qbraid.runtime import AzureQuantumProvider

provider = AzureQuantumProvider()  # Uses environment variables

Using Azure Authentication Objects

For more control over authentication, you can directly pass Azure credential or workspace objects:

from azure.identity import ClientSecretCredential
from azure.quantum import Workspace
from qbraid.runtime import AzureQuantumProvider

# Option 1: Using ClientSecretCredential
credential = ClientSecretCredential(
    tenant_id="your-tenant-id",
    client_id="your-client-id",
    client_secret="your-client-secret"
)
provider = AzureQuantumProvider(credential=credential)

# Option 2: Using an existing Workspace object
workspace = Workspace(
    subscription_id="your-subscription-id",
    resource_group="your-resource-group",
    name="your-workspace-name",
    location="your-location",
    credential=credential  # Pass the credential to the Workspace
)
provider = AzureQuantumProvider(workspace=workspace)

The ClientSecretCredential requires:

  1. A tenant ID (Azure Active Directory tenant)
  2. A client ID (Application ID)
  3. A client secret (Application secret)

These values can be obtained by creating an App Registration in your Azure Active Directory. See the Azure authentication documentation for more details on setting up service principal authentication.

Choose the authentication method that best fits your use case and security requirements.

Basic Usage

Submit a Quantum Task to an Azure Quantum device using the AzureQuantumProvider:

from qbraid.runtime import AzureQuantumProvider

provider = AzureQuantumProvider()  # Uses environment variables

# List available devices
provider.get_devices()
# [<qbraid.runtime.azure.device.AzureDevice('ionq.simulator')>,
#  <qbraid.runtime.azure.device.AzureDevice('ionq.qpu')>,
#  <qbraid.runtime.azure.device.AzureDevice('quantinuum.hqs-lt-s1')>,
#  <qbraid.runtime.azure.device.AzureDevice('quantinuum.hqs-lt-s2')>,
#  <qbraid.runtime.azure.device.AzureDevice('quantinuum.h1-1')>]

# Get a specific device
device = provider.get_device("ionq.simulator")

type(device)
# qbraid.runtime.azure.device.AzureDevice

device.metadata()
# {'device_id': 'ionq.simulator',
#  'device_type': 'SIMULATOR',
#  'num_qubits': 29,
#  'provider_name': 'IonQ',
#  'status': 'ONLINE'}

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

from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)

job = device.run(circuit, shots=10)

We now have job which is of type AzureQuantumTask, which inherits from QuantumJob. To see the results:

res = job.result()

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

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

See how to visualize these results in the Visualization section.

Supported Providers

Azure Quantum provides access to quantum hardware and simulators from several providers:

  • IonQ
  • Quantinuum
  • Rigetti
  • QCI

Each provider may have different requirements and capabilities. Refer to the Azure Quantum documentation for more details about specific providers.