Skip to content

OpenQASM Interop

Ian Davis edited this page May 13, 2025 · 1 revision

The modern QDK provides interoperability with OpenQASM programs built upon the core Q# compiler infrastructure.

Editing OpenQASM in VS Code

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)
  • OpenQASM cell support in Jupyter notebooks. The extension will detect %%openqasm magic cells and automatically update the cell language to OpenQASM
  • Error checking in OpenQASM source files
  • Breakpoint debugging and script execution for OpenQASM source files
  • Integration with Azure Quantum for quantum job submission
  • Completions
  • Code lens

Running and Debugging OpenQASM Code

After developing a OpenQASM 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 File". This will run the file on your computer, using a quantum simulator. (You can also use the Play icon and drop-down in the top-right of the editor. See the screenshot in Debugging Locally section following. Or simply press Ctrl-F5). Note that this command only appears if you currently have a ".qasm" file selected and open. You can see the output from the program in the VS Code Debug Console output pane.

Debugging Locally

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 File".

Running via Azure Quantum

See this wiki article for instructions on submitting to Azure.

Code Lens

Python

Prequisites: Follow Steps 1-3 from the Tutorial: Q# in Jupyter Notebooks and VS Code

4. Run OpenQASM in a notebook cell

%%openqasm

include "stdgates.inc";
qubit[2] q;
h q[0];
cx q[0], q[1];
bit[2] c;
c[0] = measure q[0];
c[1] = measure q[1];