-
Notifications
You must be signed in to change notification settings - Fork 97
Editing Q# in VS Code
The recommended way of developing Q# code is in VS Code with the Azure Quantum Developer Kit extension. This extension provides both a rich Q# development environment and Azure Quantum integration. Features of the extension include:
- Syntax highlighting and basic syntax features (e.g. brace matching)
- Q# cell support in Jupyter notebooks. The extension will detect
%%qsharp
magic cells and automatically update the cell language to Q# - Error checking in Q# source files
- Breakpoint debugging and script execution for Q# source files
- Integration with Azure Quantum for quantum job submission
- Hover-definition and docs
- Go-to-definition
- Function signature help
- Snippet and sample support
- Completions
After developing a Q# quantum algorithm, you have the option to run your code. This can be done either locally on a quantum simulator, for free; or via submission to Azure Quantum, for a price.
In VS Code, access the Command Palette (ctrl
/cmd
+shift
+P
). Run the command "Debug: Run Q# File". This will run the file on your computer, using a quantum simulator. Note that this command only appears if you currently have a ".qs" file selected and open.
The extension includes a debugger. The debugger can handle typical breakpoint-style debugging (step into, over, out of, etc) as well as render program state.
To start the debugger, click the debug icon in the top left of VS Code. Select "Debug Q# File".
From here, the state of the program should be visible in the debugger pane on the left, and breakpoints will work. For fun, try stepping through an adjoint section. The debugger will show you how the adjoint is generated and applied.
See this wiki article for instructions on submitting to Azure.
To submit to real quantum environments, or to use a specific vendor's simulator, you can submit your Q# file to Azure Quantum. Note that only base-profile-compliant quantum programs can be submitted to Azure Quantum. In the VS Code status bar, switch the QIR profile to Base before proceeding.
Follow the following steps to submit your base-profile-compliant Q# file to Azure Quantum:
- Sign in to an Azure Quantum Workspace.
- From the VS Code Command Palette, run the "Q#: Add an Azure Quantum Workspace" command and follow the instructions provided.
- Select a provider.
- Ensure you have a Q# file selected and open.
- Find the "Quantum Workspaces" section
- Select the provider you want to submit to.
- Either click the ⏵︎ (Play) button to the right of the provider, or run the "Q#: Submit current Q# program" command from the Command Palette while a provider is selected.
Currently, Q# is limited to single file submissions. This means that your entire program must be contained within a single Q# source file. This will change in the future, when multi-file support is introduced (see #493 for context).