How to adapt Qiskit samples to run on Azure Quantum
Article
If you have some experience with quantum computing or are just starting, it is likely that you use some samples from Qiskit.org. This article shows you how to adapt any Qiskit sample to run against any of the Azure Quantum backends. You can either download the sample or copy the code to a new notebook.
Prerequisites
An Azure account with an active subscription. If you don't have an Azure account, register for free and sign up for a pay-as-you-go subscription.
Log in to the Azure portal and select your Azure Quantum workspace.
In the left blade, select Notebooks and click My Notebooks.
Click Upload New if you've downloaded a sample, or click Add New to copy the code to a new notebook.
Locate the default backend
Most samples are configured to run by default against the aer_simulator, which is a great way to get started.
Locate the cell that has a line that defines the backend, for example, backend = Aer.get_backend('aer_simulator').
Comment out that line.
Create an Azure Quantum backend
Click + Code to add a new code cell before the code sample.
Replace the existing backend with an Azure Quantum backend. The following code configures an Azure Quantum backend from one of the providers available in your Azure Quantum workspace. For example, if you want to run the sample against a Quantinuum processor, use backend = quantinuum_qpu_backend.
import azure.quantum
from azure.quantum.qiskit import AzureQuantumProvider
workspace = Workspace(
resource_id = "", # Add the resourceID of your workspace
location = "" # Add the location of your workspace (for example "westus")
)
provider = AzureQuantumProvider(workspace)
# Create IonQ simulator and QPU backends
ionq_simulator_backend = provider.get_backend("ionq.simulator")
ionq_qpu_backend = provider.get_backend("ionq.qpu.aria-1")
# Create Rigetti simulator backend
rigetti_simulator_backend = provider.get_backend("rigetti.sim.qvm")
rigetti_qpu_backend = provider.get_backend("rigetti.qpu.ankaa-9q-3")
# Create Quantinuum simulator and QPU backends
quantinuum_simulator_backend = provider.get_backend("quantinuum.sim.h1-1e")
quantinuum_qpu_backend = provider.get_backend("quantinuum.qpu.h1-1")
# Set your backend of choice
backend = ionq_simulator_backend
Note
Azure Quantum defaults to QIR for the backends. If you need to use a passthrough backend, use the gateset parameter with the get_backend method. For more information, see Native gates support and usage.
Note
The location and resource ID of your workspace can be found in the Overview tab of your Azure Quantum workspace.
Verify the update
Click on Run all on the top left of the notebook and verify that you have jobs being queued under Job management.