author | description | ms.author | ms.date | ms.service | ms.subservice | ms.topic | title | uid |
---|---|---|---|---|---|---|---|---|
KittyYeungQ |
Explanation of how to create applications for the different targets of Azure-Quantum |
kitty |
02/01/2021 |
azure-quantum |
core |
article |
Create and run Q# applications in Azure Quantum |
microsoft.quantum.create-applications |
This guide outlines the process to create a Q# application and run it on the different quantum computing targets available in Azure Quantum. To see what types of quantum computing targets Azure Quantum offers, you can check our article Targets in Azure Quantum
Full profile targets can run any Q# program, meaning you can write programs without functionality restrictions. Azure Quantum does not provide any target with this profile yet, but you can try any Q# program locally using the full state simulator or the resources estimator from the QDK.
If you need help setting up your environment to run Q# programs locally, see Getting started with the QDK.
You can also explore different Q# code samples to run locally with the QDK.
No Control Flow profile targets can run a wide variety of Q# applications, with
the constraint that they can't use results from qubit measurements to control
the program flow. More specifically, values of type Result
do not support
equality comparison.
For example, this operation can NOT be run on a No Control Flow target:
operation SetQubitState(desired : Result, q : Qubit) : Result {
if (desired != M(q)) {
X(q);
}
}
Trying to run this operation on a No Control Flow target will fail because it evaluates a comparison between two results (desired != M(q)
)
to control the computation flow with an if
statement.
Note
Currently, there is an additional limitation for this type of profile target: you can't apply operations on qubits that have been measured, even if you don't use the results to control the program flow. This limitation is not inherent to this profile type but is circumstantial to the situation of the Limited Preview.
Presently, these No Control Flow targets are available for Azure Quantum:
- Provider: IonQ
- IonQ simulator (
ionq.simulator
) - IonQ QPU: (
ionq.qpu
)
- IonQ simulator (
Follow these steps in this section to create an application to run in IonQ targets.
- Install the QDK.
- A Quantum Workspace with IonQ listed as a provider. To create a Workspace, see Create an Azure Quantum workspace.
-
Create a Q# application using the Q# project template.
-
Open the
*.csproj
file in a text editor (for example, VS Code) and edit the file to:- Make sure the project points to the latest version of the QDK. You can verify the latest version in the official QDK Release Notes.
- Add a line specifying the target:
- IonQ QPU:
<ExecutionTarget>ionq.qpu</ExecutionTarget>
- IonQ simulator:
<ExecutionTarget>ionq.simulator</ExecutionTarget>
- IonQ QPU:
Your
*.csproj
file should look something like this:<Project Sdk="Microsoft.Quantum.Sdk/X.XX.XXXXXXXX"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <ExecutionTarget>ionq.qpu</ExecutionTarget> </PropertyGroup> </Project>
where
X.XX.XXXXXXXX
is a place holder for the number of the latest version of the QDK. -
Write your Q# program, keeping in mind that you cannot compare measurement results to control the program flow.
-
Build and run your program locally using the QDK local targets. These will let you know if your Q# application can run in IonQ's targets by checking the fulfillment of the No Control Flow restrictions and calculating the needed resources.
- You can run your Q# program locally using the QDK full state simulator by
using the command
dotnet run
. Since you selected theExecutionTarget
in the*.csproj
file, the console output will warn you if you created a file that is not compatible with the No Control Flow profile. - You can use the
resources estimator
to estimate what resources your Q# program requires to run. You invoke the resources estimator with the command:dotnet run --simulator ResourcesEstimator
.
- You can run your Q# program locally using the QDK full state simulator by
using the command
-
Once your Q# program is ready, submit the job to Azure Quantum using your preferred environment by using the target ID
ionq.qpu
for the QPU andionq.simulator
for the simulator.
For more information on how to submit jobs to Azure Quantum, see:
- Submit jobs to Azure Quantum using the Azure CLI.
- Submit jobs to Azure Quantum using Python.
- Submit jobs to Azure Quantum using Q# Jupyter Notebooks
Basic Measurement Feedback profile targets can run a wide variety of Q#
applications, with the constraint that you can only compare values of type Result
as part of conditions within if
statements in operations. The
corresponding conditional blocks may not contain return
or set
statements. This profile type supposes an improvement over No Control Flow profiles, but still is subject to
some limitations.
Currently, Azure Quantum doesn't host any targets with this profile, however, we are planning to make some available during the Limited Review.
- Now that you know how to create Q# applications, you can learn more details about how to submit jobs to Azure Quantum.
- You can also try the different samples we have available or try to submit your own projects.