Integrated hybrid computing
Integrated hybrid computing brings the classical and quantum processes together, allowing classical code to control the execution of quantum operations based on mid-circuit measurements while the physical qubits remain alive. Using common programming techniques, such as nested conditionals, loops, and function calls, a single quantum program can run complex problems, reducing the number of shots needed. Using qubit reuse techniques, larger programs can run on machines utilizing a smaller number of qubits.
Important
Integrated hybrid quantum computing isn't currently supported by the Modern Quantum Development Kit (Modern QDK) extension for Visual Studio Code, along with other components in the examples on this page, such as the IQ# kernel, the %azure
magic command, or the qsharp.azure
module. To run integrated hybrid jobs, use the Microsoft Quantum Development Kit (Classic QDK). For more information, see Continue working in the Classic QDK.
For more discussion, see:
- Granade & Weibe, "Using Random Walks for Iterative Phase Estimation".
- Lubinski, et al., "Advancing Hybrid Quantum–Classical Computation with Real-Time Execution"
Supported targets
Currently, the integrated hybrid computing model in Azure Quantum is supported on Quantinuum targets.
Quantinuum
Supported feature | Notes |
---|---|
Classical loops | Bounded loops only |
Arbitrary control flow | Use of if/else branching |
Mid-circuit measurement | Utilizes classical register resources |
Qubit reuse | N/A |
Real-time classical compute | 32-bit unsigned integer arithmetic Utilizes classical register resources |
Get started
To start exploring integrated hybrid programming, we suggest walking through the samples in this article, or explore the Hybrid quantum computing tab in the Samples gallery of the Azure Quantum portal.
Submitting integrated hybrid jobs
When submitting an integrated hybrid job, you need to add a target capability parameter after specifying the target. Other than that, integrated hybrid programs on Azure Quantum are run and managed just as regular quantum jobs. Each job has a single job ID and the result is a single histogram.
Important
Integrated hybrid quantum computing isn't currently supported by the Modern Quantum Development Kit (Modern QDK) extension for Visual Studio Code, along with other components in the examples on this page, such as the IQ# kernel, the %azure
magic command, or the qsharp.azure
module. To run integrated hybrid jobs, use the Microsoft Quantum Development Kit (Classic QDK). For more information, see Continue working in the Classic QDK.
IQ#
When using the IQ# kernel in a Jupyter Notebook, use the %azure.target-capability magic command with the AdaptiveExecution
parameter.
%azure.target quantinuum.sim.h1-1e
%azure.target-capability AdaptiveExecution
Python + Q#
When using the qsharp Python package, use the qsharp.azure.target_capability
function with the AdaptiveExecution
parameter.
qsharp.azure.target("quantinuum.sim.h1-1e")
qsharp.azure.target_capability("AdaptiveExecution")
Azure CLI
When using the Azure CLI to submit a job, add the --target-capability
parameter with the value AdaptiveExecution
.
az quantum job submit \
--target-capability AdaptiveExecution \
--target-id quantinuum.sim.h1-1e \
--job-name IterativePhaseEstimation \
--shots 100 \
--output table
Submitting integrated hybrid jobs within a session
You can combine multiple integrated hybrid jobs within a session using Q# and Python. When submitting a session, add the targetCapability
input parameter with the value AdaptiveExecution
.
with target.open_session(name="Q# session") as session:
target.submit(input_data=QuantumOperation, name="Job 1", input_params={"count":100, "targetCapability":"AdaptiveExecution"}) # First job submission
target.submit(input_data=QuantumOperation, name="Job 2", input_params={"count":200, "targetCapability":"AdaptiveExecution"}) # Second job submission
target.submit(input_data=QuantumOperation, name="Job 3", input_params={"count":300, "targetCapability":"AdaptiveExecution"}) # Third job submission
For more information, see Get started with sessions.
Note
Although sessions are available for all quantum computing hardware providers, notice that integrated hybrid quantum computing jobs are currently supported on Quantinuum targets.
Estimating the cost of an integrated hybrid job
You can estimate the cost of running an integrated hybrid job on Quantinuum hardware by running it on an emulator first.
After a successful run on the emulator:
- In your Azure Quantum workspace, select Job management.
- Select the job you submitted.
- In the Job details popup, select Cost Estimation to view how many eHQCs (Quantinuum emulator credits) were used. This number translates directly to the number of HQCs (Quantinuum quantum credits) that are needed to run the job on Quantinuum hardware.
Note
Quantinuum unrolls the entire circuit and calculates the cost on all code paths, whether they are conditionally executed or not.
Integrated hybrid samples
The following samples demonstrate the current feature set for integrated hybrid computing.
- Verify an entangled GHZ state
- Three-qubit repetition
- Iterative phase estimation
Prerequisites
- If you are new to Azure Quantum, you will need an Azure subscription and an Azure Quantum workspace to run the samples against quantum hardware. For more information, see Create an Azure Quantum workspace.
- VS Code and the Quantum Development Kit set up in your local environment. For more information, see Set up the Quantum Development Kit.
- Ensure that VS Code has latest version of the Quantum Development Kit (0.27.258160).
- In VS Code, select Ctrl + Shift + X and search for "Microsoft Quantum Development Kit".
The samples in this article are set up to run on Visual Studio (VS) Code and use the built-in Azure command line interface (CLI) to submit the job to Azure Quantum. To run the Jupyter Notebook version of these and other samples, login in to your Azure portal workspace and view the samples from the Hybrid quantum computing tab in the Samples gallery. You can either run the notebook in the cloud or download it and run it locally.
To troubleshoot issues with integrated hybrid programs, see Troubleshooting integrated hybrid.
In this sample, you will discover how to blend classical and quantum instructions in the same program, all fully processed by the quantum computing backend.
Features to note about this sample:
- The loop and qubit measurements happen while the qubits remain coherent.
- The routine mixes classical and quantum compute operations.
- You do not need to learn to program for specialized high-performance hardware running next to the QPU (such as FPGAs).
- Running an equivalent program without the integrated hybrid features would require returning every intermediate measurement result and then running post-processing on the data.
Create a VS Code project
In VS Code, create a new Q# standalone console application project named CheckGHZ.
- Select View > Command Pallete > Q#: Create new project > Standalone console application
Replace the configuration in CheckGHZ.csproj with the following:
<Project Sdk="Microsoft.Quantum.Sdk/0.27.258160"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ExecutionTarget>quantinuum</ExecutionTarget> <TargetCapability>AdaptiveExecution</TargetCapability> </PropertyGroup> </Project>
Replace the code in Program.qs with the following:
namespace Microsoft.Quantum.Samples { open Microsoft.Quantum.Measurement; open Microsoft.Quantum.Intrinsic; /// # Summary /// Counts the number of times measurements of a prepared GHZ state did not match the expected correlations. @EntryPoint() // The EntryPoint attribute is used to mark that this operation is where a quantum program will start running. operation CheckGHZ() : Int { use q = Qubit[3]; mutable mismatch = 0; for _ in 1..10 { // Prepare the GHZ state. H(q[0]); CNOT(q[0], q[1]); CNOT(q[1], q[2]); // Measures and resets the 3 qubits let (r0, r1, r2) = (MResetZ(q[0]), MResetZ(q[1]), MResetZ(q[2])); // Adjusts classical value based on qubit measurement results if not (r0 == r1 and r1 == r2) { set mismatch += 1; } } return mismatch; } }
From a terminal window in VS Code, connect to your Azure Quantum workspace and set the default resources.
az login
Note
Your Azure subscription ID, resource group, and workspace name can be listed in the terminal window after logging in by running az quantum workspace list. Alternately, you can find them in the Azure portal on the Overview page of your Azure Quantum workspace.
az account set --subscription <MySubscriptionID> az quantum workspace set --resource-group <MyResourceGroup> --workspace <MyWorkspace> --location <MyLocation>
Submit the job and view the results. This run uses approximately 10.65 eHQCs (Quantinuum emulator billing units)
az quantum job submit \ --target-id quantinuum.sim.h1-1e \ --job-name CheckGHZ \ --target-capability AdaptiveExecution \ --shots 50
az quantum job output \ -o table \ --job-id [job-id]
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for