Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Use the Microsoft Quantum Development Kit (QDK) extension for Visual Studio Code (VS Code) to submit Q# and OpenQASM programs to Azure Quantum. You can test your program locally, connect to your Azure Quantum workspace, select a provider target, submit the active program, and view its results without writing submission code.
If you use Qiskit, Cirq, PennyLane, or a Python-based Q# or OpenQASM workflow, see Submit jobs with the QDK Python package.
Prerequisites
- An Azure account with an active subscription.
- An Azure Quantum workspace. To create one, see Create an Azure Quantum workspace.
- The latest version of VS Code.
- The latest version of the QDK extension.
For installation details, see Set up the Microsoft Quantum Development Kit.
Note
The examples in this article submit jobs to simulator targets. The targets available to you depend on the providers that you configure in your workspace.
Prepare and test your program
Choose the tab for the language of your source file.
In VS Code, select File > New Text File, and save the file as
Main.qs.Add the following Q# program, which uses the Base QIR target profile.
@EntryPoint(Base) operation Main() : Result { use q = Qubit(); H(q); return MResetZ(q); }Select Run from the code lens above the
Mainoperation to test the program on the local simulator.
Connect to your Azure Quantum workspace
You can connect with a workspace connection string.
- In VS Code, select View > Command Palette.
- Enter QDK: Connect to an Azure Quantum workspace.
- Use a connection string to connect to your Azure Quantum workspace.
- Confirm that your workspace appears under Quantum Workspaces.
Important
Treat a workspace connection string as a secret. Don't store it in source control or share it in plain text.
Select an Azure Quantum target
- In the Microsoft Quantum panel, expand your workspace.
- Expand Providers.
- Expand a provider and review its available targets in your workspace.
- Select a simulator target that accepts your program's input format and QIR target profile.
Tip
Test on a simulator target before you use a paid quantum hardware target. Before your submit to quantum hardware, review the provider pricing and estimate the job cost when the provider supports cost estimation.
Submit your program
- In VS Code, open the Q# or OpenQASM file that you want to submit.
- In the Microsoft Quantum panel, find the target that you selected.
- Select the play icon next to the target.
- Enter a name that identifies the job.
- Enter the number of shots (the number of times to run the program).
- Press Enter to submit the job.
VS Code displays a notification when you submit the job. The time required to complete the job depends on the target and its queue.
Monitor the job and view results
- In the Microsoft Quantum panel, expand Jobs.
- Find the job that you submitted. Hover over the job to view details such as its status and submission time.
- After the job succeeds, select the histogram icon next to the job to display supported results as a histogram. To display or download the raw result, select the text icon.
Result formats differ by provider and target. If the result can't be displayed as a histogram, view the raw output.
For information about job states, cancellation, and output data, see Work with Azure Quantum jobs.
Troubleshoot job submission
If you experience issues with job submission, refer to the following guidance for help.
The target doesn't appear
Confirm that:
- The provider is configured in your workspace.
- The target is currently available.
- You connected to the intended Azure directory, subscription, and workspace.
For information about managing providers, see Add or remove a provider in an Azure Quantum workspace.
The program doesn't compile for the target
The program must use a QIR target profile and operations that the target supports. Review the compiler error, the program's target profile, and the target capabilities. For more information, see Quantum computing target profiles.
The job fails after submission
Open the job details and review the provider error message. Job failures can result from unsupported input, invalid job parameters, provider availability, or quota limits. For common resolutions, see Troubleshoot Azure Quantum.