Skip to content

Editing Q# in VS Code

Alex Hansen edited this page Sep 12, 2023 · 12 revisions

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

Running Q# Code

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.

Running Locally on a Quantum Simulator

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.

Running via Azure Quantum

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. image

Follow the following steps to submit your base-profile-compliant Q# file to Azure Quantum:

  1. Sign in to an Azure Quantum Workspace.
    1. From the VS Code Command Palette, run the "Q#: Add an Azure Quantum Workspace" command and follow the instructions provided.
  2. Select a provider.
    1. Ensure you have a Q# file selected and open.
    2. Find the "Quantum Workspaces" section image
    3. Select the provider you want to submit to.
    4. 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.

Single File Limitations

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).