-
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
Several common quantum algorithms are provided as samples in the completion list. After creating a new .qs
document, type sample
to filter the completion list to them, and tab-complete to insert the sample.
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. You can see the qubit state as well as local variable state in the "Variables" section:
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.
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).