Skip to content

Adding spec compat mode for editing openqasm files - #3649

Draft
Ian Davis (idavis) wants to merge 1 commit into
mainfrom
iadavis/openqasm-specmode
Draft

Adding spec compat mode for editing openqasm files#3649
Ian Davis (idavis) wants to merge 1 commit into
mainfrom
iadavis/openqasm-specmode

Conversation

@idavis

Copy link
Copy Markdown
Collaborator

Overview

This branch adds an editor-focused compatibility mode for OpenQASM programs that are valid under the OpenQASM specification but use constructs the QDK cannot compile. It separates editing and specification validation from QDK execution so these programs remain useful in VS Code while their runtime limitations stay explicit.

Editing Modes

The new qdk.openqasm.mode setting controls how the editor handles OpenQASM files.

Mode Behavior
auto Uses QDK mode by default. It selects spec mode only when OpenQASM-to-Q# lowering finds a construct the QDK cannot represent. Syntax, semantic, and later target-capability errors do not trigger spec mode.
qdk Always uses the full QDK compilation pipeline. Unsupported OpenQASM constructs remain errors, and QDK execution features remain available.
spec Reports OpenQASM parser and semantic diagnostics without reporting QDK lowering, FIR, or target-capability diagnostics. Project and include-resolution errors remain visible.

An explicit qdk or spec selection takes precedence over automatic
detection. A temporary per-compilation override takes precedence over the
workspace setting, and resetting the override restores the configured mode.

Editor Experience

  • Adds commands to switch the active OpenQASM file to QDK mode or spec mode
  • Adds a command to reset the active file to the workspace default
  • Replaces execution code lenses in spec mode with a lens that explains the
    limitation and offers to switch back to QDK mode
  • Hides QDK-only editor actions while spec mode is active
  • Guards program-loading paths when a QDK action is invoked indirectly
  • Offers to switch to QDK mode when a guarded feature is requested
  • Refreshes editor context and code lenses when the effective mode changes

Spec mode disables features that require QDK compilation, including:

  • Run and Debug
  • Circuit generation and histogram execution
  • Resource estimation
  • QIR generation
  • Azure Quantum submission

OpenQASM editing services remain registered, including diagnostics, completions, definition lookup, references, and rename support.

OpenQASM Compatibility

Spec mode allows specification validation of programs that use constructs outside the QDK compilation subset without treating the QDK limitation as a source error. Examples include:

  • Calibration blocks and defcal definitions
  • Timing and duration operations such as delay
  • Hardware qubit addressing
  • extern declarations
  • Mutable array references

Spec mode is an editing and validation mode, not an alternative execution backend. A program must run in QDK mode before it can use simulation, debugging, circuit generation, resource estimation, QIR generation, or Azure Quantum submission.

Language Service Integration

The effective mode is resolved in the Rust language service and propagated through the WASM and qsharp-lang APIs to the VS Code extension. The branch adds:

  • Workspace configuration plumbing for auto, qdk, and spec
  • APIs to query the effective mode and set or clear an override
  • A mode-resolution event published for every source in an OpenQASM compilation
  • Recompilation and diagnostic publication when settings or overrides change
  • Diagnostic ownership for multi-file projects so a spec-mode parent prevents another compilation from publishing QDK diagnostics into included files
  • Telemetry that records whether a compilation resolves to QDK or spec mode

Comment thread source/vscode/src/language-service/openqasmMode.ts Dismissed
Comment thread source/vscode/src/language-service/openqasmMode.ts Dismissed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants